Skip to content

Commit

Permalink
refactor: (#798) 예외 처리 방식 개선
Browse files Browse the repository at this point in the history
  • Loading branch information
pji-min committed Feb 14, 2025
1 parent a7a9c5d commit 347cdcb
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package team.aliens.dms.domain.vote.exception

import team.aliens.dms.common.error.ErrorProperty
import team.aliens.dms.common.error.ErrorStatus

enum class VoteErrorCode(
private val status: Int,
private val message: String,
private val sequence: Int
) : ErrorProperty {

STUDENT_NOT_FOUND(ErrorStatus.NOT_FOUND, "Student Not Found", 1),
STUDENT_ID_NOT_FOUND(ErrorStatus.BAD_REQUEST, "Student ID Not Found", 2)
;

override fun status(): Int = status
override fun message(): String = message
override fun code(): String = "Vote-$status-$sequence"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package team.aliens.dms.domain.vote.exception

import team.aliens.dms.common.error.DmsException
import team.aliens.dms.domain.vote.model.ModelStudent

object StudentNotFoundException : DmsException(
VoteErrorCode.STUDENT_NOT_FOUND
)

object StudentIdNotFoundException : DmsException(
VoteErrorCode.STUDENT_ID_NOT_FOUND
)

fun validateStudentList(modelStudentList: List<ModelStudent>) {
if (modelStudentList.isEmpty()) {
throw StudentNotFoundException
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package team.aliens.dms.domain.vote.service

import team.aliens.dms.common.annotation.Service
import team.aliens.dms.domain.vote.dto.response.ModelStudentListResponse
import team.aliens.dms.domain.vote.exception.validateStudentList
import team.aliens.dms.domain.vote.spi.ModelStudentListPort
import java.time.LocalDate

Expand All @@ -19,9 +20,7 @@ class ModelStudentListServiceImpl(

val modelStudentList = modelStudentListPort.findModelStudents(startOfDay, endOfDay)

if (modelStudentList.isEmpty()) {
throw NoSuchElementException("학생을 찾을 수 없습니다")
}
validateStudentList(modelStudentList)

return modelStudentList.map { student ->
ModelStudentListResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package team.aliens.dms.persistence.vote
import com.querydsl.jpa.impl.JPAQueryFactory
import org.springframework.stereotype.Component
import team.aliens.dms.domain.point.model.PointType
import team.aliens.dms.domain.vote.exception.StudentIdNotFoundException
import team.aliens.dms.domain.vote.model.ModelStudent
import team.aliens.dms.domain.vote.spi.ModelStudentListPort
import team.aliens.dms.persistence.point.entity.QPointHistoryJpaEntity
Expand All @@ -25,7 +26,7 @@ class ModelStudentListAdapter(
.map { student ->
val gcn = createGcn(student.grade, student.classRoom, student.number)
ModelStudent(
id = student.id ?: throw IllegalStateException("학생 ID가 존재하지 않습니다."),
id = student.id ?: throw StudentIdNotFoundException,
studentGcn = gcn,
studentName = student.name,
studentProfile = student.profileImageUrl
Expand Down

0 comments on commit 347cdcb

Please sign in to comment.