Skip to content

Commit

Permalink
merge: (#141) 지점 일정 변경 (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
khcho0125 authored Nov 23, 2022
2 parents 85e904a + 49b9de0 commit bbeaaf7
Show file tree
Hide file tree
Showing 14 changed files with 408 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package team.comit.simtong.domain.schedule.dto

import java.time.LocalDate
import java.util.UUID

/**
*
* 지점 일정 변경 요청 정보를 전달하는 ChangeSpotScheduleRequest
*
* @author Chokyunghyeon
* @date 2022/11/22
* @version 1.0.0
**/
data class ChangeSpotScheduleRequest(
val scheduleId: UUID,

val title: String,

val startAt: LocalDate,

val endAt: LocalDate
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ package team.comit.simtong.domain.schedule.spi
* @date 2022/11/21
* @version 1.0.0
**/
interface SchedulePort : CommandSchedulePort
interface SchedulePort : CommandSchedulePort, QuerySchedulePort
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ import team.comit.simtong.global.annotation.UseCase
**/
@UseCase
class AddSpotScheduleUseCase(
private val scheduleQueryUserPort: ScheduleQueryUserPort,
private val queryUserPort: ScheduleQueryUserPort,
private val commandSchedulePort: CommandSchedulePort,
private val scheduleSecurityPort: ScheduleSecurityPort
private val securityPort: ScheduleSecurityPort
) {

fun execute(request: AddSpotScheduleRequest) {
val currentUserId = scheduleSecurityPort.getCurrentUserId()
val currentUserId = securityPort.getCurrentUserId()
val (spotId, title, startAt, endAt) = request

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

if (user.authority != Authority.ROLE_SUPER && spotId != user.spotId) {
if (user.spotId != spotId && user.authority != Authority.ROLE_SUPER) {
throw NotEnoughPermissionException.EXCEPTION
}

Expand Down
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.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.global.annotation.UseCase

/**
*
* 지점 일정 변경 기능을 담당하는 ChangeSpotScheduleUseCase
*
* @author Chokyunghyeon
* @date 2022/11/22
* @version 1.0.0
**/
@UseCase
class ChangeSpotScheduleUseCase(
private val queryUserPort: ScheduleQueryUserPort,
private val querySchedulePort: QuerySchedulePort,
private val commandSchedulePort: CommandSchedulePort,
private val securityPort: ScheduleSecurityPort
) {

fun execute(request: ChangeSpotScheduleRequest) {
val currentUserId = securityPort.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
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import java.util.UUID
class AddSpotScheduleUseCaseTests {

@MockBean
private lateinit var scheduleSecurityPort: ScheduleSecurityPort
private lateinit var securityPort: ScheduleSecurityPort

@MockBean
private lateinit var commandSchedulePort: CommandSchedulePort

@MockBean
private lateinit var scheduleQueryUserPort: ScheduleQueryUserPort
private lateinit var queryUserPort: ScheduleQueryUserPort

private lateinit var addSpotScheduleUseCase: AddSpotScheduleUseCase

Expand All @@ -49,7 +49,7 @@ class AddSpotScheduleUseCaseTests {
@BeforeEach
fun setUp() {
addSpotScheduleUseCase = AddSpotScheduleUseCase(
scheduleQueryUserPort, commandSchedulePort, scheduleSecurityPort
queryUserPort, commandSchedulePort, securityPort
)
}

Expand All @@ -69,10 +69,10 @@ class AddSpotScheduleUseCaseTests {
profileImagePath = "test profile image"
)

given(scheduleSecurityPort.getCurrentUserId())
given(securityPort.getCurrentUserId())
.willReturn(userId)

given(scheduleQueryUserPort.queryUserById(userId))
given(queryUserPort.queryUserById(userId))
.willReturn(userStub)

// when & then
Expand All @@ -97,10 +97,10 @@ class AddSpotScheduleUseCaseTests {
profileImagePath = "test profile image"
)

given(scheduleSecurityPort.getCurrentUserId())
given(securityPort.getCurrentUserId())
.willReturn(userId)

given(scheduleQueryUserPort.queryUserById(userId))
given(queryUserPort.queryUserById(userId))
.willReturn(userStub)

// when & then
Expand All @@ -125,10 +125,10 @@ class AddSpotScheduleUseCaseTests {
profileImagePath = "test profile image"
)

given(scheduleSecurityPort.getCurrentUserId())
given(securityPort.getCurrentUserId())
.willReturn(userId)

given(scheduleQueryUserPort.queryUserById(userId))
given(queryUserPort.queryUserById(userId))
.willReturn(userStub)

// when & then
Expand All @@ -140,10 +140,10 @@ class AddSpotScheduleUseCaseTests {
@Test
fun `유저를 찾을 수 없음`() {
// given
given(scheduleSecurityPort.getCurrentUserId())
given(securityPort.getCurrentUserId())
.willReturn(userId)

given(scheduleQueryUserPort.queryUserById(userId))
given(queryUserPort.queryUserById(userId))
.willReturn(null)

// when & then
Expand Down
Loading

0 comments on commit bbeaaf7

Please sign in to comment.