Skip to content

Commit

Permalink
fix: 알맞은 exception으로 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
rlaisqls committed Nov 2, 2023
1 parent f9e393b commit b6246c8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ object QuestionNotFoundException : CustomException(
DomainErrorCode.QUESTION_NOT_FOUND
)

object QuestionSetNotFoundException : CustomException(
DomainErrorCode.QUESTION_NOT_FOUND
)

object AnswerNotFoundException : CustomException(
DomainErrorCode.ANSWER_NOT_FOUND
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import kr.hs.dsm.inq.domain.question.exception.AlreadyDislikedPostException
import kr.hs.dsm.inq.domain.question.exception.AlreadyLikedPostException
import kr.hs.dsm.inq.domain.question.exception.AnswerNotFoundException
import kr.hs.dsm.inq.domain.question.exception.QuestionNotFoundException
import kr.hs.dsm.inq.domain.question.exception.QuestionSetNotFoundException
import kr.hs.dsm.inq.domain.question.persistence.*
import kr.hs.dsm.inq.domain.question.persistence.dto.AnswersDto
import kr.hs.dsm.inq.domain.question.persistence.dto.CategoriesDto
Expand Down Expand Up @@ -230,7 +231,7 @@ class QuestionService(

fun likeQuestionSet(questionSetId: Long): LikeResponse {
val user = SecurityUtil.getCurrentUser()
val questionSet = questionSetsRepository.findByIdOrNull(questionSetId) ?: throw AnswerNotFoundException
val questionSet = questionSetsRepository.findByIdOrNull(questionSetId) ?: throw QuestionSetNotFoundException
return toggleLike(questionSet.post, user)
}

Expand Down Expand Up @@ -272,7 +273,7 @@ class QuestionService(

fun dislikeQuestionSet(questionSetId: Long): DislikeResponse {
val user = SecurityUtil.getCurrentUser()
val questionSet = questionSetsRepository.findByIdOrNull(questionSetId) ?: throw AnswerNotFoundException
val questionSet = questionSetsRepository.findByIdOrNull(questionSetId) ?: throw QuestionSetNotFoundException
return toggleDislike(questionSet.post, user)
}

Expand Down Expand Up @@ -395,7 +396,7 @@ class QuestionService(

val questionSetDetail = questionSetId.run {
questionSetsRepository.queryQuestionSetDtoById(user, questionSetId)
?: throw QuestionNotFoundException
?: throw QuestionSetNotFoundException
}

return GetQuestionSetDetailResponse.of(questionSetDetail)
Expand All @@ -404,7 +405,7 @@ class QuestionService(
fun answerQuestionSet(questionSetId: Long){
val user = SecurityUtil.getCurrentUser()

val questionSet = questionSetsRepository.findByIdOrNull(questionSetId)?: throw QuestionNotFoundException
val questionSet = questionSetsRepository.findByIdOrNull(questionSetId)?: throw QuestionSetNotFoundException

questionSolvingHistoryRepository.save(
QuestionSolvingHistory(
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/kr/hs/dsm/inq/global/error/ErrorCode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ enum class DomainErrorCode(
ANSWER_NOT_FOUND(ErrorStatus.NOT_FOUND, "Answer Not Found", 3),
TAG_NOT_FOUND(ErrorStatus.NOT_FOUND, "Tag Not Found", 4),
ATTENDANCE_NOT_FOUND(ErrorStatus.NOT_FOUND, "Attendance Not Found", 5),
QUESTION_SET_NOT_FOUND(ErrorStatus.NOT_FOUND, "Question Not Found", 6),

ALREADY_LIKED_POST(ErrorStatus.CONFLICT, "Already liked post", 1),
ALREADY_DISLIKED_POST(ErrorStatus.CONFLICT, "Already disliked post", 2),
Expand Down

0 comments on commit b6246c8

Please sign in to comment.