From b235ece155a3cab0cbac8ba38f945d323aa7a42c Mon Sep 17 00:00:00 2001 From: Junyong Lee Date: Fri, 31 Jan 2025 15:38:30 +0900 Subject: [PATCH] :bug: Fix Entity and Service(Image, Article, Feed, Auction) to get PresignedUrl with no delay --- .../karrot/article/persistence/ArticleEntity.kt | 3 ++- .../karrot/article/service/ArticleService.kt | 2 +- .../karrot/auction/persistence/AuctionEntity.kt | 3 ++- .../karrot/auction/service/AuctionService.kt | 3 +-- .../karrot/feed/persistence/FeedEntity.kt | 3 ++- .../karrot/feed/service/FeedService.kt | 2 +- .../karrot/image/persistence/ImageUrlEntity.kt | 14 -------------- .../karrot/image/service/ImageService.kt | 17 ----------------- 8 files changed, 9 insertions(+), 38 deletions(-) diff --git a/src/main/kotlin/com/toyProject7/karrot/article/persistence/ArticleEntity.kt b/src/main/kotlin/com/toyProject7/karrot/article/persistence/ArticleEntity.kt index c53e6c2..8bd36d9 100644 --- a/src/main/kotlin/com/toyProject7/karrot/article/persistence/ArticleEntity.kt +++ b/src/main/kotlin/com/toyProject7/karrot/article/persistence/ArticleEntity.kt @@ -35,7 +35,8 @@ class ArticleEntity( var status: Int, @Column(name = "location", nullable = false) var location: String, - @OneToMany(mappedBy = "article") + @OneToMany + @JoinColumn(name = "image_url", nullable = true) var imageUrls: MutableList = mutableListOf(), @OneToMany(mappedBy = "article") var articleLikes: MutableList = mutableListOf(), diff --git a/src/main/kotlin/com/toyProject7/karrot/article/service/ArticleService.kt b/src/main/kotlin/com/toyProject7/karrot/article/service/ArticleService.kt index 205f3f3..39d8c62 100644 --- a/src/main/kotlin/com/toyProject7/karrot/article/service/ArticleService.kt +++ b/src/main/kotlin/com/toyProject7/karrot/article/service/ArticleService.kt @@ -28,7 +28,7 @@ class ArticleService( private val articleRepository: ArticleRepository, private val articleLikesRepository: ArticleLikesRepository, private val userService: UserService, - @Lazy private val imageService: ImageService, + private val imageService: ImageService, @Lazy private val chatRoomService: ChatRoomService, ) { @Transactional diff --git a/src/main/kotlin/com/toyProject7/karrot/auction/persistence/AuctionEntity.kt b/src/main/kotlin/com/toyProject7/karrot/auction/persistence/AuctionEntity.kt index 43f2905..6f703f6 100644 --- a/src/main/kotlin/com/toyProject7/karrot/auction/persistence/AuctionEntity.kt +++ b/src/main/kotlin/com/toyProject7/karrot/auction/persistence/AuctionEntity.kt @@ -37,7 +37,8 @@ class AuctionEntity( var status: Int, @Column(name = "location", nullable = false) var location: String, - @OneToMany(mappedBy = "auction") + @OneToMany + @JoinColumn(name = "image_url", nullable = true) var imageUrls: MutableList = mutableListOf(), @OneToMany(mappedBy = "auction") var auctionLikes: MutableList = mutableListOf(), diff --git a/src/main/kotlin/com/toyProject7/karrot/auction/service/AuctionService.kt b/src/main/kotlin/com/toyProject7/karrot/auction/service/AuctionService.kt index e1506a2..9ac3360 100644 --- a/src/main/kotlin/com/toyProject7/karrot/auction/service/AuctionService.kt +++ b/src/main/kotlin/com/toyProject7/karrot/auction/service/AuctionService.kt @@ -17,7 +17,6 @@ import com.toyProject7.karrot.auction.persistence.AuctionRepository import com.toyProject7.karrot.image.persistence.ImageUrlEntity import com.toyProject7.karrot.image.service.ImageService import com.toyProject7.karrot.user.service.UserService -import org.springframework.context.annotation.Lazy import org.springframework.data.repository.findByIdOrNull import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @@ -29,7 +28,7 @@ class AuctionService( private val auctionRepository: AuctionRepository, private val auctionLikesRepository: AuctionLikesRepository, private val userService: UserService, - @Lazy private val imageService: ImageService, + private val imageService: ImageService, ) { @Transactional fun updatePrice(auctionMessage: AuctionMessage): AuctionMessage { diff --git a/src/main/kotlin/com/toyProject7/karrot/feed/persistence/FeedEntity.kt b/src/main/kotlin/com/toyProject7/karrot/feed/persistence/FeedEntity.kt index 30f2917..4af70c0 100644 --- a/src/main/kotlin/com/toyProject7/karrot/feed/persistence/FeedEntity.kt +++ b/src/main/kotlin/com/toyProject7/karrot/feed/persistence/FeedEntity.kt @@ -27,7 +27,8 @@ class FeedEntity( var content: String, @Column(name = "tag", nullable = false) var tag: String, - @OneToMany(mappedBy = "feed") + @OneToMany + @JoinColumn(name = "image_url", nullable = true) var imageUrls: MutableList = mutableListOf(), @OneToMany(mappedBy = "feed") var feedLikes: MutableList = mutableListOf(), diff --git a/src/main/kotlin/com/toyProject7/karrot/feed/service/FeedService.kt b/src/main/kotlin/com/toyProject7/karrot/feed/service/FeedService.kt index 2250cee..58aca5a 100644 --- a/src/main/kotlin/com/toyProject7/karrot/feed/service/FeedService.kt +++ b/src/main/kotlin/com/toyProject7/karrot/feed/service/FeedService.kt @@ -26,7 +26,7 @@ class FeedService( private val feedLikesRepository: FeedLikesRepository, private val userService: UserService, @Lazy private val commentService: CommentService, - @Lazy private val imageService: ImageService, + private val imageService: ImageService, ) { @Transactional fun postFeed( diff --git a/src/main/kotlin/com/toyProject7/karrot/image/persistence/ImageUrlEntity.kt b/src/main/kotlin/com/toyProject7/karrot/image/persistence/ImageUrlEntity.kt index 56480a5..bab3ed9 100644 --- a/src/main/kotlin/com/toyProject7/karrot/image/persistence/ImageUrlEntity.kt +++ b/src/main/kotlin/com/toyProject7/karrot/image/persistence/ImageUrlEntity.kt @@ -1,30 +1,16 @@ package com.toyProject7.karrot.image.persistence -import com.toyProject7.karrot.article.persistence.ArticleEntity -import com.toyProject7.karrot.auction.persistence.AuctionEntity -import com.toyProject7.karrot.feed.persistence.FeedEntity import jakarta.persistence.Column import jakarta.persistence.Entity import jakarta.persistence.GeneratedValue import jakarta.persistence.GenerationType import jakarta.persistence.Id -import jakarta.persistence.JoinColumn -import jakarta.persistence.ManyToOne @Entity(name = "image_urls") class ImageUrlEntity( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) val id: Long? = null, - @ManyToOne - @JoinColumn(name = "article_id", nullable = true) - var article: ArticleEntity? = null, - @ManyToOne - @JoinColumn(name = "feed_id", nullable = true) - var feed: FeedEntity? = null, - @ManyToOne - @JoinColumn(name = "auction_id", nullable = true) - var auction: AuctionEntity? = null, @Column(name = "s3", nullable = false, length = 512) var s3: String, @Column(name = "presigned", nullable = false, length = 512) diff --git a/src/main/kotlin/com/toyProject7/karrot/image/service/ImageService.kt b/src/main/kotlin/com/toyProject7/karrot/image/service/ImageService.kt index f0a9663..882306a 100644 --- a/src/main/kotlin/com/toyProject7/karrot/image/service/ImageService.kt +++ b/src/main/kotlin/com/toyProject7/karrot/image/service/ImageService.kt @@ -1,8 +1,5 @@ package com.toyProject7.karrot.image.service -import com.toyProject7.karrot.article.service.ArticleService -import com.toyProject7.karrot.auction.service.AuctionService -import com.toyProject7.karrot.feed.service.FeedService import com.toyProject7.karrot.image.ImageDeleteException import com.toyProject7.karrot.image.ImagePresignedUrlCreateException import com.toyProject7.karrot.image.ImageS3UrlCreateException @@ -25,9 +22,6 @@ class ImageService( private val s3Client: S3Client, private val s3Presigner: S3Presigner, private val imageUrlRepository: ImageUrlRepository, - private val articleService: ArticleService, - private val feedService: FeedService, - private val auctionService: AuctionService, ) { @Transactional fun postImageUrl( @@ -39,17 +33,6 @@ class ImageService( ImageUrlEntity( s3 = generateS3Path(type, typeId, imageIndex), ) - when (type) { - "article" -> { - imageUrlEntity.article = articleService.getArticleEntityById(typeId) - } - "feed" -> { - imageUrlEntity.feed = feedService.getFeedEntityById(typeId) - } - "auction" -> { - imageUrlEntity.auction = auctionService.getAuctionEntityById(typeId) - } - } imageUrlRepository.save(imageUrlEntity) return imageUrlEntity