Skip to content

Commit 6531ae9

Browse files
authored
Merge pull request #22 from Nexters/feature/implement-home-api
[FEAT] 홈 비즈니스 로직 구현
2 parents 5e8d638 + 69ac2e4 commit 6531ae9

File tree

26 files changed

+278
-146
lines changed

26 files changed

+278
-146
lines changed
78.3 KB
Loading

data/src/main/java/com/hanbang/data/datasource/UserRemoteDataSource.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ interface UserRemoteDataSource {
4444
suspend fun getDailyFortunes(
4545
userId: String,
4646
fortuneDate: String
47-
): List<DailyFortuneDto>
47+
): DailyFortuneDto
4848

4949
suspend fun getDailyFortuneDetail(
5050
userId: String,

data/src/main/java/com/hanbang/data/model/DailyFortuneDto.kt

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,21 @@ import com.hanbang.domain.model.DailyFortune
88
* @created 2025/08/13
99
*/
1010
data class DailyFortuneDto(
11-
val id: Int,
12-
val userId: String,
13-
val fortuneDate: String,
14-
val fortuneType: String,
15-
val imageUrl: String,
16-
val description: String
17-
)
11+
val title: String,
12+
val content: List<Content>
13+
) {
14+
data class Content(
15+
val id: Int,
16+
val userId: String,
17+
val fortuneDate: String,
18+
val fortuneType: String,
19+
val imageUrl: String,
20+
val description: String
21+
)
22+
}
1823

