-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
...n/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/ChangeSpotScheduleUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package team.comit.simtong.domain.schedule.usecase | ||
|
||
import team.comit.simtong.domain.schedule.dto.ChangeSpotScheduleRequest | ||
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.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.spi.QueryUserPort | ||
import team.comit.simtong.global.annotation.UseCase | ||
|
||
/** | ||
* | ||
* 지점 일정 변경 기능을 담당하는 ChangeSpotScheduleUseCase | ||
* | ||
* @author Chokyunghyeon | ||
* @date 2022/11/22 | ||
* @version 1.0.0 | ||
**/ | ||
@UseCase | ||
class ChangeSpotScheduleUseCase( | ||
private val queryUserPort: QueryUserPort, | ||
private val querySchedulePort: QuerySchedulePort, | ||
private val commandSchedulePort: CommandSchedulePort, | ||
private val scheduleSecurityPort: ScheduleSecurityPort | ||
) { | ||
|
||
fun execute(request: ChangeSpotScheduleRequest) { | ||
val currentUserId = scheduleSecurityPort.getCurrentUserId() | ||
|
||
val user = queryUserPort.queryUserById(currentUserId) | ||
?: throw UserNotFoundException.EXCEPTION | ||
|
||
val schedule = querySchedulePort.queryScheduleById(request.scheduleId) | ||
?: throw ScheduleNotFoundException.EXCEPTION | ||
|
||
if (user.spotId != schedule.spotId && user.authority != Authority.ROLE_SUPER) { | ||
throw NotEnoughPermissionException.EXCEPTION | ||
} | ||
|
||
commandSchedulePort.save( | ||
schedule.copy( | ||
title = request.title, | ||
startAt = request.startAt, | ||
endAt = request.endAt | ||
) | ||
) | ||
} | ||
} |