Skip to content

Commit d89ed4b

Browse files
committed
[BOOK-490] feat: 독서 기록 목록 조회 (V2) DTO 변경사항 반영
대표 감정을 representativeEmotion으로 내려주는 관계로, 네이티브 코드내에서 대표 감정을 선출하는 로직 제거
1 parent f2aa710 commit d89ed4b

9 files changed

Lines changed: 47 additions & 244 deletions

File tree

core/common/src/main/kotlin/com/ninecraft/booket/core/common/utils/EmotionAnalyzer.kt

Lines changed: 0 additions & 34 deletions
This file was deleted.

core/data/api/src/main/kotlin/com/ninecraft/booket/core/data/api/repository/RecordRepository.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ interface RecordRepository {
1818
sort: String,
1919
page: Int,
2020
size: Int,
21-
): Result<ReadingRecordsModel> // TODO: V2로 변경 필요
21+
): Result<ReadingRecordsModel>
2222

2323
suspend fun getRecordDetail(
2424
readingRecordId: String,

core/data/impl/src/main/kotlin/com/ninecraft/booket/core/data/impl/mapper/ResponseToModel.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import com.ninecraft.booket.core.model.BookSearchModel
66
import com.ninecraft.booket.core.model.BookSummaryModel
77
import com.ninecraft.booket.core.model.BookUpsertModel
88
import com.ninecraft.booket.core.model.DetailEmotionModel
9-
import com.ninecraft.booket.core.model.Emotion
109
import com.ninecraft.booket.core.model.EmotionCode
1110
import com.ninecraft.booket.core.model.EmotionGroupModel
1211
import com.ninecraft.booket.core.model.EmotionGroupsModel
@@ -230,6 +229,7 @@ internal fun RecordRegisterResponse.toModel(): RecordRegisterModel {
230229

231230
internal fun ReadingRecordsResponse.toModel(): ReadingRecordsModel {
232231
return ReadingRecordsModel(
232+
representativeEmotion = representativeEmotion.toModel(),
233233
lastPage = lastPage,
234234
totalResults = totalResults,
235235
startIndex = startIndex,
@@ -290,9 +290,8 @@ internal fun SeedResponse.toModel(): SeedModel {
290290
}
291291

292292
internal fun Category.toEmotionModel(): EmotionModel? {
293-
val emotion = Emotion.fromDisplayName(name) ?: return null
294293
return EmotionModel(
295-
name = emotion,
294+
code = EmotionCode.fromDisplayName(name) ?: return null,
296295
count = count,
297296
)
298297
}

core/model/src/main/kotlin/com/ninecraft/booket/core/model/ReadingRecordsModel.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.ninecraft.booket.core.model
33
import androidx.compose.runtime.Stable
44

55
data class ReadingRecordsModel(
6+
val representativeEmotion: PrimaryEmotionModel = PrimaryEmotionModel(),
67
val lastPage: Boolean = true,
78
val totalResults: Int = 0,
89
val startIndex: Int = 0,

core/network/src/main/kotlin/com/ninecraft/booket/core/network/response/ReadingRecordsResponse.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import kotlinx.serialization.Serializable
55

66
@Serializable
77
data class ReadingRecordsResponse(
8+
@SerialName("representativeEmotion")
9+
val representativeEmotion: PrimaryEmotion,
810
@SerialName("lastPage")
911
val lastPage: Boolean,
1012
@SerialName("totalResults")

feature/detail/src/main/kotlin/com/ninecraft/booket/feature/detail/book/BookDetailPresenter.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import com.ninecraft.booket.core.data.api.repository.RecordRepository
1414
import com.ninecraft.booket.core.model.BookDetailModel
1515
import com.ninecraft.booket.core.model.EmotionCode
1616
import com.ninecraft.booket.core.model.EmotionModel
17+
import com.ninecraft.booket.core.model.PrimaryEmotionModel
1718
import com.ninecraft.booket.core.model.ReadingRecordModel
1819
import com.ninecraft.booket.core.ui.component.FooterState
1920
import com.ninecraft.booket.feature.screens.BookDetailScreen
@@ -81,6 +82,7 @@ class BookDetailPresenter(
8182
var uiState by rememberRetained { mutableStateOf<UiState>(UiState.Idle) }
8283
var footerState by rememberRetained { mutableStateOf<FooterState>(FooterState.Idle) }
8384
var bookDetail by rememberRetained { mutableStateOf(BookDetailModel()) }
85+
var representativeEmotion by rememberRetained { mutableStateOf(PrimaryEmotionModel()) }
8486
var seedsStates by rememberRetained { mutableStateOf<ImmutableList<EmotionModel>>(persistentListOf()) }
8587
var isStatsExpanded by rememberRetained { mutableStateOf(false) }
8688
var readingRecords by rememberRetained { mutableStateOf(persistentListOf<ReadingRecordModel>()) }
@@ -122,6 +124,7 @@ class BookDetailPresenter(
122124
bookDetail = detail
123125
currentBookStatus = BookStatus.fromValue(detail.userBookStatus) ?: BookStatus.BEFORE_READING
124126
selectedBookStatus = currentBookStatus
127+
representativeEmotion = records.representativeEmotion
125128
seedsStates = seeds.categories.toImmutableList()
126129
readingRecords = records.readingRecords.toPersistentList()
127130
readingRecordsTotalCount = records.totalResults
@@ -421,6 +424,7 @@ class BookDetailPresenter(
421424
uiState = uiState,
422425
footerState = footerState,
423426
bookDetail = bookDetail,
427+
representativeEmotion = representativeEmotion,
424428
seedsStats = seedsStates,
425429
isStatsExpanded = isStatsExpanded,
426430
readingRecords = readingRecords,

feature/detail/src/main/kotlin/com/ninecraft/booket/feature/detail/book/BookDetailUiState.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.ninecraft.booket.core.common.R
55
import com.ninecraft.booket.core.common.constants.BookStatus
66
import com.ninecraft.booket.core.model.BookDetailModel
77
import com.ninecraft.booket.core.model.EmotionModel
8+
import com.ninecraft.booket.core.model.PrimaryEmotionModel
89
import com.ninecraft.booket.core.model.ReadingRecordModel
910
import com.ninecraft.booket.core.ui.component.FooterState
1011
import com.slack.circuit.runtime.CircuitUiEvent
@@ -26,6 +27,7 @@ data class BookDetailUiState(
2627
val footerState: FooterState = FooterState.Idle,
2728
val isLoading: Boolean = false,
2829
val bookDetail: BookDetailModel = BookDetailModel(),
30+
val representativeEmotion: PrimaryEmotionModel = PrimaryEmotionModel(),
2931
val seedsStats: ImmutableList<EmotionModel> = persistentListOf(),
3032
val isStatsExpanded: Boolean = false,
3133
val readingRecords: ImmutableList<ReadingRecordModel> = persistentListOf(),

feature/detail/src/main/kotlin/com/ninecraft/booket/feature/detail/book/component/CollectedSeeds.kt

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -22,35 +22,33 @@ import androidx.compose.material3.HorizontalDivider
2222
import androidx.compose.material3.Icon
2323
import androidx.compose.material3.Text
2424
import androidx.compose.runtime.Composable
25-
import androidx.compose.runtime.remember
2625
import androidx.compose.ui.Alignment
2726
import androidx.compose.ui.Modifier
2827
import androidx.compose.ui.draw.clip
2928
import androidx.compose.ui.graphics.vector.ImageVector
3029
import androidx.compose.ui.res.painterResource
3130
import androidx.compose.ui.res.vectorResource
3231
import androidx.compose.ui.unit.dp
33-
import com.ninecraft.booket.core.common.utils.analyzeEmotions
3432
import com.ninecraft.booket.core.designsystem.ComponentPreview
33+
import com.ninecraft.booket.core.designsystem.graphicRes
3534
import com.ninecraft.booket.core.designsystem.ratioBarColor
3635
import com.ninecraft.booket.core.designsystem.theme.ReedTheme
3736
import com.ninecraft.booket.core.designsystem.theme.Yellow700
38-
import com.ninecraft.booket.core.model.Emotion
37+
import com.ninecraft.booket.core.model.EmotionCode
3938
import com.ninecraft.booket.core.model.EmotionModel
39+
import com.ninecraft.booket.core.model.PrimaryEmotionModel
4040
import kotlinx.collections.immutable.ImmutableList
4141
import kotlinx.collections.immutable.persistentListOf
4242
import com.ninecraft.booket.core.designsystem.R as designR
4343

4444
@Composable
4545
internal fun CollectedSeeds(
4646
seedsStats: ImmutableList<EmotionModel>,
47+
representativeEmotion: PrimaryEmotionModel,
4748
isStatsExpanded: Boolean,
4849
onToggleClick: () -> Unit,
4950
modifier: Modifier = Modifier,
5051
) {
51-
val analysisResult = remember(seedsStats) { analyzeEmotions(seedsStats) }
52-
val topEmotion = analysisResult.topEmotions.firstOrNull()
53-
5452
Column(
5553
modifier = modifier
5654
.fillMaxWidth()
@@ -65,7 +63,7 @@ internal fun CollectedSeeds(
6563
.padding(ReedTheme.spacing.spacing4),
6664
) {
6765
CollectedSeedsHeader(
68-
topEmotion = topEmotion,
66+
primaryEmotion = representativeEmotion,
6967
isStatsExpanded = isStatsExpanded,
7068
onToggleClick = onToggleClick,
7169
)
@@ -91,9 +89,9 @@ internal fun CollectedSeeds(
9189
modifier = Modifier.fillMaxWidth(),
9290
horizontalArrangement = Arrangement.spacedBy(ReedTheme.spacing.spacing1),
9391
) {
94-
Emotion.entries.forEach { emotion ->
95-
val emotionModel = seedsStats.find { it.name == emotion }
96-
?: EmotionModel(emotion, 0)
92+
EmotionCode.entries.forEach { emotionCode ->
93+
val emotionModel = seedsStats.find { it.code == emotionCode }
94+
?: EmotionModel(emotionCode, 0)
9795
EmotionStatCard(
9896
emotion = emotionModel,
9997
modifier = Modifier.weight(1f),
@@ -107,7 +105,7 @@ internal fun CollectedSeeds(
107105

108106
@Composable
109107
private fun CollectedSeedsHeader(
110-
topEmotion: EmotionModel?,
108+
primaryEmotion: PrimaryEmotionModel,
111109
isStatsExpanded: Boolean,
112110
onToggleClick: () -> Unit,
113111
modifier: Modifier = Modifier,
@@ -122,9 +120,9 @@ private fun CollectedSeedsHeader(
122120
Row(
123121
verticalAlignment = Alignment.CenterVertically,
124122
) {
125-
topEmotion?.let { emotion ->
123+
primaryEmotion?.let { emotion ->
126124
Image(
127-
painter = painterResource(id = getEmotionImageResourceByDisplayName(emotion.name.displayName)),
125+
painter = painterResource(id = emotion.code.graphicRes),
128126
contentDescription = "Seed Image",
129127
modifier = Modifier
130128
.size(36.dp)
@@ -136,7 +134,7 @@ private fun CollectedSeedsHeader(
136134

137135
Row {
138136
Text(
139-
text = "'${topEmotion?.name?.displayName ?: ""}'",
137+
text = "'${primaryEmotion?.code?.displayName ?: ""}'",
140138
color = Yellow700,
141139
style = ReedTheme.typography.label1SemiBold,
142140
)
@@ -173,16 +171,16 @@ private fun EmotionRatioBar(
173171
.height(12.dp)
174172
.clip(RoundedCornerShape(ReedTheme.radius.full)),
175173
) {
176-
Emotion.entries.forEach { emotion ->
177-
val emotionModel = seedsStats.find { it.name == emotion }
174+
EmotionCode.entries.forEach { emotionCode ->
175+
val emotionModel = seedsStats.find { it.code == emotionCode }
178176
val count = emotionModel?.count ?: 0
179177
if (count > 0) {
180178
val weight = count.toFloat() / totalCount
181179
Box(
182180
modifier = Modifier
183181
.weight(weight)
184182
.height(12.dp)
185-
.background(emotion.ratioBarColor),
183+
.background(emotionCode.ratioBarColor),
186184
)
187185
}
188186
}
@@ -208,13 +206,13 @@ private fun EmotionStatCard(
208206
modifier = Modifier
209207
.size(10.dp)
210208
.clip(RoundedCornerShape(ReedTheme.radius.xs))
211-
.background(emotion.name.ratioBarColor),
209+
.background(emotion.code.ratioBarColor),
212210
)
213211

214212
Spacer(modifier = Modifier.height(ReedTheme.spacing.spacing2))
215213

216214
Text(
217-
text = emotion.name.displayName,
215+
text = emotion.code.displayName,
218216
color = ReedTheme.colors.contentSecondary,
219217
style = ReedTheme.typography.label2Regular,
220218
)
@@ -233,12 +231,13 @@ private fun CollectedSeedsCollapsedPreview() {
233231
ReedTheme {
234232
CollectedSeeds(
235233
seedsStats = persistentListOf(
236-
EmotionModel(Emotion.WARM, 4),
237-
EmotionModel(Emotion.JOY, 2),
238-
EmotionModel(Emotion.SAD, 2),
239-
EmotionModel(Emotion.INSIGHT, 2),
240-
EmotionModel(Emotion.ETC, 2),
234+
EmotionModel(EmotionCode.WARMTH, 4),
235+
EmotionModel(EmotionCode.JOY, 2),
236+
EmotionModel(EmotionCode.SADNESS, 2),
237+
EmotionModel(EmotionCode.INSIGHT, 2),
238+
EmotionModel(EmotionCode.OTHER, 2),
241239
),
240+
representativeEmotion = PrimaryEmotionModel(EmotionCode.WARMTH, "기쁨"),
242241
isStatsExpanded = false,
243242
onToggleClick = {},
244243
)
@@ -251,12 +250,13 @@ private fun CollectedSeedsExpandedPreview() {
251250
ReedTheme {
252251
CollectedSeeds(
253252
seedsStats = persistentListOf(
254-
EmotionModel(Emotion.WARM, 4),
255-
EmotionModel(Emotion.JOY, 2),
256-
EmotionModel(Emotion.SAD, 2),
257-
EmotionModel(Emotion.INSIGHT, 2),
258-
EmotionModel(Emotion.ETC, 2),
253+
EmotionModel(EmotionCode.WARMTH, 4),
254+
EmotionModel(EmotionCode.JOY, 2),
255+
EmotionModel(EmotionCode.SADNESS, 2),
256+
EmotionModel(EmotionCode.INSIGHT, 2),
257+
EmotionModel(EmotionCode.OTHER, 2),
259258
),
259+
representativeEmotion = PrimaryEmotionModel(EmotionCode.WARMTH, "기쁨"),
260260
isStatsExpanded = true,
261261
onToggleClick = {},
262262
)
@@ -269,12 +269,13 @@ private fun CollectedSeedsExpandedDuplicatedPreview() {
269269
ReedTheme {
270270
CollectedSeeds(
271271
seedsStats = persistentListOf(
272-
EmotionModel(Emotion.WARM, 4),
273-
EmotionModel(Emotion.JOY, 4),
274-
EmotionModel(Emotion.SAD, 2),
275-
EmotionModel(Emotion.INSIGHT, 2),
276-
EmotionModel(Emotion.ETC, 2),
272+
EmotionModel(EmotionCode.WARMTH, 4),
273+
EmotionModel(EmotionCode.JOY, 4),
274+
EmotionModel(EmotionCode.SADNESS, 2),
275+
EmotionModel(EmotionCode.INSIGHT, 2),
276+
EmotionModel(EmotionCode.OTHER, 2),
277277
),
278+
representativeEmotion = PrimaryEmotionModel(EmotionCode.WARMTH, "기쁨"),
278279
isStatsExpanded = true,
279280
onToggleClick = {},
280281
)

0 commit comments

Comments
 (0)