Skip to content

Commit

Permalink
feat: 투표 카테고리 조회 -> PostCategoryConfig로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
jinukeu committed Jan 27, 2024
1 parent 32bcd6a commit 73033f0
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.susu.data.data.repository

import com.susu.core.model.Category
import com.susu.core.model.Vote
import com.susu.data.local.model.toModel
import com.susu.data.remote.api.VoteService
Expand Down Expand Up @@ -48,4 +49,6 @@ class VoteRepositoryImpl @Inject constructor(
).getOrThrow().toModel()

override suspend fun getPopularVoteList(): List<Vote> = api.getPopularVoteList().getOrThrow().map { it.toModel() }

override suspend fun getPostCategoryConfig(): List<Category> = api.getPostCategoryConfig().getOrThrow().map { it.toModel() }
}
4 changes: 4 additions & 0 deletions data/src/main/java/com/susu/data/remote/api/VoteService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.susu.data.remote.api

import com.susu.data.remote.model.request.CreateVoteRequest
import com.susu.data.remote.model.response.PopularVoteResponse
import com.susu.data.remote.model.response.PostCategoryConfig
import com.susu.data.remote.model.response.VoteListResponse
import com.susu.data.remote.model.response.VoteResponse
import com.susu.data.remote.retrofit.ApiResult
Expand Down Expand Up @@ -30,4 +31,7 @@ interface VoteService {

@GET("votes/popular")
suspend fun getPopularVoteList(): ApiResult<List<PopularVoteResponse>>

@GET("posts/configs/create-post")
suspend fun getPostCategoryConfig(): ApiResult<List<PostCategoryConfig>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.susu.data.remote.model.response

import com.susu.core.model.Category
import kotlinx.serialization.Serializable

@Serializable
data class PostCategoryConfig(
val id: Int,
val name: String,
)

internal fun PostCategoryConfig.toModel() = Category(
id = id,
name = name,
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.susu.domain.repository

import com.susu.core.model.Category
import com.susu.core.model.Vote

interface VoteRepository {
Expand All @@ -20,4 +21,6 @@ interface VoteRepository {
): List<Vote>

suspend fun getPopularVoteList(): List<Vote>

suspend fun getPostCategoryConfig(): List<Category>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.susu.domain.usecase.vote

import com.susu.core.common.runCatchingIgnoreCancelled
import com.susu.domain.repository.VoteRepository
import javax.inject.Inject

class GetPostCategoryConfigUseCase @Inject constructor(
private val voteRepository: VoteRepository,
) {
suspend operator fun invoke() = runCatchingIgnoreCancelled {
voteRepository.getPostCategoryConfig()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ fun CommunityScreen(
onClick = { onClickCategory(null) },
)

uiState.categoryConfigList.dropLast(1).forEach { category ->
uiState.categoryConfigList.forEach { category ->
SusuFilledButton(
color = FilledButtonColor.Black,
style = XSmallButtonStyle.height28,
Expand All @@ -198,16 +198,6 @@ fun CommunityScreen(
onClick = { onClickCategory(category) },
)
}

uiState.categoryConfigList.lastOrNull()?.let {
SusuFilledButton(
color = FilledButtonColor.Black,
style = XSmallButtonStyle.height28,
text = stringResource(id = com.susu.core.ui.R.string.word_free),
isActive = uiState.selectedCategory == it,
onClick = { onClickCategory(it) },
)
}
}

Row(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.susu.core.ui.base.BaseViewModel
import com.susu.core.ui.extension.decodeFromUri
import com.susu.domain.usecase.categoryconfig.GetCategoryConfigUseCase
import com.susu.domain.usecase.vote.GetPopularVoteListUseCase
import com.susu.domain.usecase.vote.GetPostCategoryConfigUseCase
import com.susu.domain.usecase.vote.GetVoteListUseCase
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.collections.immutable.toPersistentList
Expand All @@ -19,7 +20,7 @@ import javax.inject.Inject
@HiltViewModel
class CommunityViewModel @Inject constructor(
private val getVoteListUseCase: GetVoteListUseCase,
private val getCategoryConfigUseCase: GetCategoryConfigUseCase,
private val getPostCategoryConfigUseCase: GetPostCategoryConfigUseCase,
private val getPopularVoteListUseCase: GetPopularVoteListUseCase,
) : BaseViewModel<CommunityState, CommunitySideEffect>(
CommunityState(),
Expand Down Expand Up @@ -63,7 +64,7 @@ class CommunityViewModel @Inject constructor(
fun getCategoryConfig() = viewModelScope.launch {
if (currentState.categoryConfigList.isNotEmpty()) return@launch

getCategoryConfigUseCase()
getPostCategoryConfigUseCase()
.onSuccess { categoryConfig ->
intent {
copy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ fun VoteAddScreen(
Row(
horizontalArrangement = Arrangement.spacedBy(SusuTheme.spacing.spacing_xxxxs),
) {
uiState.categoryConfigList.dropLast(1).forEach {
uiState.categoryConfigList.forEach {
SusuFilledButton(
color = FilledButtonColor.Black,
style = XSmallButtonStyle.height28,
Expand All @@ -136,16 +136,6 @@ fun VoteAddScreen(
onClick = { onClickCategoryButton(it) },
)
}

uiState.categoryConfigList.lastOrNull()?.let {
SusuFilledButton(
color = FilledButtonColor.Black,
style = XSmallButtonStyle.height28,
text = stringResource(com.susu.core.ui.R.string.word_free),
isActive = it == uiState.selectedCategory,
onClick = { onClickCategoryButton(it) },
)
}
}

Spacer(modifier = Modifier.size(SusuTheme.spacing.spacing_m))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.susu.core.ui.base.BaseViewModel
import com.susu.core.ui.extension.encodeToUri
import com.susu.domain.usecase.categoryconfig.GetCategoryConfigUseCase
import com.susu.domain.usecase.vote.CreateVoteUseCase
import com.susu.domain.usecase.vote.GetPostCategoryConfigUseCase
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.collections.immutable.toPersistentList
import kotlinx.coroutines.launch
Expand All @@ -14,7 +15,7 @@ import javax.inject.Inject

@HiltViewModel
class VoteAddViewModel @Inject constructor(
private val getCategoryConfigUseCase: GetCategoryConfigUseCase,
private val getPostCategoryConfigUseCase: GetPostCategoryConfigUseCase,
private val createVoteUseCase: CreateVoteUseCase,
) : BaseViewModel<VoteAddState, VoteAddSideEffect>(
VoteAddState(),
Expand All @@ -39,7 +40,7 @@ class VoteAddViewModel @Inject constructor(
fun getCategoryConfig() = viewModelScope.launch {
if (currentState.categoryConfigList.isNotEmpty()) return@launch

getCategoryConfigUseCase()
getPostCategoryConfigUseCase()
.onSuccess { categoryConfig ->
intent {
copy(
Expand Down

0 comments on commit 73033f0

Please sign in to comment.