Skip to content

Commit 653b06f

Browse files
committed
Merge branch 'develop'
2 parents 85f0b8b + ed148b1 commit 653b06f

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/main/kotlin/dsm/pick2024/domain/weekendmeal/service/QueryWeekendMealApplicationService.kt

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package dsm.pick2024.domain.weekendmeal.service
22

3+
import dsm.pick2024.domain.weekendmeal.domain.WeekendMealPeriod
34
import dsm.pick2024.domain.weekendmeal.port.`in`.QueryWeekendMealApplicationUseCase
45
import dsm.pick2024.domain.weekendmeal.port.out.QueryWeekendMealPeriodPort
56
import dsm.pick2024.domain.weekendmeal.presentation.dto.response.QueryWeekendMealStatusResponse
67
import org.springframework.stereotype.Service
78
import org.springframework.transaction.annotation.Transactional
9+
import java.time.LocalDate
810
import java.time.LocalDate.*
911
import java.time.ZoneId
1012

@@ -19,16 +21,27 @@ class QueryWeekendMealApplicationService(
1921

2022
val periods = queryWeekendMealPeriodPort.queryAllWeekendMeal()
2123

22-
val period = periods.find {
23-
(today.isEqual(it.start) || today.isAfter(it.start)) && today.isBefore(it.end.plusDays(1))
24-
}
24+
val currentPeriod = findCurrentPeriod(today, periods)
25+
26+
val nextPeriod = currentPeriod ?: findNextPeriod(today, periods)
2527

26-
val status = period != null
27-
val month = period?.month?.value
28+
val status = currentPeriod != null
29+
val month = nextPeriod?.month?.value
2830

2931
return QueryWeekendMealStatusResponse(
3032
status,
3133
month
3234
)
3335
}
36+
37+
private fun findCurrentPeriod(today: LocalDate, periods: List<WeekendMealPeriod>): WeekendMealPeriod? {
38+
return periods.find {
39+
(today.isEqual(it.start) || today.isAfter(it.start)) && today.isBefore(it.end.plusDays(1))
40+
}
41+
}
42+
43+
private fun findNextPeriod(today: LocalDate, periods: List<WeekendMealPeriod>): WeekendMealPeriod? {
44+
return periods.firstOrNull { it.start.isAfter(today) }
45+
?: periods.lastOrNull { it.end.isBefore(today) }
46+
}
3447
}

0 commit comments

Comments
 (0)