19-
internal fun DailyFortuneDto.toDomain(): DailyFortune {
20-
return com.hanbang.domain.model.DailyFortune(
24+
internal fun DailyFortuneDto.Content.toDomain(): DailyFortune.Content {
25+
return DailyFortune.Content(
2126
id = id,
2227
userId = userId,
2328
fortuneDate = fortuneDate,
@@ -27,4 +32,9 @@ internal fun DailyFortuneDto.toDomain(): DailyFortune {
2732
)
2833
}
2934

30-
internal fun List<DailyFortuneDto>.toDomain() = map { it.toDomain() }
35+
internal fun List<DailyFortuneDto.Content>.toDomain() = map { it.toDomain() }
36+
37+
internal fun DailyFortuneDto.toDomain() = DailyFortune(
38+
title = title,
39+
content = content.toDomain()
40+
)

data/src/main/java/com/hanbang/data/model/LottoRecommendationDto.kt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,15 @@ import com.hanbang.domain.model.LottoRecommendation
88
* @created 2025/08/13
99
*/
1010
data class LottoRecommendationDto(
11-
val id: Int,
1211
val userId: String,
1312
val round: Int,
14-
val content: LottoRecommendationContentDto,
15-
val createdAt: String,
16-
val updatedAt: String
13+
val content: LottoRecommendationContentDto?,
1714
)
1815

1916
internal fun LottoRecommendationDto.toDomain(): LottoRecommendation {
2017
return LottoRecommendation(
21-
id = id,
2218
userId = userId,
2319
round = round,
24-
content = content.toDomain(),
25-
createdAt = createdAt,
26-
updatedAt = updatedAt
20+
content = content?.toDomain(),
2721
)
2822
}

data/src/main/java/com/hanbang/data/model/PillarDetailDto.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ data class PillarDetailDto(
1313
val branch: String,
1414
val stemTenGod: String,
1515
val branchTenGod: String,
16-
val stemElement: String,
17-
val branchElement: String
1816
)
1917

2018
internal fun PillarDetailDto.toDomain(): PillarDetail {
@@ -23,7 +21,5 @@ internal fun PillarDetailDto.toDomain(): PillarDetail {
2321
branch = PillarElement.parsePillarElementInString(branch),
2422
stemTenGod = stemTenGod,
2523
branchTenGod = branchTenGod,
26-
stemElement = stemElement,
27-
branchElement = branchElement
2824
)
2925
}

data/src/main/java/com/hanbang/data/repository/DefaultSattoRepository.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import com.hanbang.data.datasource.UserRemoteDataSource
66
import com.hanbang.data.model.toDomain
77
import com.hanbang.domain.model.DailyFortuneDetail
88
import com.hanbang.domain.model.FourPillar
9+
import com.hanbang.domain.model.DailyFortune
910
import com.hanbang.domain.model.GenderType
11+
import com.hanbang.domain.model.LottoRecommendation
1012
import com.hanbang.domain.model.User
1113
import com.hanbang.domain.repository.SattoRepository
1214
import kotlinx.coroutines.Dispatchers
@@ -100,6 +102,18 @@ class DefaultSattoRepository @Inject constructor(
100102
emit(dailyFortuneDetailDto.toDomain())
101103
}.flowOn(Dispatchers.IO)
102104

105+
override fun getDailyFortunes(fortuneDate: String): Flow<DailyFortune> = flow {
106+
val userId = userLocalDataSource.getUserId()
107+
val dailyFortunesDto = userRemoteDataSource.getDailyFortunes(userId, fortuneDate)
108+
emit(dailyFortunesDto.toDomain())
109+
}.flowOn(Dispatchers.IO)
110+
111+
override fun getLottoRecommendation(): Flow<LottoRecommendation> = flow {
112+
val userId = userLocalDataSource.getUserId()
113+
val lottoRecommendationDto = userRemoteDataSource.getLottoRecommendation(userId)
114+
emit(lottoRecommendationDto.toDomain())
115+
}.flowOn(Dispatchers.IO)
116+
103117
private fun formatBirthDateTime(year: Int, month: Int, day: Int, hour: Int, minute: Int): String {
104118
val dateTime = LocalDateTime.of(year, month, day, hour, minute)
105119
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")

domain/src/main/java/com/hanbang/domain/model/DailyFortune.kt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@ package com.hanbang.domain.model
66
* @created 2025/08/13
77
*/
88
data class DailyFortune(
9-
val id: Int,
10-
val userId: String,
11-
val fortuneDate: String,
12-
val fortuneType: String,
13-
val imageUrl: String,
14-
val description: String
15-
)
9+
val title: String,
10+
val content: List<Content>
11+
) {
12+
data class Content(
13+
val id: Int,
14+
val userId: String,
15+
val fortuneDate: String,
16+
val fortuneType: String,
17+
val imageUrl: String,
18+
val description: String
19+
)
20+
}

domain/src/main/java/com/hanbang/domain/model/LottoRecommendation.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ package com.hanbang.domain.model
66
* @created 2025/08/13
77
*/
88
data class LottoRecommendation(
9-
val id: Int,
109
val userId: String,
1110
val round: Int,
12-
val content: LottoRecommendationContent,
13-
val createdAt: String,
14-
val updatedAt: String
11+
val content: LottoRecommendationContent?,
1512
)

domain/src/main/java/com/hanbang/domain/model/PillarDetail.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,4 @@ data class PillarDetail(
1010
val branch: PillarElement,
1111
val stemTenGod: String,
1212
val branchTenGod: String,
13-
val stemElement: String,
14-
val branchElement: String
1513
)

domain/src/main/java/com/hanbang/domain/repository/SattoRepository.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package com.hanbang.domain.repository
22

33
import com.hanbang.domain.model.DailyFortuneDetail
44
import com.hanbang.domain.model.FourPillar
5+
import com.hanbang.domain.model.DailyFortune
56
import com.hanbang.domain.model.GenderType
7+
import com.hanbang.domain.model.LottoRecommendation
68
import com.hanbang.domain.model.User
79
import kotlinx.coroutines.flow.Flow
810

@@ -44,4 +46,10 @@ interface SattoRepository {
4446
fun getDailyFortuneDetail(
4547
fortuneDate: String
4648
): Flow<DailyFortuneDetail>
49+
50+
fun getDailyFortunes(
51+
fortuneDate: String
52+
): Flow<DailyFortune>
53+
54+
fun getLottoRecommendation(): Flow<LottoRecommendation>
4755
}

0 commit comments

Comments
 (0)