Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

edit 시에 PresignedUrl을 제대로 반환하지 않는 문제 해결 #80

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<ImageUrlEntity> = mutableListOf(),
@OneToMany(mappedBy = "article")
var articleLikes: MutableList<ArticleLikesEntity> = mutableListOf(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ImageUrlEntity> = mutableListOf(),
@OneToMany(mappedBy = "auction")
var auctionLikes: MutableList<AuctionLikesEntity> = mutableListOf(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ImageUrlEntity> = mutableListOf(),
@OneToMany(mappedBy = "feed")
var feedLikes: MutableList<FeedLikesEntity> = mutableListOf(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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(
Expand All @@ -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
Expand Down