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

πŸ„ :: (Meogo-16) delete review #17

Merged
merged 2 commits into from
Sep 5, 2024
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 @@ -4,14 +4,18 @@ import lombok.RequiredArgsConstructor
import org.meogo.domain.review.presentation.dto.request.ModifyReviewRequest
import org.meogo.domain.review.presentation.dto.request.ReviewRequest
import org.meogo.domain.review.service.CreateReviewService
import org.meogo.domain.review.service.DeleteReviewService
import org.meogo.domain.review.service.ModifyReviewService
import org.meogo.domain.review.service.QueryAllBySchoolIdService
import org.springframework.http.HttpStatus
import org.springframework.web.bind.annotation.DeleteMapping
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PatchMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.ResponseStatus
import org.springframework.web.bind.annotation.RestController
import javax.validation.Valid

Expand All @@ -21,9 +25,11 @@ import javax.validation.Valid
class ReviewController(
private val createReviewService: CreateReviewService,
private val queryAllBySchoolIdService: QueryAllBySchoolIdService,
private val modifyReviewService: ModifyReviewService
private val modifyReviewService: ModifyReviewService,
private val deleteReviewService: DeleteReviewService
) {
@PostMapping
@ResponseStatus(value = HttpStatus.CREATED)
fun create(
@Valid @RequestBody
request: ReviewRequest
Expand All @@ -37,4 +43,9 @@ class ReviewController(
@PatchMapping("/modify")
fun modify(@RequestParam(name = "review_id") reviewId: Long, @RequestBody request: ModifyReviewRequest) =
modifyReviewService.modifyReview(reviewId, request)

@DeleteMapping("/delete")
@ResponseStatus(value = HttpStatus.NO_CONTENT)
fun delete(@RequestParam(name = "review_id") reviewId: Long) =
deleteReviewService.deleteReview(reviewId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ interface ReviewRepository : Repository<Review, Long> {
fun findAllBySchoolId(id: Int): List<Review>?

fun findById(id: Long): Review?

fun deleteById(id: Long)
}
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)
}
meltapplee marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.meogo.domain.review.service

import org.meogo.domain.review.exception.ReviewNotFoundException
import org.meogo.domain.review.exception.UserMisMatchException
import org.meogo.domain.review.presentation.dto.request.ModifyReviewRequest
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.springframework.stereotype.Service
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.meogo.domain.review.exception
package org.meogo.domain.user.exception

import org.meogo.global.error.exception.ErrorCode
import org.meogo.global.error.exception.MeogoException
Expand Down
Loading