Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
rudeh2926 committed Nov 5, 2024
2 parents 85f0b8b + ed148b1 commit 653b06f
Showing 1 changed file with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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>): 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>): WeekendMealPeriod? {
return periods.firstOrNull { it.start.isAfter(today) }
?: periods.lastOrNull { it.end.isBefore(today) }
}
}

0 comments on commit 653b06f

Please sign in to comment.