From 14f933c1287f4cd84b784eefddba728323c6a842 Mon Sep 17 00:00:00 2001 From: KimBeomJin Date: Mon, 9 Jan 2023 20:22:33 +0900 Subject: [PATCH 1/3] =?UTF-8?q?refactor:=20(#286)=20Holiday=20Aggregate=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refactor: (#286) Holiday Aggregate 리팩토링 --- .../holiday/usecase/AppointAnnualUseCase.kt | 29 ++++-------- .../holiday/usecase/AppointHolidayUseCase.kt | 23 +++++----- .../holiday/usecase/CancelHolidayUseCase.kt | 9 ++-- .../usecase/ChangeEmployeeHolidayUseCase.kt | 13 ++---- .../usecase/CheckHolidayPeriodUseCase.kt | 1 - .../usecase/QueryEmployeeHolidayUseCase.kt | 32 ++++--------- .../usecase/QueryIndividualHolidayUseCase.kt | 5 +-- .../usecase/QueryRemainAnnualUseCase.kt | 8 ++-- .../holiday/usecase/ShareHolidayUseCase.kt | 7 +-- .../simtong/domain/holiday/model/Holiday.kt | 45 ++++++++++++++++++- .../domain/holiday/model/HolidayQueryType.kt | 10 ++++- 11 files changed, 95 insertions(+), 87 deletions(-) diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/AppointAnnualUseCase.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/AppointAnnualUseCase.kt index d3f929f8..628f1842 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/AppointAnnualUseCase.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/AppointAnnualUseCase.kt @@ -2,7 +2,7 @@ package team.comit.simtong.domain.holiday.usecase import team.comit.simtong.domain.holiday.exception.HolidayExceptions import team.comit.simtong.domain.holiday.model.Holiday -import team.comit.simtong.domain.holiday.model.HolidayStatus +import team.comit.simtong.domain.holiday.model.Holiday.Companion.checkNotExceededAnnualLimit import team.comit.simtong.domain.holiday.model.HolidayType import team.comit.simtong.domain.holiday.spi.CommandHolidayPort import team.comit.simtong.domain.holiday.spi.HolidayQueryUserPort @@ -17,8 +17,9 @@ import java.time.LocalDate * 연차 지정을 담당하는 AppointAnnualUseCase * * @author Chokyunghyeon + * @author kimbeomjin * @date 2022/12/17 - * @version 1.0.0 + * @version 1.2.5 **/ @UseCase class AppointAnnualUseCase( @@ -36,32 +37,20 @@ class AppointAnnualUseCase( val user = queryUserPort.queryUserById(securityPort.getCurrentUserId()) ?: throw UserExceptions.NotFound() - queryHolidayPort.queryHolidayByDateAndUserId(date, user.id)?.run { - when (type) { - HolidayType.ANNUAL -> - throw HolidayExceptions.AlreadyExists("해당 날짜는 이미 연차입니다.") - - HolidayType.HOLIDAY -> if (status == HolidayStatus.COMPLETED) { - throw HolidayExceptions.AlreadyExists("해당 날짜는 이미 휴무일입니다.") - } - } + if (queryHolidayPort.existsHolidayByDateAndUserIdAndType(date, user.id, HolidayType.ANNUAL)) { + throw HolidayExceptions.AlreadyExists("해당 날짜는 이미 연차입니다.") } - val countAnnual = queryHolidayPort.countHolidayByYearAndUserIdAndType(date.year, user.id, HolidayType.ANNUAL) + val annualCount = queryHolidayPort.countHolidayByYearAndUserIdAndType(date.year, user.id, HolidayType.ANNUAL) - if (countAnnual >= Holiday.ANNUAL_LEAVE_LIMIT) { - throw HolidayExceptions.AnnualLeaveLimitExcess() - } + checkNotExceededAnnualLimit(annualCount) commandHolidayPort.save( - Holiday( + Holiday.createAnnual( date = date, userId = user.id, - spotId = user.spotId, - type = HolidayType.ANNUAL, - status = HolidayStatus.COMPLETED + spotId = user.spotId ) ) } - } \ No newline at end of file diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/AppointHolidayUseCase.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/AppointHolidayUseCase.kt index e7130cb9..9c02e88b 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/AppointHolidayUseCase.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/AppointHolidayUseCase.kt @@ -2,7 +2,7 @@ package team.comit.simtong.domain.holiday.usecase import team.comit.simtong.domain.holiday.exception.HolidayExceptions import team.comit.simtong.domain.holiday.model.Holiday -import team.comit.simtong.domain.holiday.model.HolidayStatus +import team.comit.simtong.domain.holiday.model.Holiday.Companion.checkNotExceededHolidayLimit import team.comit.simtong.domain.holiday.model.HolidayType import team.comit.simtong.domain.holiday.spi.CommandHolidayPort import team.comit.simtong.domain.holiday.spi.HolidayQueryUserPort @@ -18,8 +18,9 @@ import java.time.LocalDate * 휴무일 지정을 담당하는 AppointHolidayUseCase * * @author Chokyunghyeon + * @author kimbeomjin * @date 2022/12/03 - * @version 1.0.0 + * @version 1.2.5 **/ @UseCase class AppointHolidayUseCase( @@ -34,8 +35,9 @@ class AppointHolidayUseCase( val user = queryUserPort.queryUserById(securityPort.getCurrentUserId()) ?: throw UserExceptions.NotFound() - val holidayPeriod = queryHolidayPeriodPort.queryHolidayPeriodByYearAndMonthAndSpotId(date.year, date.monthValue, user.spotId) - ?: throw HolidayExceptions.NotFound("휴무표 작성 기간이 등록되지 않았습니다.") + val holidayPeriod = queryHolidayPeriodPort.queryHolidayPeriodByYearAndMonthAndSpotId( + date.year, date.monthValue, user.spotId + ) ?: throw HolidayExceptions.NotFound("휴무표 작성 기간이 등록되지 않았습니다.") val today = LocalDate.now() @@ -47,21 +49,16 @@ class AppointHolidayUseCase( throw HolidayExceptions.AlreadyExists("해당 날짜는 이미 휴무일입니다.") } - val countHoliday = queryHolidayPort.countHolidayByWeekAndUserIdAndType(date, user.id, HolidayType.HOLIDAY) + val holidayCount = queryHolidayPort.countHolidayByWeekAndUserIdAndType(date, user.id, HolidayType.HOLIDAY) - if (countHoliday >= Holiday.WEEK_HOLIDAY_LIMIT) { - throw HolidayExceptions.WeekHolidayLimitExcess() - } + checkNotExceededHolidayLimit(holidayCount) commandHolidayPort.save( - Holiday( + Holiday.createHoliday( date = date, userId = user.id, - type = HolidayType.HOLIDAY, - spotId = user.spotId, - status = HolidayStatus.WRITTEN + spotId = user.spotId ) ) } - } \ No newline at end of file diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/CancelHolidayUseCase.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/CancelHolidayUseCase.kt index 69ca966f..d4c274da 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/CancelHolidayUseCase.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/CancelHolidayUseCase.kt @@ -1,7 +1,6 @@ package team.comit.simtong.domain.holiday.usecase import team.comit.simtong.domain.holiday.exception.HolidayExceptions -import team.comit.simtong.domain.holiday.model.HolidayStatus import team.comit.simtong.domain.holiday.model.HolidayType import team.comit.simtong.domain.holiday.spi.CommandHolidayPort import team.comit.simtong.domain.holiday.spi.HolidaySecurityPort @@ -14,8 +13,9 @@ import java.time.LocalDate * 휴무일 또는 연차 취소 요청을 담당하는 CancelHolidayUseCase * * @author Chokyunghyeon + * @author kimbeomjin * @date 2022/12/04 - * @version 1.0.0 + * @version 1.2.5 **/ @UseCase class CancelHolidayUseCase( @@ -31,8 +31,8 @@ class CancelHolidayUseCase( ?: throw HolidayExceptions.NotFound() when (holiday.type) { - HolidayType.HOLIDAY -> if (holiday.status == HolidayStatus.COMPLETED) { - throw HolidayExceptions.CannotChange("결정된 휴무일는 취소할 수 없습니다.") + HolidayType.HOLIDAY -> if (holiday.isCompleted()) { + throw HolidayExceptions.CannotChange("결정된 휴무일은 취소할 수 없습니다.") } HolidayType.ANNUAL -> if (holiday.date <= LocalDate.now()) { @@ -42,5 +42,4 @@ class CancelHolidayUseCase( commandHolidayPort.delete(holiday) } - } \ No newline at end of file diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/ChangeEmployeeHolidayUseCase.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/ChangeEmployeeHolidayUseCase.kt index e822324c..61a55647 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/ChangeEmployeeHolidayUseCase.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/ChangeEmployeeHolidayUseCase.kt @@ -1,7 +1,6 @@ package team.comit.simtong.domain.holiday.usecase import team.comit.simtong.domain.holiday.exception.HolidayExceptions -import team.comit.simtong.domain.holiday.model.Holiday import team.comit.simtong.domain.holiday.model.HolidayType import team.comit.simtong.domain.holiday.spi.CommandHolidayPort import team.comit.simtong.domain.holiday.spi.HolidayQueryUserPort @@ -19,7 +18,7 @@ import java.util.UUID * * @author kimbeomjin * @date 2022/12/23 - * @version 1.0.0 + * @version 1.2.5 **/ @UseCase class ChangeEmployeeHolidayUseCase( @@ -36,18 +35,14 @@ class ChangeEmployeeHolidayUseCase( val holiday = queryHolidayPort.queryHolidayByDateAndUserId(beforeDate, userId) ?: throw HolidayExceptions.NotFound() - if (admin.spotId != holiday.spotId) { + if (!holiday.isSameSpot(admin.spotId)) { throw HolidayExceptions.CannotChange("같은 지점 직원의 휴무일만 변경할 수 있습니다.") } - val countHoliday = queryHolidayPort.countHolidayByWeekAndUserIdAndType(afterDate, userId, HolidayType.HOLIDAY) - - if (countHoliday >= Holiday.WEEK_HOLIDAY_LIMIT) { - throw HolidayExceptions.WeekHolidayLimitExcess() - } + val holidayCount = queryHolidayPort.countHolidayByWeekAndUserIdAndType(afterDate, userId, HolidayType.HOLIDAY) commandHolidayPort.save( - holiday.copy(date = afterDate) + holiday.change(holidayCount, afterDate) ) commandHolidayPort.delete(holiday) } diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/CheckHolidayPeriodUseCase.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/CheckHolidayPeriodUseCase.kt index 34e137fe..65826169 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/CheckHolidayPeriodUseCase.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/CheckHolidayPeriodUseCase.kt @@ -31,5 +31,4 @@ class CheckHolidayPeriodUseCase( throw HolidayExceptions.NotWritablePeriod() } } - } \ No newline at end of file diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/QueryEmployeeHolidayUseCase.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/QueryEmployeeHolidayUseCase.kt index e65b2e71..8388f11e 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/QueryEmployeeHolidayUseCase.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/QueryEmployeeHolidayUseCase.kt @@ -2,7 +2,6 @@ package team.comit.simtong.domain.holiday.usecase import team.comit.simtong.domain.holiday.dto.QueryEmployeeHolidayResponse import team.comit.simtong.domain.holiday.model.HolidayQueryType -import team.comit.simtong.domain.holiday.model.HolidayType import team.comit.simtong.domain.holiday.spi.HolidayQueryUserPort import team.comit.simtong.domain.holiday.spi.HolidaySecurityPort import team.comit.simtong.domain.holiday.spi.QueryHolidayPort @@ -20,7 +19,7 @@ import java.util.UUID * * @author kimbeomjin * @date 2022/12/22 - * @version 1.0.0 + * @version 1.2.5 **/ @ReadOnlyUseCase class QueryEmployeeHolidayUseCase( @@ -33,28 +32,13 @@ class QueryEmployeeHolidayUseCase( val currentUserId = securityPort.getCurrentUserId() val user = queryUserPort.queryUserById(currentUserId) ?: throw UserExceptions.NotFound() - val holidays = when (HolidayQueryType.valueOf(typeName)) { - HolidayQueryType.HOLIDAY -> queryHolidayPort.queryHolidaysByYearAndMonthAndTeamId( - year = year, month = month, - type = HolidayType.HOLIDAY, - spotId = user.spotId, - teamId = teamId - ) - - HolidayQueryType.ANNUAL -> queryHolidayPort.queryHolidaysByYearAndMonthAndTeamId( - year = year, month = month, - type = HolidayType.ANNUAL, - spotId = user.spotId, - teamId = teamId - ) - - HolidayQueryType.ALL -> queryHolidayPort.queryHolidaysByYearAndMonthAndTeamId( - year = year, month = month, - type = null, - spotId = user.spotId, - teamId = teamId - ) - } + val holidays = queryHolidayPort.queryHolidaysByYearAndMonthAndTeamId( + year = year, + month = month, + type = HolidayQueryType.valueOf(typeName).toHolidayType(), + spotId = user.spotId, + teamId = teamId + ) val response = holidays.map { QueryEmployeeHolidayResponse.Holiday( diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/QueryIndividualHolidayUseCase.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/QueryIndividualHolidayUseCase.kt index 18bdabee..9a1f7ca1 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/QueryIndividualHolidayUseCase.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/QueryIndividualHolidayUseCase.kt @@ -22,9 +22,7 @@ class QueryIndividualHolidayUseCase( private val securityPort: HolidaySecurityPort ) { - fun execute( - request: QueryIndividualRequest - ) : QueryIndividualHolidaysResponse { + fun execute(request: QueryIndividualRequest) : QueryIndividualHolidaysResponse { val currentUserId = securityPort.getCurrentUserId() val holidays = queryHolidayPort.queryHolidaysByPeriodAndUserIdAndStatus( @@ -43,5 +41,4 @@ class QueryIndividualHolidayUseCase( return QueryIndividualHolidaysResponse(response) } - } \ No newline at end of file diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/QueryRemainAnnualUseCase.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/QueryRemainAnnualUseCase.kt index 0ee557c9..89ed0394 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/QueryRemainAnnualUseCase.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/QueryRemainAnnualUseCase.kt @@ -11,8 +11,9 @@ import team.comit.simtong.global.annotation.ReadOnlyUseCase * 남은 연차 개수 확인을 담당하는 QueryRemainAnnualUseCase * * @author Chokyunghyeon + * @author kimbeomjin * @date 2022/12/20 - * @version 1.0.0 + * @version 1.2.5 **/ @ReadOnlyUseCase class QueryRemainAnnualUseCase( @@ -23,9 +24,8 @@ class QueryRemainAnnualUseCase( fun execute(year: Int): Long { val currentUserId = securityPort.getCurrentUserId() - val countAnnual = queryHolidayPort.countHolidayByYearAndUserIdAndType(year, currentUserId, HolidayType.ANNUAL) + val annualCount = queryHolidayPort.countHolidayByYearAndUserIdAndType(year, currentUserId, HolidayType.ANNUAL) - return Holiday.ANNUAL_LEAVE_LIMIT - countAnnual + return Holiday.calculateRemainedAnnualCount(annualCount) } - } \ No newline at end of file diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/ShareHolidayUseCase.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/ShareHolidayUseCase.kt index a5978ec3..dd5db05e 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/ShareHolidayUseCase.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/ShareHolidayUseCase.kt @@ -1,6 +1,5 @@ package team.comit.simtong.domain.holiday.usecase -import team.comit.simtong.domain.holiday.model.HolidayStatus import team.comit.simtong.domain.holiday.model.HolidayType import team.comit.simtong.domain.holiday.spi.CommandHolidayPort import team.comit.simtong.domain.holiday.spi.HolidayQueryUserPort @@ -15,7 +14,7 @@ import team.comit.simtong.global.annotation.UseCase * * @author kimbeomjin * @date 2022/12/21 - * @version 1.0.0 + * @version 1.2.5 **/ @UseCase class ShareHolidayUseCase( @@ -34,9 +33,7 @@ class ShareHolidayUseCase( ) val completedHolidays = holidays.map { - it.copy( - status = HolidayStatus.COMPLETED - ) + it.share() } commandHolidayPort.saveAll(completedHolidays) diff --git a/simtong-domain/src/main/kotlin/team/comit/simtong/domain/holiday/model/Holiday.kt b/simtong-domain/src/main/kotlin/team/comit/simtong/domain/holiday/model/Holiday.kt index aa9ef4b8..6fb5c050 100644 --- a/simtong-domain/src/main/kotlin/team/comit/simtong/domain/holiday/model/Holiday.kt +++ b/simtong-domain/src/main/kotlin/team/comit/simtong/domain/holiday/model/Holiday.kt @@ -1,5 +1,6 @@ package team.comit.simtong.domain.holiday.model +import team.comit.simtong.domain.holiday.exception.HolidayExceptions import team.comit.simtong.global.DomainProperties.getProperty import team.comit.simtong.global.DomainPropertiesPrefix import team.comit.simtong.global.annotation.Aggregate @@ -11,8 +12,9 @@ import java.util.UUID * 휴무일의 Root Aggregate를 담당하는 Holiday * * @author Chokyunghyeon + * @author kimbeomjin * @date 2022/12/02 - * @version 1.0.0 + * @version 1.2.5 **/ @Aggregate data class Holiday( @@ -33,5 +35,46 @@ data class Holiday( val ANNUAL_LEAVE_LIMIT: Long = getProperty(DomainPropertiesPrefix.ANNUAL_LEAVE_LIMIT).toLong() + fun createHoliday( + date: LocalDate, + userId: UUID, + type: HolidayType = HolidayType.HOLIDAY, + spotId: UUID, + status: HolidayStatus = HolidayStatus.WRITTEN + ) = Holiday(date, userId, type, spotId, status) + + fun createAnnual( + date: LocalDate, + userId: UUID, + type: HolidayType = HolidayType.ANNUAL, + spotId: UUID, + status: HolidayStatus = HolidayStatus.COMPLETED + ) = Holiday(date, userId, type, spotId, status) + + fun calculateRemainedAnnualCount(annualCount: Long) = ANNUAL_LEAVE_LIMIT - annualCount + + fun checkNotExceededHolidayLimit(holidayCount: Long) { + if (holidayCount >= WEEK_HOLIDAY_LIMIT) { + throw HolidayExceptions.WeekHolidayLimitExcess() + } + } + + fun checkNotExceededAnnualLimit(annualCount: Long) { + if (annualCount >= ANNUAL_LEAVE_LIMIT) { + throw HolidayExceptions.AnnualLeaveLimitExcess() + } + } + } + + fun share() = this.copy(status = HolidayStatus.COMPLETED) + + fun isSameSpot(spotId: UUID) = this.spotId == spotId + + fun isCompleted() = this.status == HolidayStatus.COMPLETED + + fun change(holidayCount: Long, to: LocalDate): Holiday { + checkNotExceededHolidayLimit(holidayCount) + + return this.copy(date = to) } } \ No newline at end of file diff --git a/simtong-domain/src/main/kotlin/team/comit/simtong/domain/holiday/model/HolidayQueryType.kt b/simtong-domain/src/main/kotlin/team/comit/simtong/domain/holiday/model/HolidayQueryType.kt index 1315ccee..2f2f3c8c 100644 --- a/simtong-domain/src/main/kotlin/team/comit/simtong/domain/holiday/model/HolidayQueryType.kt +++ b/simtong-domain/src/main/kotlin/team/comit/simtong/domain/holiday/model/HolidayQueryType.kt @@ -6,7 +6,7 @@ package team.comit.simtong.domain.holiday.model * * @author kimbeomjin * @date 2022/12/22 - * @version 1.0.0 + * @version 1.2.5 **/ enum class HolidayQueryType { @@ -24,5 +24,13 @@ enum class HolidayQueryType { * 연차 */ ANNUAL + ; + fun toHolidayType(): HolidayType? { + return when (this) { + HOLIDAY -> HolidayType.HOLIDAY + ANNUAL -> HolidayType.ANNUAL + ALL -> null + } + } } \ No newline at end of file From 11c81ce9ce0c6bccad5ebe1de0234248c8e59666 Mon Sep 17 00:00:00 2001 From: KimBeomJin Date: Mon, 9 Jan 2023 20:27:12 +0900 Subject: [PATCH 2/3] =?UTF-8?q?test:=20(#286)=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usecase/AppointAnnualUseCaseTests.kt | 51 +++---------------- 1 file changed, 8 insertions(+), 43 deletions(-) diff --git a/simtong-application/src/test/kotlin/team/comit/simtong/domain/holiday/usecase/AppointAnnualUseCaseTests.kt b/simtong-application/src/test/kotlin/team/comit/simtong/domain/holiday/usecase/AppointAnnualUseCaseTests.kt index 85fb9360..6ccb4d75 100644 --- a/simtong-application/src/test/kotlin/team/comit/simtong/domain/holiday/usecase/AppointAnnualUseCaseTests.kt +++ b/simtong-application/src/test/kotlin/team/comit/simtong/domain/holiday/usecase/AppointAnnualUseCaseTests.kt @@ -76,8 +76,8 @@ class AppointAnnualUseCaseTests { given(queryUserPort.queryUserById(id)) .willReturn(userStub) - given(queryHolidayPort.queryHolidayByDateAndUserId(date, id)) - .willReturn(null) + given(queryHolidayPort.existsHolidayByDateAndUserIdAndType(date, userStub.id, HolidayType.ANNUAL)) + .willReturn(false) given(queryHolidayPort.countHolidayByYearAndUserIdAndType(date.year, id, HolidayType.ANNUAL)) .willReturn(0) @@ -97,8 +97,8 @@ class AppointAnnualUseCaseTests { given(queryUserPort.queryUserById(id)) .willReturn(userStub) - given(queryHolidayPort.queryHolidayByDateAndUserId(date, id)) - .willReturn(null) + given(queryHolidayPort.existsHolidayByDateAndUserIdAndType(date, userStub.id, HolidayType.ANNUAL)) + .willReturn(false) given(queryHolidayPort.countHolidayByYearAndUserIdAndType(date.year, id, HolidayType.ANNUAL)) .willReturn(Holiday.ANNUAL_LEAVE_LIMIT) @@ -112,22 +112,14 @@ class AppointAnnualUseCaseTests { @Test fun `작성중인 휴무일을 변경할 때`() { // given - val holidayStub = Holiday( - date = date, - spotId = id, - type = HolidayType.HOLIDAY, - userId = id, - status = HolidayStatus.WRITTEN - ) - given(securityPort.getCurrentUserId()) .willReturn(id) given(queryUserPort.queryUserById(id)) .willReturn(userStub) - given(queryHolidayPort.queryHolidayByDateAndUserId(date, userStub.id)) - .willReturn(holidayStub) + given(queryHolidayPort.existsHolidayByDateAndUserIdAndType(date, userStub.id, HolidayType.ANNUAL)) + .willReturn(false) given(queryHolidayPort.countHolidayByYearAndUserIdAndType(date.year, id, HolidayType.ANNUAL)) .willReturn(0) @@ -138,32 +130,6 @@ class AppointAnnualUseCaseTests { } } - @Test - fun `확정된 휴무일을 변경할 때`() { - // given - val holidayStub = Holiday( - date = date, - spotId = id, - type = HolidayType.HOLIDAY, - userId = id, - status = HolidayStatus.COMPLETED - ) - - given(securityPort.getCurrentUserId()) - .willReturn(id) - - given(queryUserPort.queryUserById(id)) - .willReturn(userStub) - - given(queryHolidayPort.queryHolidayByDateAndUserId(date, userStub.id)) - .willReturn(holidayStub) - - // when & then - assertThrows { - appointAnnualUseCase.execute(date) - } - } - @Test fun `이미 연차일때`() { // given @@ -181,8 +147,8 @@ class AppointAnnualUseCaseTests { given(queryUserPort.queryUserById(id)) .willReturn(userStub) - given(queryHolidayPort.queryHolidayByDateAndUserId(date, userStub.id)) - .willReturn(annualStub) + given(queryHolidayPort.existsHolidayByDateAndUserIdAndType(date, userStub.id, HolidayType.ANNUAL)) + .willReturn(true) // when & then assertThrows { @@ -212,5 +178,4 @@ class AppointAnnualUseCaseTests { appointAnnualUseCase.execute(LocalDate.MIN) } } - } \ No newline at end of file From 71a7afc8433871987f9fb8c8a9acfe0b5d02de38 Mon Sep 17 00:00:00 2001 From: KimBeomJin Date: Mon, 9 Jan 2023 22:39:07 +0900 Subject: [PATCH 3/3] refactor: (#286) share() -> complete() --- .../comit/simtong/domain/holiday/usecase/ShareHolidayUseCase.kt | 2 +- .../kotlin/team/comit/simtong/domain/holiday/model/Holiday.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/ShareHolidayUseCase.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/ShareHolidayUseCase.kt index dd5db05e..c007d114 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/ShareHolidayUseCase.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/holiday/usecase/ShareHolidayUseCase.kt @@ -33,7 +33,7 @@ class ShareHolidayUseCase( ) val completedHolidays = holidays.map { - it.share() + it.complete() } commandHolidayPort.saveAll(completedHolidays) diff --git a/simtong-domain/src/main/kotlin/team/comit/simtong/domain/holiday/model/Holiday.kt b/simtong-domain/src/main/kotlin/team/comit/simtong/domain/holiday/model/Holiday.kt index 6fb5c050..5bb185c1 100644 --- a/simtong-domain/src/main/kotlin/team/comit/simtong/domain/holiday/model/Holiday.kt +++ b/simtong-domain/src/main/kotlin/team/comit/simtong/domain/holiday/model/Holiday.kt @@ -66,7 +66,7 @@ data class Holiday( } } - fun share() = this.copy(status = HolidayStatus.COMPLETED) + fun complete() = this.copy(status = HolidayStatus.COMPLETED) fun isSameSpot(spotId: UUID) = this.spotId == spotId