diff --git a/src/main/kotlin/com/example/boheom/domain/feed/domain/repository/ApplyRepository.kt b/src/main/kotlin/com/example/boheom/domain/feed/domain/repository/ApplyRepository.kt index d9ba14d..b7c44c9 100644 --- a/src/main/kotlin/com/example/boheom/domain/feed/domain/repository/ApplyRepository.kt +++ b/src/main/kotlin/com/example/boheom/domain/feed/domain/repository/ApplyRepository.kt @@ -12,4 +12,6 @@ interface ApplyRepository : JpaRepository { fun findByUser(user: User): List fun findByFeed(feed: Feed): List fun deleteByUserAndFeed(user: User, feed: Feed) + fun existsByFeed(feed: Feed): Boolean + fun deleteByFeed(feed: Feed) } \ No newline at end of file diff --git a/src/main/kotlin/com/example/boheom/domain/feed/service/DeleteFeedService.kt b/src/main/kotlin/com/example/boheom/domain/feed/service/DeleteFeedService.kt index 574f8a2..9247574 100644 --- a/src/main/kotlin/com/example/boheom/domain/feed/service/DeleteFeedService.kt +++ b/src/main/kotlin/com/example/boheom/domain/feed/service/DeleteFeedService.kt @@ -1,5 +1,6 @@ package com.example.boheom.domain.feed.service +import com.example.boheom.domain.feed.domain.repository.ApplyRepository import com.example.boheom.domain.feed.domain.repository.FeedRepository import com.example.boheom.domain.feed.domain.repository.FeedTagRepository import com.example.boheom.domain.feed.exception.IncorrectUserException @@ -15,6 +16,7 @@ class DeleteFeedService( private val userFacade: UserFacade, private val feedRepository: FeedRepository, private val feedTagRepository: FeedTagRepository, + private val applyRepository: ApplyRepository, ) { @Transactional fun execute(feedId: UUID) { @@ -25,6 +27,10 @@ class DeleteFeedService( throw IncorrectUserException } + if (applyRepository.existsByFeed(feed)) { + applyRepository.deleteByFeed(feed) + } + feedTagRepository.deleteAllByFeed(feed) feedRepository.delete(feed) }