-
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.
Merge pull request #17 from MEOGO-DSM/16-delete-review
π :: (Meogo-16) delete review
- Loading branch information
Showing
5 changed files
with
44 additions
and
3 deletions.
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) | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/main/kotlin/org/meogo/domain/review/service/ModifyReviewService.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
2 changes: 1 addition & 1 deletion
2
...review/exception/UserMisMatchException.kt β ...n/user/exception/UserMisMatchException.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