File tree Expand file tree Collapse file tree
data/src/main/java/com/threegap/bitnagil/data/emotion
domain/src/main/java/com/threegap/bitnagil/domain/emotion/model Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -18,11 +18,11 @@ data class DailyEmotionResponse(
1818 val emotionMarbleHomeMessage : String? ,
1919)
2020
21- fun DailyEmotionResponse.toDomain (): DailyEmotion =
21+ fun DailyEmotionResponse.toDomain (fetchedDate : LocalDate ): DailyEmotion =
2222 DailyEmotion (
2323 type = emotionMarbleType,
2424 name = emotionMarbleName,
2525 imageUrl = imageUrl,
2626 homeMessage = emotionMarbleHomeMessage,
27- fetchedDate = LocalDate .now() ,
27+ fetchedDate = fetchedDate ,
2828 )
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ class EmotionRepositoryImpl @Inject constructor(
2121 private val _dailyEmotionFlow = MutableStateFlow (DailyEmotion .INIT )
2222 override val dailyEmotionFlow: Flow <DailyEmotion > = _dailyEmotionFlow
2323 .onSubscription {
24- if (_dailyEmotionFlow .value.isStale) fetchDailyEmotion()
24+ if (_dailyEmotionFlow .value.isStale( LocalDate .now()) ) fetchDailyEmotion()
2525 }
2626
2727 override suspend fun getEmotions (): Result <List <Emotion >> {
@@ -43,9 +43,9 @@ class EmotionRepositoryImpl @Inject constructor(
4343 override suspend fun fetchDailyEmotion (): Result <Unit > {
4444 if (! isFetching.compareAndSet(false , true )) return Result .success(Unit )
4545 return try {
46- val currentDate = LocalDate .now().toString ()
47- emotionDataSource.fetchDailyEmotion(currentDate ).map {
48- _dailyEmotionFlow .value = it.toDomain()
46+ val today = LocalDate .now()
47+ emotionDataSource.fetchDailyEmotion(today.toString() ).map {
48+ _dailyEmotionFlow .value = it.toDomain(today )
4949 }
5050 } finally {
5151 isFetching.set(false )
Original file line number Diff line number Diff line change @@ -9,8 +9,7 @@ data class DailyEmotion(
99 val homeMessage : String? ,
1010 val fetchedDate : LocalDate = LocalDate .MIN ,
1111) {
12- val isStale: Boolean
13- get() = fetchedDate != LocalDate .now()
12+ fun isStale (today : LocalDate ): Boolean = fetchedDate != today
1413
1514 companion object {
1615 val INIT = DailyEmotion (
You can’t perform that action at this time.
0 commit comments