Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ fun PostDetailResponse.toDomain(): PostDetail =
isHost = this.isHost,
isScrapped = this.isScrapped,
content = this.content,
date = this.displayDate,
track = this.track.toDomain(),
writer = this.user.toDomain(),
like = this.like.toDomain(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.example.data.mapper.todomain

import com.example.data.model.response.BadgesResponse
import com.example.data.model.response.TodayPostItemResponse
import com.example.data.model.response.TodayPostTrackResponse
import com.example.data.model.response.TodayPostsResponse
import com.example.domain.model.Badges
import com.example.domain.model.BADGE
import com.example.domain.model.DailyQuestion
import com.example.domain.model.FeedItem
import com.example.domain.model.HomeScreenData
Expand All @@ -29,19 +28,12 @@ fun TodayPostItemResponse.toDomain(): FeedItem =
postId = postId,
isScrapped = isScrapped,
content = content,
badges = badges.toDomain(),
badge = badge?.let { BADGE.valueOf(it) },
track = track.toDomain(),
writer = user.toDomain(),
like = like.toDomain(),
)

private fun BadgesResponse.toDomain(): Badges =
Badges(
isEditorPick = isEditorPick,
isPopular = isPopular,
isNew = isNew,
)

private fun TodayPostTrackResponse.toDomain(): Track =
Track(
trackId = trackId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ data class PostDetailResponse(
val isScrapped: Boolean,
@SerialName("content")
val content: String,
@SerialName("displayDate")
val displayDate: String,
@SerialName("track")
val track: TrackResponse,
@SerialName("user")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.data.model.response

import com.example.domain.model.Badges
import com.example.domain.model.BADGE
import com.example.domain.model.FeedItem
import com.example.domain.model.Like
import com.example.domain.model.Track
Expand Down Expand Up @@ -52,12 +52,7 @@ data class QuestionPostItemResponse(
postId = postId,
isScrapped = isScrapped,
content = content,
badges =
Badges(
isEditorPick = isEditorPick,
isPopular = false,
isNew = false,
),
badge = if (isEditorPick) BADGE.EDITOR else null,
track =
Track(
trackId = track.trackId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,12 @@ data class TodayPostItemResponse(
@SerialName("postId") val postId: Long,
@SerialName("isScrapped") val isScrapped: Boolean,
@SerialName("content") val content: String,
@SerialName("badges") val badges: BadgesResponse,
@SerialName("badge") val badge: String?,
@SerialName("track") val track: TodayPostTrackResponse,
@SerialName("user") val user: UserResponse,
@SerialName("like") val like: LikeResponse,
)

@Serializable
data class BadgesResponse(
@SerialName("isEditorPick") val isEditorPick: Boolean,
@SerialName("isPopular") val isPopular: Boolean,
@SerialName("isNew") val isNew: Boolean,
)

@Serializable
data class TodayPostTrackResponse(
@SerialName("trackId") val trackId: String,
Expand Down
13 changes: 7 additions & 6 deletions core/domain/src/main/java/com/example/domain/model/FeedItem.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package com.example.domain.model


data class FeedItem(
val postId: Long,
val isScrapped: Boolean,
val content: String,
val badges: Badges,
val badge: BADGE?,
val track: Track,
val writer: Writer,
val like: Like,
)

data class Badges(
val isEditorPick: Boolean,
val isPopular: Boolean,
val isNew: Boolean,
)
enum class BADGE {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kotlin 에서 enum class의 네이밍 컨벤션은 파스칼 케이스로 알고 있습니다

EDITOR,
BEST,
NEW,
}
12 changes: 11 additions & 1 deletion core/domain/src/main/java/com/example/domain/model/PostDetail.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
package com.example.domain.model

import java.time.LocalDate
import java.time.format.DateTimeFormatter

data class PostDetail(
val postId: Long,
val isHost: Boolean,
val isScrapped: Boolean,
val content: String,
private val date: String,
val track: Track,
val writer: Writer,
val like: Like,
)
) {
val displayDate: String
get() = runCatching {
val parsedDate = LocalDate.parse(date, DateTimeFormatter.ISO_DATE)
"${parsedDate.monthValue}월 ${parsedDate.dayOfMonth}일"
}.getOrElse { "알 수 없는 날짜" }
}
1 change: 1 addition & 0 deletions core/navigation/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ dependencies {
implementation(libs.kotlinx.serialization.json)
implementation(projects.core.designsystem)
implementation(projects.core.common)
implementation(projects.core.domain)
implementation(projects.core.ui)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.example.navigation
import androidx.annotation.DrawableRes
import androidx.navigation3.runtime.NavKey
import com.dplay.designsystem.R
import com.example.domain.model.BADGE
import com.example.ui.model.TrackState
import kotlinx.serialization.Serializable

Expand Down Expand Up @@ -62,5 +63,5 @@ data object Record : NavKey
@Serializable
data class Detail(
val postId: Long,
val date: String = "",
val badge: BADGE? = null,
) : NavKey
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.detail

import com.example.designsystem.component.snackbar.type.SnackBarType
import com.example.domain.model.BADGE
import com.example.domain.model.Like
import com.example.domain.model.Track
import com.example.domain.model.Writer
Expand All @@ -12,6 +13,7 @@ class DetailContract {
val isScrapped: Boolean = false,
val content: String = "",
val isHost: Boolean = false,
val date: String = "",
val track: Track =
Track(
trackId = "",
Expand All @@ -31,18 +33,15 @@ class DetailContract {
isLiked = false,
count = 0,
),
val date: String = "2025-10-19",
val badge: BADGE? = null,
val bottomSheetVisible: Boolean = false,
val streamingTrackId: String? = null,
val currentUserId: Long = 0L,
) : BaseContract.State {
val isMyPost: Boolean get() = currentUserId != 0L && currentUserId == writer.userId
}
) : BaseContract.State

sealed interface DetailIntent : BaseContract.Intent {
data class LoadData(
val postId: Long,
val date: String = "",
val badge: BADGE? = null,
) : DetailIntent

data object OnBookmarkClick : DetailIntent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ object DetailNavigationModule {
): EntryProviderScope<NavKey>.() -> Unit =
{
entry<Detail> { args ->
DetailRoute(postId = args.postId, navigator = navigator, date = args.date)
DetailRoute(postId = args.postId, navigator = navigator, badge = args.badge)
}
}
}
16 changes: 11 additions & 5 deletions feature/detail/src/main/java/com/example/detail/DetailScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import com.example.designsystem.component.snackbar.LocalShowSnackBar
import com.example.designsystem.theme.DPlayTheme
import com.example.designsystem.util.noRippleClickable
import com.example.designsystem.util.roundedBackgroundWithPadding
import com.example.domain.model.BADGE
import com.example.navigation.Navigator
import kotlinx.coroutines.flow.collectLatest

Expand All @@ -53,13 +54,13 @@ fun DetailRoute(
postId: Long,
navigator: Navigator,
viewModel: DetailViewModel = hiltViewModel(),
date: String = "",
badge: BADGE? = null,
) {
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
val showSnackBar = LocalShowSnackBar.current

LaunchedEffect(Unit) {
viewModel.handleIntent(DetailContract.DetailIntent.LoadData(postId = postId, date = date))
viewModel.handleIntent(DetailContract.DetailIntent.LoadData(postId = postId, badge = badge))
}

LaunchedEffect(viewModel.sideEffect) {
Expand Down Expand Up @@ -172,9 +173,14 @@ private fun DetailScreen(
onClick = onBookmarkClick,
modifier = Modifier.align(Alignment.TopEnd),
)
if (state.isHost) {
state.badge?.let { badge ->
val chipType = when (badge) {
BADGE.BEST -> DPlayChipType.BEST
BADGE.EDITOR -> DPlayChipType.EDITOR
BADGE.NEW -> DPlayChipType.NEW
}
DPlayChip(
type = DPlayChipType.EDITOR,
type = chipType,
modifier = Modifier.align(Alignment.BottomCenter),
)
}
Expand Down Expand Up @@ -272,7 +278,7 @@ private fun DetailScreen(
.noRippleClickable { changeBottomSheetVisible(false) },
)

if (state.isMyPost) {
if (state.isHost) {
DPlayButtonBottomSheet(
mainText = "삭제하기",
subText = "취소하기",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import com.example.common.audio.AudioPlayer
import com.example.designsystem.component.snackbar.type.SnackBarType
import com.example.detail.DetailContract.DetailSideEffect.NavigateToMyPage
import com.example.detail.DetailContract.DetailSideEffect.ShowSnackBar
import com.example.domain.model.BADGE
import com.example.domain.model.Like
import com.example.domain.repository.PostRepository
import com.example.domain.repository.TrackRepository
import com.example.domain.repository.UserRepository
import com.example.ui.base.BaseViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
Expand All @@ -25,7 +24,6 @@ class DetailViewModel
private val postRepository: PostRepository,
private val trackRepository: TrackRepository,
private val audioPlayer: AudioPlayer,
private val userRepository: UserRepository,
) : BaseViewModel<DetailContract.DetailState, DetailContract.DetailIntent, DetailContract.DetailSideEffect>(
DetailContract.DetailState(),
) {
Expand All @@ -51,7 +49,7 @@ class DetailViewModel

override fun handleIntent(intent: DetailContract.DetailIntent) {
when (intent) {
is DetailContract.DetailIntent.LoadData -> loadData(intent.postId, intent.date)
is DetailContract.DetailIntent.LoadData -> loadData(intent.postId, intent.badge)
is DetailContract.DetailIntent.OnBackButtonClick -> {
setSideEffect(DetailContract.DetailSideEffect.NavigateBackStack)
}
Expand All @@ -77,11 +75,9 @@ class DetailViewModel

private fun loadData(
postId: Long,
date: String,
badge: BADGE?,
) {
viewModelScope.launch {
val currentUserId = userRepository.getUser().first()?.id ?: 0L

postRepository
.getPostDetail(postId = postId)
.onSuccess { postDetail ->
Expand All @@ -91,11 +87,11 @@ class DetailViewModel
isScrapped = postDetail.isScrapped,
content = postDetail.content,
isHost = postDetail.isHost,
date = postDetail.displayDate,
track = postDetail.track,
writer = postDetail.writer,
like = postDetail.like,
date = date,
currentUserId = currentUserId,
badge = badge,
)
}
}.onFailure { e ->
Expand Down
2 changes: 2 additions & 0 deletions feature/home/src/main/java/com/example/home/HomeContract.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.home

import com.example.designsystem.component.snackbar.type.SnackBarType
import com.example.domain.model.BADGE
import com.example.domain.model.DailyQuestion
import com.example.domain.model.FeedItem
import com.example.ui.base.BaseContract
Expand Down Expand Up @@ -58,6 +59,7 @@ class HomeContract {

data class NavigateToPostDetail(
val postId: Long,
val badge: BADGE?,
) : HomeSideEffect

data object NavigateToRecord : HomeSideEffect
Expand Down
12 changes: 6 additions & 6 deletions feature/home/src/main/java/com/example/home/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import com.example.designsystem.component.chip.DPlayChip
import com.example.designsystem.component.chip.type.DPlayChipType
import com.example.designsystem.component.snackbar.LocalShowSnackBar
import com.example.designsystem.theme.DPlayTheme
import com.example.domain.model.Badge
import com.example.domain.model.FeedItem
import com.example.navigation.Detail
import com.example.navigation.Navigator
Expand Down Expand Up @@ -171,12 +172,11 @@ private fun HomePager(
val currentItem = feedItems.getOrNull(pagerState.currentPage)
val isCurrentPageLocked = uiState.locked && pagerState.currentPage >= 3
val currentChipType: DPlayChipType? =
currentItem?.let {
when {
it.badges.isPopular -> DPlayChipType.BEST
it.badges.isEditorPick -> DPlayChipType.EDITOR
it.badges.isNew -> DPlayChipType.NEW
else -> null
currentItem?.badge?.let {
when (it) {
Badge.BEST -> DPlayChipType.BEST
Badge.EDITOR -> DPlayChipType.EDITOR
Badge.NEW -> DPlayChipType.NEW
}
}

Expand Down
Loading