From ed148b13ceadb1c75e1c2e98ae3d45253b45d118 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=8F=84=EA=B2=BD?= Date: Tue, 5 Nov 2024 19:48:34 +0900 Subject: [PATCH] . --- .../QueryWeekendMealApplicationService.kt | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/dsm/pick2024/domain/weekendmeal/service/QueryWeekendMealApplicationService.kt b/src/main/kotlin/dsm/pick2024/domain/weekendmeal/service/QueryWeekendMealApplicationService.kt index f23c621d..cf07dacc 100644 --- a/src/main/kotlin/dsm/pick2024/domain/weekendmeal/service/QueryWeekendMealApplicationService.kt +++ b/src/main/kotlin/dsm/pick2024/domain/weekendmeal/service/QueryWeekendMealApplicationService.kt @@ -1,10 +1,12 @@ package dsm.pick2024.domain.weekendmeal.service +import dsm.pick2024.domain.weekendmeal.domain.WeekendMealPeriod import dsm.pick2024.domain.weekendmeal.port.`in`.QueryWeekendMealApplicationUseCase import dsm.pick2024.domain.weekendmeal.port.out.QueryWeekendMealPeriodPort import dsm.pick2024.domain.weekendmeal.presentation.dto.response.QueryWeekendMealStatusResponse import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional +import java.time.LocalDate import java.time.LocalDate.* import java.time.ZoneId @@ -19,16 +21,27 @@ class QueryWeekendMealApplicationService( val periods = queryWeekendMealPeriodPort.queryAllWeekendMeal() - val period = periods.find { - (today.isEqual(it.start) || today.isAfter(it.start)) && today.isBefore(it.end.plusDays(1)) - } + val currentPeriod = findCurrentPeriod(today, periods) + + val nextPeriod = currentPeriod ?: findNextPeriod(today, periods) - val status = period != null - val month = period?.month?.value + val status = currentPeriod != null + val month = nextPeriod?.month?.value return QueryWeekendMealStatusResponse( status, month ) } + + private fun findCurrentPeriod(today: LocalDate, periods: List): WeekendMealPeriod? { + return periods.find { + (today.isEqual(it.start) || today.isAfter(it.start)) && today.isBefore(it.end.plusDays(1)) + } + } + + private fun findNextPeriod(today: LocalDate, periods: List): WeekendMealPeriod? { + return periods.firstOrNull { it.start.isAfter(today) } + ?: periods.lastOrNull { it.end.isBefore(today) } + } }