Skip to content

Commit

Permalink
merge: (#35) ErrorCode 관련 모든 예외 처리 리팩터링 (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
softpeanut authored Dec 16, 2022
2 parents 39af80a + faad94a commit 07e6237
Show file tree
Hide file tree
Showing 133 changed files with 676 additions and 1,360 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package team.comit.simtong.domain.auth.usecase

import team.comit.simtong.domain.auth.exception.AuthCodeMismatchException
import team.comit.simtong.domain.auth.exception.AuthExceptions
import team.comit.simtong.domain.auth.model.AuthCodeLimit
import team.comit.simtong.domain.auth.spi.CommandAuthCodeLimitPort
import team.comit.simtong.domain.auth.spi.QueryAuthCodePort
Expand All @@ -11,6 +11,7 @@ import team.comit.simtong.global.annotation.UseCase
* 이메일 인증 코드 확인을 담당하는 CheckAuthCodeUseCase
*
* @author Chokyunghyeon
* @author kimbeomjin
* @date 2022/09/24
* @version 1.0.0
**/
Expand All @@ -21,10 +22,10 @@ class CheckAuthCodeUseCase(
) {

fun execute(email: String, code: String) {
val authCode = queryAuthCodePort.queryAuthCodeByEmail(email)
val authCode = queryAuthCodePort.queryAuthCodeByEmail(email) ?: throw AuthExceptions.RequiredNewEmailAuthentication()

if (authCode?.code != code) {
throw AuthCodeMismatchException.EXCEPTION
if (authCode.code != code) {
throw AuthExceptions.DifferentAuthCode()
}

commandAuthCodeLimitPort.save(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package team.comit.simtong.domain.auth.usecase

import team.comit.simtong.domain.auth.exception.RefreshTokenNotFoundException
import team.comit.simtong.domain.auth.dto.TokenResponse
import team.comit.simtong.domain.auth.exception.AuthExceptions
import team.comit.simtong.domain.auth.spi.JwtPort
import team.comit.simtong.domain.auth.spi.QueryRefreshTokenPort
import team.comit.simtong.domain.auth.dto.TokenResponse
import team.comit.simtong.global.annotation.UseCase

/**
Expand All @@ -23,7 +23,7 @@ class ReissueTokenUseCase(

fun execute(request: String): TokenResponse {
val token = queryRefreshTokenPort.queryRefreshTokenByToken(request)
?: throw RefreshTokenNotFoundException.EXCEPTION
?: throw AuthExceptions.RefreshTokenNotFound()

return jwtPort.receiveToken(
userId = token.userId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package team.comit.simtong.domain.auth.usecase

import team.comit.simtong.domain.auth.exception.CertifiedEmailException
import team.comit.simtong.domain.auth.exception.AuthExceptions
import team.comit.simtong.domain.auth.model.AuthCode
import team.comit.simtong.domain.auth.model.AuthCodeLimit
import team.comit.simtong.domain.auth.spi.CommandAuthCodeLimitPort
Expand Down Expand Up @@ -29,8 +29,8 @@ class SendAuthCodeUseCase(
val authCodeLimit = queryAuthCodeLimitPort.queryAuthCodeLimitByEmail(email)
?: AuthCodeLimit(email)

if(authCodeLimit.verified) {
throw CertifiedEmailException.EXCEPTION
if (authCodeLimit.verified) {
throw AuthExceptions.AlreadyCertifiedEmail()
}

commandAuthCodeLimitPort.save(authCodeLimit.increaseCount())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package team.comit.simtong.domain.file.usecase

import team.comit.simtong.domain.file.exception.InvalidEmployeeException
import team.comit.simtong.domain.file.exception.FileExceptions
import team.comit.simtong.domain.file.spi.QueryEmployeeCertificatePort
import team.comit.simtong.global.annotation.ReadOnlyUseCase

Expand All @@ -23,7 +23,7 @@ class CheckEmployeeUseCase(
)

if (!isEmployee) {
throw InvalidEmployeeException.EXCEPTION
throw FileExceptions.NotExistsEmployee()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package team.comit.simtong.domain.holiday.usecase

import team.comit.simtong.domain.holiday.exception.WeekHolidayLimitExcessException
import team.comit.simtong.domain.holiday.exception.HolidayExceptions
import team.comit.simtong.domain.holiday.model.Holiday
import team.comit.simtong.domain.holiday.model.HolidayType
import team.comit.simtong.domain.holiday.spi.CommandHolidayPort
import team.comit.simtong.domain.holiday.spi.HolidayQueryUserPort
import team.comit.simtong.domain.holiday.spi.HolidaySecurityPort
import team.comit.simtong.domain.holiday.spi.QueryHolidayPort
import team.comit.simtong.domain.user.exception.UserNotFoundException
import team.comit.simtong.domain.user.exception.UserExceptions
import team.comit.simtong.global.annotation.UseCase
import java.time.LocalDate

Expand All @@ -29,12 +29,12 @@ class AppointHolidayUseCase(

fun execute(date: LocalDate) {
val user = queryUserPort.queryUserById(securityPort.getCurrentUserId())
?: throw UserNotFoundException.EXCEPTION
?: throw UserExceptions.NotFound()

val countHoliday = queryHolidayPort.countHolidayByWeekAndUserIdAndType(date, user.id, HolidayType.HOLIDAY)

if (countHoliday >= Holiday.WEEK_HOLIDAY_LIMIT) {
throw WeekHolidayLimitExcessException.EXCEPTION
throw HolidayExceptions.WeekHolidayLimitExcess()
}

commandHolidayPort.save(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package team.comit.simtong.domain.holiday.usecase

import team.comit.simtong.domain.holiday.exception.HolidayNotFoundException
import team.comit.simtong.domain.holiday.exception.HolidayExceptions
import team.comit.simtong.domain.holiday.spi.CommandHolidayPort
import team.comit.simtong.domain.holiday.spi.HolidaySecurityPort
import team.comit.simtong.domain.holiday.spi.QueryHolidayPort
Expand All @@ -26,7 +26,7 @@ class CancelHolidayUseCase(
val currentUserId = securityPort.getCurrentUserId()

val holiday = queryHolidayPort.queryHolidayByDateAndUserId(date, currentUserId)
?: throw HolidayNotFoundException.EXCEPTION
?: throw HolidayExceptions.NotFound()

commandHolidayPort.delete(holiday)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import team.comit.simtong.domain.menu.dto.MenuResponse
import team.comit.simtong.domain.menu.spi.MenuQueryUserPort
import team.comit.simtong.domain.menu.spi.MenuSecurityPort
import team.comit.simtong.domain.menu.spi.QueryMenuPort
import team.comit.simtong.domain.user.exception.UserNotFoundException
import team.comit.simtong.domain.user.exception.UserExceptions
import team.comit.simtong.global.annotation.ReadOnlyUseCase
import java.time.LocalDate

Expand All @@ -25,7 +25,7 @@ class QueryMenuByMonthUseCase(

fun execute(date: LocalDate): MenuResponse {
val currentUserId = menuSecurityPort.getCurrentUserId()
val user = queryUserPort.queryUserById(currentUserId) ?: throw UserNotFoundException.EXCEPTION
val user = queryUserPort.queryUserById(currentUserId) ?: throw UserExceptions.NotFound()

val menu = queryMenuPort.queryMenusByMonthAndSpotId(date, user.spotId)
val result = menu.map { MenuResponse.MenuElement(it.date, it.meal) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package team.comit.simtong.domain.menu.usecase

import team.comit.simtong.domain.menu.exception.MenuAlreadyExistsSameMonthException
import team.comit.simtong.domain.menu.exception.MenuExceptions
import team.comit.simtong.domain.menu.spi.CommandMenuPort
import team.comit.simtong.domain.menu.spi.ParseMenuFilePort
import team.comit.simtong.domain.menu.spi.QueryMenuPort
Expand Down Expand Up @@ -28,7 +28,7 @@ class SaveMenuUseCase(
val menu = parseMenuFilePort.importMenu(file, year, month, spotId)

if (queryMenuPort.queryMenusByMonthAndSpotId(LocalDate.of(year, month, 1), spotId).isNotEmpty()) {
throw MenuAlreadyExistsSameMonthException.EXCEPTION
throw MenuExceptions.AlreadyExistsSameMonth("${year}${month}월 메뉴가 이미 존재합니다.")
}

commandMenuPort.saveAll(menu)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import team.comit.simtong.domain.schedule.model.Scope
import team.comit.simtong.domain.schedule.spi.CommandSchedulePort
import team.comit.simtong.domain.schedule.spi.ScheduleQueryUserPort
import team.comit.simtong.domain.schedule.spi.ScheduleSecurityPort
import team.comit.simtong.domain.user.exception.UserNotFoundException
import team.comit.simtong.domain.user.exception.UserExceptions
import team.comit.simtong.global.annotation.UseCase

/**
Expand All @@ -29,7 +29,7 @@ class AddIndividualScheduleUseCase(
val (title, startAt, endAt, alarm) = request

val user = queryUserPort.queryUserById(currentUserId)
?: throw UserNotFoundException.EXCEPTION
?: throw UserExceptions.NotFound()

commandSchedulePort.save(
Schedule(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import team.comit.simtong.domain.schedule.model.Scope
import team.comit.simtong.domain.schedule.spi.CommandSchedulePort
import team.comit.simtong.domain.schedule.spi.ScheduleQueryUserPort
import team.comit.simtong.domain.schedule.spi.ScheduleSecurityPort
import team.comit.simtong.domain.user.exception.NotEnoughPermissionException
import team.comit.simtong.domain.user.exception.UserNotFoundException
import team.comit.simtong.domain.user.exception.UserExceptions
import team.comit.simtong.domain.user.model.Authority
import team.comit.simtong.global.annotation.UseCase

Expand All @@ -31,10 +30,10 @@ class AddSpotScheduleUseCase(
val (spotId, title, startAt, endAt) = request

val user = queryUserPort.queryUserById(currentUserId)
?: throw UserNotFoundException.EXCEPTION
?: throw UserExceptions.NotFound()

if (user.spotId != spotId && user.authority != Authority.ROLE_SUPER) {
throw NotEnoughPermissionException.EXCEPTION
throw UserExceptions.NotEnoughPermission("같은 지점 관리자이거나 최고 관리자이어야 합니다.")
}

commandSchedulePort.save(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package team.comit.simtong.domain.schedule.usecase

import team.comit.simtong.domain.schedule.dto.ChangeIndividualScheduleRequest
import team.comit.simtong.domain.schedule.exception.NotScheduleOwnerException
import team.comit.simtong.domain.schedule.exception.ScheduleNotFoundException
import team.comit.simtong.domain.schedule.exception.ScheduleExceptions
import team.comit.simtong.domain.schedule.spi.CommandSchedulePort
import team.comit.simtong.domain.schedule.spi.QuerySchedulePort
import team.comit.simtong.domain.schedule.spi.ScheduleQueryUserPort
import team.comit.simtong.domain.schedule.spi.ScheduleSecurityPort
import team.comit.simtong.domain.user.exception.UserNotFoundException
import team.comit.simtong.domain.user.exception.UserExceptions
import team.comit.simtong.global.annotation.UseCase

/**
Expand All @@ -31,13 +30,13 @@ class ChangeIndividualScheduleUseCase(
val (scheduleId, title, startAt, endAt, alarm) = request

val schedule = querySchedulePort.queryScheduleById(scheduleId)
?: throw ScheduleNotFoundException.EXCEPTION
?: throw ScheduleExceptions.NotFound()

val user = queryUserPort.queryUserById(currentUserId)
?: throw UserNotFoundException.EXCEPTION
?: throw UserExceptions.NotFound()

if (user.id != schedule.userId) {
throw NotScheduleOwnerException.EXCEPTION
throw ScheduleExceptions.NotScheduleOwner()
}

commandSchedulePort.save(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package team.comit.simtong.domain.schedule.usecase

import team.comit.simtong.domain.schedule.dto.ChangeSpotScheduleRequest
import team.comit.simtong.domain.schedule.exception.NotScheduleOwnerException
import team.comit.simtong.domain.schedule.exception.ScheduleNotFoundException
import team.comit.simtong.domain.schedule.exception.ScheduleExceptions
import team.comit.simtong.domain.schedule.model.Scope
import team.comit.simtong.domain.schedule.spi.CommandSchedulePort
import team.comit.simtong.domain.schedule.spi.QuerySchedulePort
import team.comit.simtong.domain.schedule.spi.ScheduleQueryUserPort
import team.comit.simtong.domain.schedule.spi.ScheduleSecurityPort
import team.comit.simtong.domain.user.exception.NotEnoughPermissionException
import team.comit.simtong.domain.user.exception.UserNotFoundException
import team.comit.simtong.domain.user.exception.UserExceptions
import team.comit.simtong.domain.user.model.Authority
import team.comit.simtong.global.annotation.UseCase

Expand All @@ -33,16 +31,16 @@ class ChangeSpotScheduleUseCase(
val currentUserId = securityPort.getCurrentUserId()

val user = queryUserPort.queryUserById(currentUserId)
?: throw UserNotFoundException.EXCEPTION
?: throw UserExceptions.NotFound()

val schedule = querySchedulePort.queryScheduleById(request.scheduleId)
?: throw ScheduleNotFoundException.EXCEPTION
?: throw ScheduleExceptions.NotFound()

when {
Scope.ENTIRE != schedule.scope -> throw NotScheduleOwnerException.EXCEPTION
Scope.ENTIRE != schedule.scope -> throw ScheduleExceptions.NotScheduleOwner()

user.spotId != schedule.spotId &&
Authority.ROLE_SUPER != user.authority -> throw NotEnoughPermissionException.EXCEPTION
user.spotId != schedule.spotId && Authority.ROLE_SUPER != user.authority ->
throw UserExceptions.NotEnoughPermission("같은 지점 관리자이거나 최고 관리자이어야 합니다.")
}

commandSchedulePort.save(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import team.comit.simtong.domain.schedule.model.Scope
import team.comit.simtong.domain.schedule.spi.QuerySchedulePort
import team.comit.simtong.domain.schedule.spi.ScheduleQueryUserPort
import team.comit.simtong.domain.schedule.spi.ScheduleSecurityPort
import team.comit.simtong.domain.user.exception.UserNotFoundException
import team.comit.simtong.domain.user.exception.UserExceptions
import team.comit.simtong.global.annotation.ReadOnlyUseCase
import java.time.LocalDate

Expand All @@ -27,7 +27,7 @@ class QueryIndividualSpotScheduleUseCase(

fun execute(date: LocalDate): QueryIndividualSpotScheduleResponse {
val user = queryUserPort.queryUserById(securityPort.getCurrentUserId())
?: throw UserNotFoundException.EXCEPTION
?: throw UserExceptions.NotFound()

val individualSchedules = querySchedulePort.querySchedulesByMonthAndUserIdAndScope(
date, user.id, Scope.INDIVIDUAL
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package team.comit.simtong.domain.schedule.usecase

import team.comit.simtong.domain.schedule.exception.DifferentScopeException
import team.comit.simtong.domain.schedule.exception.NotScheduleOwnerException
import team.comit.simtong.domain.schedule.exception.ScheduleNotFoundException
import team.comit.simtong.domain.schedule.exception.ScheduleExceptions
import team.comit.simtong.domain.schedule.model.Scope
import team.comit.simtong.domain.schedule.spi.CommandSchedulePort
import team.comit.simtong.domain.schedule.spi.QuerySchedulePort
import team.comit.simtong.domain.schedule.spi.ScheduleQueryUserPort
import team.comit.simtong.domain.schedule.spi.ScheduleSecurityPort
import team.comit.simtong.domain.user.exception.UserNotFoundException
import team.comit.simtong.domain.user.exception.UserExceptions
import team.comit.simtong.global.annotation.UseCase
import java.util.UUID

Expand All @@ -32,17 +30,17 @@ class RemoveIndividualScheduleUseCase(
val currentUserId = securityPort.getCurrentUserId()

val user = queryUserPort.queryUserById(currentUserId)
?: throw UserNotFoundException.EXCEPTION
?: throw UserExceptions.NotFound()

val schedule = querySchedulePort.queryScheduleById(scheduleId)
?: throw ScheduleNotFoundException.EXCEPTION
?: throw ScheduleExceptions.NotFound()

if (user.id != schedule.userId) {
throw NotScheduleOwnerException.EXCEPTION
throw ScheduleExceptions.NotScheduleOwner()
}

if (Scope.INDIVIDUAL != schedule.scope) {
throw DifferentScopeException.EXCEPTION
throw ScheduleExceptions.DifferentScope("개인 일정이 아닙니다.")
}

commandSchedulePort.delete(schedule)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package team.comit.simtong.domain.schedule.usecase

import team.comit.simtong.domain.schedule.exception.DifferentScopeException
import team.comit.simtong.domain.schedule.exception.ScheduleNotFoundException
import team.comit.simtong.domain.schedule.exception.ScheduleExceptions
import team.comit.simtong.domain.schedule.model.Scope
import team.comit.simtong.domain.schedule.spi.CommandSchedulePort
import team.comit.simtong.domain.schedule.spi.QuerySchedulePort
import team.comit.simtong.domain.schedule.spi.ScheduleQueryUserPort
import team.comit.simtong.domain.schedule.spi.ScheduleSecurityPort
import team.comit.simtong.domain.user.exception.NotEnoughPermissionException
import team.comit.simtong.domain.user.exception.UserNotFoundException
import team.comit.simtong.domain.user.exception.UserExceptions
import team.comit.simtong.domain.user.model.Authority
import team.comit.simtong.global.annotation.UseCase
import java.util.UUID
Expand All @@ -33,17 +31,17 @@ class RemoveSpotScheduleUseCase(
val currentUserId = securityPort.getCurrentUserId()

val user = queryUserPort.queryUserById(currentUserId)
?: throw UserNotFoundException.EXCEPTION
?: throw UserExceptions.NotFound()

val schedule = querySchedulePort.queryScheduleById(scheduleId)
?: throw ScheduleNotFoundException.EXCEPTION
?: throw ScheduleExceptions.NotFound()

if (user.spotId != schedule.spotId && user.authority != Authority.ROLE_SUPER) {
throw NotEnoughPermissionException.EXCEPTION
throw UserExceptions.NotEnoughPermission("같은 지점 관리자이거나 최고 관리자이어야 합니다.")
}

if (Scope.ENTIRE != schedule.scope) {
throw DifferentScopeException.EXCEPTION
throw ScheduleExceptions.DifferentScope("지점 일정이 아닙니다.")
}

commandSchedulePort.delete(schedule)
Expand Down
Loading

0 comments on commit 07e6237

Please sign in to comment.