From e2bab716e999fd417a3d03112888e95a176a5e06 Mon Sep 17 00:00:00 2001 From: Jo Kyung Hyeon Date: Sun, 27 Nov 2022 13:22:03 +0900 Subject: [PATCH] =?UTF-8?q?add:=20(#156)=20=EA=B0=9C=EC=9D=B8=20=EC=9D=BC?= =?UTF-8?q?=EC=A0=95=20=EB=B3=80=EA=B2=BD=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/ChangeIndividualScheduleRequest.kt | 26 +++++++++ .../ChangeIndividualScheduleUseCase.kt | 53 +++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/dto/ChangeIndividualScheduleRequest.kt create mode 100644 simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/ChangeIndividualScheduleUseCase.kt diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/dto/ChangeIndividualScheduleRequest.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/dto/ChangeIndividualScheduleRequest.kt new file mode 100644 index 00000000..3e271314 --- /dev/null +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/dto/ChangeIndividualScheduleRequest.kt @@ -0,0 +1,26 @@ +package team.comit.simtong.domain.schedule.dto + +import java.time.LocalDate +import java.time.LocalTime +import java.util.UUID + +/** + * + * 개인 일정 변경 요청 정보를 전달하는 ChangeIndividualScheduleRequest + * + * @author Chokyunghyeon + * @date 2022/11/27 + * @version 1.0.0 + **/ +data class ChangeIndividualScheduleRequest( + + val scheduleId: UUID, + + val title: String, + + val startAt: LocalDate, + + val endAt: LocalDate, + + val alarm: LocalTime +) \ 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 new file mode 100644 index 00000000..74d79426 --- /dev/null +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/ChangeIndividualScheduleUseCase.kt @@ -0,0 +1,53 @@ +package team.comit.simtong.domain.schedule.usecase + +import team.comit.simtong.domain.schedule.dto.ChangeIndividualScheduleRequest +import team.comit.simtong.domain.schedule.exception.ScheduleNotFoundException +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.spot.exception.DifferentSpotException +import team.comit.simtong.domain.user.exception.UserNotFoundException +import team.comit.simtong.global.annotation.UseCase + +/** + * + * 개인 일정 정보 변경 요청을 담당하는 ChangeIndividualScheduleUseCase + * + * @author Chokyunghyeon + * @date 2022/11/27 + * @version 1.0.0 + **/ +@UseCase +class ChangeIndividualScheduleUseCase( + private val queryUserPort: ScheduleQueryUserPort, + private val querySchedulePort: QuerySchedulePort, + private val commandSchedulePort: CommandSchedulePort, + private val securityPort: ScheduleSecurityPort +) { + + fun execute(request: ChangeIndividualScheduleRequest) { + val currentUserId = securityPort.getCurrentUserId() + val (scheduleId, title, startAt, endAt, alarm) = request + + val schedule = querySchedulePort.queryScheduleById(scheduleId) + ?: throw ScheduleNotFoundException.EXCEPTION + + val user = queryUserPort.queryUserById(currentUserId) + ?: throw UserNotFoundException.EXCEPTION + + if (user.spotId != schedule.spotId) { + throw DifferentSpotException.EXCEPTION + } + + commandSchedulePort.save( + schedule.copy( + title = title, + startAt = startAt, + endAt = endAt, + alarmTime = alarm + ) + ) + } + +} \ No newline at end of file