-
Notifications
You must be signed in to change notification settings - Fork 0
[Feat/#199] 마트 공휴일 휴무 지원 및 영업중 여부 판별에 공휴일 반영 #201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
core/src/main/kotlin/kr/dongchimi/core/holiday/HolidayCache.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package kr.dongchimi.core.holiday | ||
|
|
||
| import java.time.LocalDate | ||
|
|
||
| interface HolidayCache { | ||
| /** null이면 미캐싱, 빈 Set이면 "공휴일 없음"으로 캐싱된 상태 */ | ||
| fun get(year: Int): Set<LocalDate>? | ||
|
|
||
| fun put( | ||
| year: Int, | ||
| holidays: Set<LocalDate>, | ||
| ) | ||
|
|
||
| /** API 장애 시 짧은 TTL로 빈 값을 캐싱해 요청마다 외부 API를 재시도하지 않게 한다. */ | ||
| fun putFallback(year: Int) | ||
| } |
8 changes: 8 additions & 0 deletions
8
core/src/main/kotlin/kr/dongchimi/core/holiday/HolidayClient.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package kr.dongchimi.core.holiday | ||
|
|
||
| import java.time.LocalDate | ||
|
|
||
| interface HolidayClient { | ||
| /** 해당 연도의 공휴일 목록을 외부 API에서 조회한다. 실패 시 예외를 던진다. */ | ||
| fun fetchHolidays(year: Int): Set<LocalDate> | ||
| } |
31 changes: 31 additions & 0 deletions
31
core/src/main/kotlin/kr/dongchimi/core/holiday/HolidayReader.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package kr.dongchimi.core.holiday | ||
|
|
||
| import io.github.oshai.kotlinlogging.KotlinLogging | ||
| import org.springframework.stereotype.Component | ||
| import java.time.LocalDate | ||
|
|
||
| private val logger = KotlinLogging.logger {} | ||
|
|
||
| @Component | ||
| class HolidayReader( | ||
| private val holidayCache: HolidayCache, | ||
| private val holidayClient: HolidayClient, | ||
| ) { | ||
| /** 자정 넘김 영업 판별이 전날 공휴일 여부까지 보므로 전날이 걸치는 연도도 함께 조회한다. */ | ||
| fun getHolidays(baseDate: LocalDate): Set<LocalDate> { | ||
| val years = setOf(baseDate.year, baseDate.minusDays(1).year) | ||
| return years.flatMap { holidaysOf(it) }.toSet() | ||
| } | ||
|
|
||
| private fun holidaysOf(year: Int): Set<LocalDate> = holidayCache.get(year) ?: fetchAndCache(year) | ||
|
|
||
| // 캐시·API 모두 실패하면 공휴일 없음으로 간주한다. isOpenNow는 부가 정보라 조회 자체를 깨지 않는다. | ||
| private fun fetchAndCache(year: Int): Set<LocalDate> = | ||
| runCatching { holidayClient.fetchHolidays(year) } | ||
| .onSuccess { holidayCache.put(year, it) } | ||
| .getOrElse { exception -> | ||
| logger.warn(exception) { "공휴일 조회 실패, 공휴일 없음으로 간주: year=$year" } | ||
| holidayCache.putFallback(year) | ||
| emptySet() | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
core/src/main/kotlin/kr/dongchimi/core/holiday/HolidayService.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package kr.dongchimi.core.holiday | ||
|
|
||
| import org.springframework.stereotype.Service | ||
| import java.time.LocalDate | ||
|
|
||
| @Service | ||
| class HolidayService( | ||
| private val holidayReader: HolidayReader, | ||
| ) { | ||
| /** baseDate 기준 영업중 판별에 필요한 공휴일 목록 (전날이 걸치는 연도까지 커버) */ | ||
| fun getHolidays(baseDate: LocalDate): Set<LocalDate> = holidayReader.getHolidays(baseDate) | ||
| } |
18 changes: 15 additions & 3 deletions
18
core/src/main/kotlin/kr/dongchimi/core/market/BusinessHours.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,29 @@ | ||
| package kr.dongchimi.core.market | ||
|
|
||
| import java.time.DayOfWeek | ||
| import java.time.LocalDate | ||
| import java.time.LocalDateTime | ||
|
|
||
| data class BusinessHours( | ||
| val slots: List<BusinessHourSlot>, | ||
| val isHolidayClosed: Boolean = false, | ||
| ) { | ||
| fun isOpenAt(dateTime: LocalDateTime): Boolean { | ||
| fun isOpenAt( | ||
| dateTime: LocalDateTime, | ||
| holidays: Set<LocalDate>, | ||
| ): Boolean { | ||
| val today = dateTime.toLocalDate() | ||
| val time = dateTime.toLocalTime() | ||
|
|
||
| return slotsOf(dateTime.dayOfWeek).any { it.contains(time) } || | ||
| slotsOf(dateTime.dayOfWeek.minus(1)).any { it.containsOvernightTail(time) } | ||
| // 전날이 공휴일 휴무면 자정을 넘긴 꼬리 영업도 휴무 처리한다. | ||
| return (!closedOn(today, holidays) && slotsOf(today.dayOfWeek).any { it.contains(time) }) || | ||
| (!closedOn(today.minusDays(1), holidays) && slotsOf(today.dayOfWeek.minus(1)).any { it.containsOvernightTail(time) }) | ||
| } | ||
|
|
||
| private fun closedOn( | ||
| date: LocalDate, | ||
| holidays: Set<LocalDate>, | ||
| ): Boolean = isHolidayClosed && date in holidays | ||
|
|
||
| private fun slotsOf(dayOfWeek: DayOfWeek): List<BusinessHourSlot> = slots.filter { dayOfWeek in it.days } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.