-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5aeb932
commit ad4db95
Showing
3 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/kotlin/org/meogo/domain/review/service/DeleteReviewService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.meogo.domain.review.service | ||
|
||
import org.meogo.domain.review.exception.ReviewNotFoundException | ||
import org.meogo.domain.review.repository.ReviewRepository | ||
import org.meogo.domain.user.exception.UserMisMatchException | ||
import org.meogo.domain.user.exception.UserNotFoundException | ||
import org.meogo.domain.user.facade.UserFacade | ||
import org.meogo.domain.user.repository.UserRepository | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Service | ||
class DeleteReviewService( | ||
private val reviewRepository: ReviewRepository, | ||
private val userFacade: UserFacade, | ||
private val userRepository: UserRepository | ||
) { | ||
|
||
@Transactional | ||
fun deleteReview(id: Long) { | ||
val user = userFacade.currentUser() ?: throw UserNotFoundException | ||
val review = reviewRepository.findById(id) ?: throw ReviewNotFoundException | ||
|
||
if (user.id != review.userId) throw UserMisMatchException | ||
|
||
reviewRepository.deleteById(review.id) | ||
} | ||
} |