From ba64ffbfd172f5c183252c46cda5b85b5a980cb9 Mon Sep 17 00:00:00 2001 From: KimBeomJin Date: Sat, 3 Dec 2022 19:14:35 +0900 Subject: [PATCH] =?UTF-8?q?chore:=20(#167)=20=EC=9D=BC=EC=A0=95=20?= =?UTF-8?q?=EB=B2=94=EC=9C=84=EA=B0=80=20=EB=8B=A4=EB=A5=BC=20=EA=B2=BD?= =?UTF-8?q?=EC=9A=B0=20=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RemoveIndividualScheduleUseCase.kt | 11 +++-- .../usecase/RemoveSpotScheduleUseCase.kt | 6 +++ .../RemoveIndividualScheduleUseCaseTests.kt | 11 ++--- .../usecase/RemoveSpotScheduleUseCaseTests.kt | 43 +++++++++++++++++++ .../schedule/error/ScheduleErrorCode.kt | 3 ++ .../exception/DifferentScopeException.kt | 20 +++++++++ 6 files changed, 86 insertions(+), 8 deletions(-) create mode 100644 simtong-domain/src/main/kotlin/team/comit/simtong/domain/schedule/exception/DifferentScopeException.kt 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 61789063..58c8867f 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 @@ -1,12 +1,13 @@ 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.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.global.annotation.UseCase import java.util.UUID @@ -36,8 +37,12 @@ class RemoveIndividualScheduleUseCase( val schedule = querySchedulePort.queryScheduleById(scheduleId) ?: throw ScheduleNotFoundException.EXCEPTION - if (user.id != schedule.userId || Scope.INDIVIDUAL != schedule.scope) { - throw NotEnoughPermissionException.EXCEPTION + if (user.id != schedule.userId) { + throw NotScheduleOwnerException.EXCEPTION + } + + if (Scope.INDIVIDUAL != schedule.scope) { + throw DifferentScopeException.EXCEPTION } 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 275967c5..4eaa66f8 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 @@ -1,6 +1,8 @@ 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.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 @@ -40,6 +42,10 @@ class RemoveSpotScheduleUseCase( throw NotEnoughPermissionException.EXCEPTION } + if (Scope.ENTIRE != schedule.scope) { + throw DifferentScopeException.EXCEPTION + } + commandSchedulePort.delete(schedule) } diff --git a/simtong-application/src/test/kotlin/team/comit/simtong/domain/schedule/usecase/RemoveIndividualScheduleUseCaseTests.kt b/simtong-application/src/test/kotlin/team/comit/simtong/domain/schedule/usecase/RemoveIndividualScheduleUseCaseTests.kt index 969c1f93..805186cc 100644 --- a/simtong-application/src/test/kotlin/team/comit/simtong/domain/schedule/usecase/RemoveIndividualScheduleUseCaseTests.kt +++ b/simtong-application/src/test/kotlin/team/comit/simtong/domain/schedule/usecase/RemoveIndividualScheduleUseCaseTests.kt @@ -6,6 +6,8 @@ import org.junit.jupiter.api.assertDoesNotThrow import org.junit.jupiter.api.assertThrows import org.mockito.kotlin.given import org.springframework.boot.test.mock.mockito.MockBean +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.model.Schedule import team.comit.simtong.domain.schedule.model.Scope @@ -13,7 +15,6 @@ 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.model.Authority import team.comit.simtong.domain.user.model.User @@ -147,7 +148,7 @@ class RemoveIndividualScheduleUseCaseTests { } @Test - fun `권한이 부족함 - 다른 사용자`() { + fun `자신의 일정이 아님`() { // given val scheduleStub = Schedule( id = scheduleId, @@ -170,13 +171,13 @@ class RemoveIndividualScheduleUseCaseTests { .willReturn(scheduleStub) // when & then - assertThrows { + assertThrows { removeIndividualScheduleUseCase.execute(scheduleId) } } @Test - fun `권한이 부족함 - 지점 일정`() { + fun `일정 범위가 다름`() { // given val scheduleStub = Schedule( id = scheduleId, @@ -199,7 +200,7 @@ class RemoveIndividualScheduleUseCaseTests { .willReturn(scheduleStub) // when & then - assertThrows { + assertThrows { removeIndividualScheduleUseCase.execute(scheduleId) } } diff --git a/simtong-application/src/test/kotlin/team/comit/simtong/domain/schedule/usecase/RemoveSpotScheduleUseCaseTests.kt b/simtong-application/src/test/kotlin/team/comit/simtong/domain/schedule/usecase/RemoveSpotScheduleUseCaseTests.kt index 15332376..72b076c4 100644 --- a/simtong-application/src/test/kotlin/team/comit/simtong/domain/schedule/usecase/RemoveSpotScheduleUseCaseTests.kt +++ b/simtong-application/src/test/kotlin/team/comit/simtong/domain/schedule/usecase/RemoveSpotScheduleUseCaseTests.kt @@ -6,6 +6,7 @@ import org.junit.jupiter.api.assertDoesNotThrow import org.junit.jupiter.api.assertThrows import org.mockito.kotlin.given import org.springframework.boot.test.mock.mockito.MockBean +import team.comit.simtong.domain.schedule.exception.DifferentScopeException import team.comit.simtong.domain.schedule.exception.ScheduleNotFoundException import team.comit.simtong.domain.schedule.model.Schedule import team.comit.simtong.domain.schedule.model.Scope @@ -160,6 +161,48 @@ class RemoveSpotScheduleUseCaseTests { } } + @Test + fun `일정 범위가 다름`() { + // given + val userStub = User( + id = userId, + nickname = "test nickname", + name = "test name", + email = "test@test.com", + password = "test password", + employeeNumber = 1234567890, + authority = Authority.ROLE_SUPER, + spotId = UUID.randomUUID(), + teamId = UUID.randomUUID(), + profileImagePath = "test profile image" + ) + + val scheduleStub = Schedule( + id = scheduleId, + userId = userId, + 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(queryUserPort.queryUserById(userId)) + .willReturn(userStub) + + given(querySchedulePort.queryScheduleById(scheduleId)) + .willReturn(scheduleStub) + + // when & then + assertThrows { + removeSpotScheduleUseCase.execute(scheduleId) + } + } + @Test fun `일정을 찾을 수 없음`() { // given diff --git a/simtong-domain/src/main/kotlin/team/comit/simtong/domain/schedule/error/ScheduleErrorCode.kt b/simtong-domain/src/main/kotlin/team/comit/simtong/domain/schedule/error/ScheduleErrorCode.kt index a2fc14dd..314c4928 100644 --- a/simtong-domain/src/main/kotlin/team/comit/simtong/domain/schedule/error/ScheduleErrorCode.kt +++ b/simtong-domain/src/main/kotlin/team/comit/simtong/domain/schedule/error/ScheduleErrorCode.kt @@ -15,6 +15,9 @@ enum class ScheduleErrorCode( private val message: String ) : ErrorProperty { + // 401 + DIFFERENT_SCHEDULE_SCOPE(401, "일정의 범위가 다름"), + // 403 NOT_SCHEDULE_OWNER(403, "일정의 소유자가 아님"), diff --git a/simtong-domain/src/main/kotlin/team/comit/simtong/domain/schedule/exception/DifferentScopeException.kt b/simtong-domain/src/main/kotlin/team/comit/simtong/domain/schedule/exception/DifferentScopeException.kt new file mode 100644 index 00000000..0ea354c7 --- /dev/null +++ b/simtong-domain/src/main/kotlin/team/comit/simtong/domain/schedule/exception/DifferentScopeException.kt @@ -0,0 +1,20 @@ +package team.comit.simtong.domain.schedule.exception + +import team.comit.simtong.domain.schedule.error.ScheduleErrorCode +import team.comit.simtong.global.error.BusinessException + +/** + * + * Different Schedule Scope Error를 발생시키는 DifferentScopeException + * + * @author kimbeomjin + * @date 2022/12/03 + * @version 1.0.0 + **/ +class DifferentScopeException private constructor(): BusinessException(ScheduleErrorCode.DIFFERENT_SCHEDULE_SCOPE) { + + companion object { + @JvmField + val EXCEPTION = DifferentScopeException() + } +} \ No newline at end of file