diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/AddIndividualScheduleUseCase.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/AddIndividualScheduleUseCase.kt index b3974065..7cb11fd9 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/AddIndividualScheduleUseCase.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/AddIndividualScheduleUseCase.kt @@ -15,7 +15,7 @@ import team.comit.simtong.global.annotation.UseCase * * @author Chokyunghyeon * @date 2022/11/26 - * @version 1.0.0 + * @version 1.2.5 **/ @UseCase class AddIndividualScheduleUseCase( @@ -32,7 +32,7 @@ class AddIndividualScheduleUseCase( ?: throw UserExceptions.NotFound() commandSchedulePort.save( - Schedule( + Schedule.of( userId = currentUserId, spotId = user.spotId, title = title, @@ -43,5 +43,4 @@ class AddIndividualScheduleUseCase( ) ) } - } \ No newline at end of file diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/AddSpotScheduleUseCase.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/AddSpotScheduleUseCase.kt index 4413ff97..874b0720 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/AddSpotScheduleUseCase.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/AddSpotScheduleUseCase.kt @@ -15,8 +15,9 @@ import team.comit.simtong.global.annotation.UseCase * 지점 일정 추가를 담당하는 AddSpotScheduleUseCase * * @author Chokyunghyeon + * @author kimbeomjin * @date 2022/11/21 - * @version 1.0.0 + * @version 1.2.5 **/ @UseCase class AddSpotScheduleUseCase( @@ -37,7 +38,7 @@ class AddSpotScheduleUseCase( } commandSchedulePort.save( - Schedule( + Schedule.of( userId = currentUserId, spotId = spotId, title = title, @@ -47,5 +48,4 @@ class AddSpotScheduleUseCase( ) ) } - } \ No newline at end of file diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/ChangeIndividualScheduleUseCase.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/ChangeIndividualScheduleUseCase.kt index c4ee4491..cadc78ef 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/ChangeIndividualScheduleUseCase.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/ChangeIndividualScheduleUseCase.kt @@ -14,8 +14,9 @@ import team.comit.simtong.global.annotation.UseCase * 개인 일정 정보 변경 요청을 담당하는 ChangeIndividualScheduleUseCase * * @author Chokyunghyeon + * @author kimbeomjin * @date 2022/11/27 - * @version 1.0.0 + * @version 1.2.5 **/ @UseCase class ChangeIndividualScheduleUseCase( @@ -35,18 +36,14 @@ class ChangeIndividualScheduleUseCase( val user = queryUserPort.queryUserById(currentUserId) ?: throw UserExceptions.NotFound() - if (user.id != schedule.userId) { - throw ScheduleExceptions.NotScheduleOwner() - } - commandSchedulePort.save( - schedule.copy( + schedule.changeIndividualSchedule( title = title, startAt = startAt, endAt = endAt, - alarmTime = alarm + alarmTime = alarm, + userId = user.id ) ) } - } \ No newline at end of file diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/ChangeSpotScheduleUseCase.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/ChangeSpotScheduleUseCase.kt index 584076cc..f336f9b2 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/ChangeSpotScheduleUseCase.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/ChangeSpotScheduleUseCase.kt @@ -16,8 +16,9 @@ import team.comit.simtong.global.annotation.UseCase * 지점 일정 변경 기능을 담당하는 ChangeSpotScheduleUseCase * * @author Chokyunghyeon + * @author kimbeomjin * @date 2022/11/22 - * @version 1.0.0 + * @version 1.2.5 **/ @UseCase class ChangeSpotScheduleUseCase( @@ -36,15 +37,12 @@ class ChangeSpotScheduleUseCase( val schedule = querySchedulePort.queryScheduleById(request.scheduleId) ?: throw ScheduleExceptions.NotFound() - when { - Scope.ENTIRE != schedule.scope -> throw ScheduleExceptions.NotScheduleOwner() - - user.spotId != schedule.spotId && Authority.ROLE_SUPER != user.authority -> - throw UserExceptions.NotEnoughPermission("같은 지점 관리자이거나 최고 관리자이어야 합니다.") + if (!schedule.isSameSpot(user.spotId) && user.authority != Authority.ROLE_SUPER) { + throw UserExceptions.NotEnoughPermission("같은 지점 관리자이거나 최고 관리자이어야 합니다.") } commandSchedulePort.save( - schedule.copy( + schedule.changeEntireSchedule( title = request.title, startAt = request.startAt, endAt = request.endAt diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/QueryEntireSpotScheduleUseCase.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/QueryEntireSpotScheduleUseCase.kt index d87e4148..c536e4a6 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/QueryEntireSpotScheduleUseCase.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/QueryEntireSpotScheduleUseCase.kt @@ -38,5 +38,4 @@ class QueryEntireSpotScheduleUseCase( return QueryEntireSpotScheduleResponse(response) } - } \ No newline at end of file diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/RemoveIndividualScheduleUseCase.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/RemoveIndividualScheduleUseCase.kt index 7cd050b7..afcf49c6 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/RemoveIndividualScheduleUseCase.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/RemoveIndividualScheduleUseCase.kt @@ -16,7 +16,7 @@ import java.util.UUID * * @author kimbeomjin * @date 2022/12/03 - * @version 1.0.0 + * @version 1.2.5 **/ @UseCase class RemoveIndividualScheduleUseCase( @@ -35,13 +35,8 @@ class RemoveIndividualScheduleUseCase( val schedule = querySchedulePort.queryScheduleById(scheduleId) ?: throw ScheduleExceptions.NotFound() - if (user.id != schedule.userId) { - throw ScheduleExceptions.NotScheduleOwner() - } - - if (Scope.INDIVIDUAL != schedule.scope) { - throw ScheduleExceptions.DifferentScope("개인 일정이 아닙니다.") - } + schedule.checkScope(Scope.INDIVIDUAL) + schedule.checkOwner(user.id) commandSchedulePort.delete(schedule) } diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/RemoveSpotScheduleUseCase.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/RemoveSpotScheduleUseCase.kt index 210cdddd..e31ea738 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/RemoveSpotScheduleUseCase.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/RemoveSpotScheduleUseCase.kt @@ -17,7 +17,7 @@ import java.util.UUID * * @author Chokyunghyeon * @date 2022/11/22 - * @version 1.0.0 + * @version 1.2.5 **/ @UseCase class RemoveSpotScheduleUseCase( @@ -36,15 +36,12 @@ class RemoveSpotScheduleUseCase( val schedule = querySchedulePort.queryScheduleById(scheduleId) ?: throw ScheduleExceptions.NotFound() - if (user.spotId != schedule.spotId && user.authority != Authority.ROLE_SUPER) { - throw UserExceptions.NotEnoughPermission("같은 지점 관리자이거나 최고 관리자이어야 합니다.") - } + schedule.checkScope(Scope.ENTIRE) - if (Scope.ENTIRE != schedule.scope) { - throw ScheduleExceptions.DifferentScope("지점 일정이 아닙니다.") + if (!schedule.isSameSpot(user.spotId) && user.authority != Authority.ROLE_SUPER) { + throw UserExceptions.NotEnoughPermission("같은 지점 관리자이거나 최고 관리자이어야 합니다.") } commandSchedulePort.delete(schedule) } - } \ No newline at end of file diff --git a/simtong-application/src/test/kotlin/team/comit/simtong/domain/schedule/usecase/ChangeIndividualScheduleUseCaseTest.kt b/simtong-application/src/test/kotlin/team/comit/simtong/domain/schedule/usecase/ChangeIndividualScheduleUseCaseTest.kt index 34445c09..6ae48c29 100644 --- a/simtong-application/src/test/kotlin/team/comit/simtong/domain/schedule/usecase/ChangeIndividualScheduleUseCaseTest.kt +++ b/simtong-application/src/test/kotlin/team/comit/simtong/domain/schedule/usecase/ChangeIndividualScheduleUseCaseTest.kt @@ -65,7 +65,7 @@ class ChangeIndividualScheduleUseCaseTest { password = "test password", employeeNumber = 1234567890, authority = Authority.ROLE_COMMON, - spotId = UUID.randomUUID(), + spotId = spotId, teamId = UUID.randomUUID(), profileImagePath = "test profile image" ) @@ -112,35 +112,6 @@ class ChangeIndividualScheduleUseCaseTest { } } - @Test - fun `소유자가 아님`() { - // given - val otherScheduleStub = Schedule( - id = scheduleId, - userId = UUID.randomUUID(), - spotId = spotId, - title = "test title", - scope = Scope.INDIVIDUAL, - startAt = LocalDate.now(), - endAt = LocalDate.now(), - alarmTime = Schedule.DEFAULT_ALARM_TIME - ) - - given(securityPort.getCurrentUserId()) - .willReturn(userId) - - given(querySchedulePort.queryScheduleById(requestStub.scheduleId)) - .willReturn(otherScheduleStub) - - given(queryUserPort.queryUserById(userId)) - .willReturn(userStub) - - // when & then - assertThrows { - changeIndividualScheduleUseCase.execute(requestStub) - } - } - @Test fun `유저를 찾을 수 없음`() { // given diff --git a/simtong-application/src/test/kotlin/team/comit/simtong/domain/schedule/usecase/ChangeSpotScheduleUseCaseTests.kt b/simtong-application/src/test/kotlin/team/comit/simtong/domain/schedule/usecase/ChangeSpotScheduleUseCaseTests.kt index 004d8846..6fcf844b 100644 --- a/simtong-application/src/test/kotlin/team/comit/simtong/domain/schedule/usecase/ChangeSpotScheduleUseCaseTests.kt +++ b/simtong-application/src/test/kotlin/team/comit/simtong/domain/schedule/usecase/ChangeSpotScheduleUseCaseTests.kt @@ -144,7 +144,7 @@ class ChangeSpotScheduleUseCaseTests { .willReturn(individualScheduleStub) // when & then - assertThrows { + assertThrows { changeSpotScheduleUseCase.execute(requestStub) } } diff --git a/simtong-domain/src/main/kotlin/team/comit/simtong/domain/schedule/model/Schedule.kt b/simtong-domain/src/main/kotlin/team/comit/simtong/domain/schedule/model/Schedule.kt index 30f907c0..38f6ca3a 100644 --- a/simtong-domain/src/main/kotlin/team/comit/simtong/domain/schedule/model/Schedule.kt +++ b/simtong-domain/src/main/kotlin/team/comit/simtong/domain/schedule/model/Schedule.kt @@ -1,5 +1,6 @@ package team.comit.simtong.domain.schedule.model +import team.comit.simtong.domain.schedule.exception.ScheduleExceptions import java.time.LocalDate import java.time.LocalTime import java.util.UUID @@ -9,11 +10,12 @@ import java.util.UUID * 일정 Aggregate의 Root를 담당하는 Schedule * * @author Chokyunghyeon + * @author kimbeomjin * @date 2022/11/21 - * @version 1.0.0 + * @version 1.2.5 **/ data class Schedule( - val id: UUID = UUID(0, 0), + val id: UUID, val userId: UUID, @@ -27,7 +29,7 @@ data class Schedule( val endAt: LocalDate, - val alarmTime: LocalTime = DEFAULT_ALARM_TIME + val alarmTime: LocalTime ) { companion object { @@ -35,7 +37,74 @@ data class Schedule( /** * Default AM 8:30 */ - val DEFAULT_ALARM_TIME: LocalTime = LocalTime.of(8,30) + val DEFAULT_ALARM_TIME: LocalTime = LocalTime.of(8, 30) + + fun of( + id: UUID = UUID(0, 0), + userId: UUID, + spotId: UUID, + title: String, + scope: Scope, + startAt: LocalDate, + endAt: LocalDate, + alarmTime: LocalTime = DEFAULT_ALARM_TIME + ) = Schedule( + id = id, + userId = userId, + spotId = spotId, + title = title, + scope = scope, + startAt = startAt, + endAt = endAt, + alarmTime = alarmTime + ) + } + + fun isSameSpot(spotId: UUID) = this.spotId == spotId + + fun changeIndividualSchedule( + title: String, + startAt: LocalDate, + endAt: LocalDate, + alarmTime: LocalTime, + userId: UUID + ): Schedule { + checkScope(Scope.INDIVIDUAL) + checkOwner(userId) + + return this.copy( + title = title, + startAt = startAt, + endAt = endAt, + alarmTime = alarmTime + ) + } + + fun changeEntireSchedule( + title: String, + startAt: LocalDate, + endAt: LocalDate + ): Schedule { + checkScope(Scope.ENTIRE) + + return this.copy( + title = title, + startAt = startAt, + endAt = endAt + ) + } + + fun checkOwner(userId: UUID) { + if (this.userId != userId) { + throw ScheduleExceptions.NotScheduleOwner() + } } + fun checkScope(scope: Scope) { + when (scope) { + Scope.INDIVIDUAL -> if (this.scope != Scope.INDIVIDUAL) throw ScheduleExceptions.DifferentScope("개인 일정이 아닙니다.") + + Scope.ENTIRE -> if (this.scope != Scope.ENTIRE) throw ScheduleExceptions.DifferentScope("지점 일정이 아닙니다.") + } + } } \ No newline at end of file diff --git a/simtong-infrastructure/build.gradle.kts b/simtong-infrastructure/build.gradle.kts index 2b2db47a..112040c5 100644 --- a/simtong-infrastructure/build.gradle.kts +++ b/simtong-infrastructure/build.gradle.kts @@ -55,13 +55,6 @@ dependencies { testImplementation(Dependencies.S3MOCK) } -kapt { - arguments { - arg("mapstruct.defaultComponentModel", "spring") - arg("mapstruct.unmappedTargetPolicy", "ignore") - } -} - allOpen { annotation("javax.persistence.Entity") annotation("javax.persistence.MappedSuperclass")