Skip to content

Commit

Permalink
🧩 :: 예외 처리 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyoil2 committed May 7, 2024
1 parent aaf7ddd commit 705d95b
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.springframework.transaction.annotation.Transactional
import scul.projectscul.domain.bookmark.domain.BookMark
import scul.projectscul.domain.bookmark.domain.repository.BookMarkRepository
import scul.projectscul.domain.culture.domain.repository.CultureRepository
import scul.projectscul.domain.review.excpetion.CultureNotFoundException
import scul.projectscul.domain.user.facade.UserFacade
import java.util.UUID

Expand All @@ -19,7 +20,7 @@ class BookMarkService (

fun execute(cultureId: UUID) {
val currentUser = userFacade.getCurrentUser()
val culture = cultureRepository.findCultureById(cultureId)
val culture = cultureRepository.findCultureById(cultureId) ?: throw CultureNotFoundException

val bookMark = bookMarkRepository.findBookMarkByCultureAndUser(culture, currentUser)
if (bookMark != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ interface ReviewRepository : JpaRepository<Review, UUID> {

fun findReviewsByCulture_Id(id: UUID) : List<Review>

fun findReviewsByUser(user: User) : List<Review>
fun findReviewsByUser(user: User) : List<Review>?

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package scul.projectscul.domain.user.exception
package scul.projectscul.domain.review.excpetion

import scul.projectscul.global.security.error.exception.ErrorCode
import scul.projectscul.global.security.error.exception.SculException

object PasswordMisMatchException : SculException(
ErrorCode.PASSWORD_MISMATCH
object CultureNotFoundException : SculException(
ErrorCode.CULTURE_NOT_FOUND
)
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ReviewController (
}

@GetMapping
fun getMyReviews() : GetReviewsResponse {
fun getMyReviews() : GetReviewsResponse? {
return getMyReviewService.execute()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.springframework.transaction.annotation.Transactional
import scul.projectscul.domain.culture.domain.repository.CultureRepository
import scul.projectscul.domain.review.domain.Review
import scul.projectscul.domain.review.domain.repository.ReviewRepository
import scul.projectscul.domain.review.excpetion.CultureNotFoundException
import scul.projectscul.domain.review.presentation.dto.request.CreateReviewRequest
import scul.projectscul.domain.user.facade.UserFacade
import java.time.LocalDate
Expand All @@ -19,7 +20,7 @@ class CreateReviewService (
){
fun execute(request: CreateReviewRequest, cultureId: UUID) {
val currentUser = userFacade.getCurrentUser()
val culture = cultureRepository.findCultureById(cultureId)
val culture = cultureRepository.findCultureById(cultureId) ?: throw CultureNotFoundException

val now = LocalDate.now()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ class GetMyReviewService (
private val userFacade: UserFacade
) {

fun execute(): GetReviewsResponse {
fun execute(): GetReviewsResponse? {
val currentUser = userFacade.getCurrentUser()
return GetReviewsResponse(
reviewRepository.findReviewsByUser(currentUser)
return reviewRepository.findReviewsByUser(currentUser)?.let {
GetReviewsResponse(
it
.map {
GetReviewsResponse.ReviewsResponse(it)
}
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ enum class ErrorCode(
LOG_NOT_EXIST(404, "Log Not Exist"),
ROLE_NOT_ADMIN(401,"Role Not Admin"),

//place
PLACE_NOT_FOUND(404, "Place Not Found"),
//culture
CULTURE_NOT_FOUND(404, "Culture Not Found"),

//file
FILE_BAD_REQUEST(400, "File Bad Request"),
Expand Down

0 comments on commit 705d95b

Please sign in to comment.