-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from YAPP-Github/feature/MZ-203-vote-list-api
Feature/mz 203 vote list api
- Loading branch information
Showing
29 changed files
with
547 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,26 @@ | ||
package com.susu.core.model | ||
|
||
import androidx.compose.runtime.Stable | ||
import kotlinx.datetime.LocalDateTime | ||
import kotlinx.datetime.toKotlinLocalDateTime | ||
import kotlinx.serialization.Serializable | ||
|
||
@Stable | ||
@Serializable | ||
data class Vote( | ||
val id: Long = 0, | ||
val uid: Long = 0, | ||
val category: String = "", | ||
val content: String = "", | ||
val count: Int = 0, | ||
val isModified: Boolean = false, | ||
val createdAt: LocalDateTime = java.time.LocalDateTime.now().toKotlinLocalDateTime(), | ||
val optionList: List<VoteOption> = emptyList(), | ||
) | ||
|
||
@Stable | ||
@Serializable | ||
data class VoteOption( | ||
val id: Long, | ||
val category: String, | ||
val content: String, | ||
val isModified: Boolean, | ||
val optionList: List<String>, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,37 @@ | ||
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 | ||
import retrofit2.http.Body | ||
import retrofit2.http.GET | ||
import retrofit2.http.POST | ||
import retrofit2.http.Query | ||
|
||
interface VoteService { | ||
|
||
@POST("/api/v1/votes") | ||
@POST("votes") | ||
suspend fun createVote( | ||
@Body createVoteRequest: CreateVoteRequest, | ||
): ApiResult<VoteResponse> | ||
|
||
@GET("votes") | ||
suspend fun getVoteList( | ||
@Query("content") content: String?, | ||
@Query("mine") mine: Boolean?, | ||
@Query("sortType") sortType: String?, | ||
@Query("categoryId") categoryId: Int?, | ||
@Query("page") page: Int?, | ||
@Query("size") size: Int?, | ||
@Query("sort") sort: String?, | ||
): ApiResult<VoteListResponse> | ||
|
||
@GET("votes/popular") | ||
suspend fun getPopularVoteList(): ApiResult<List<PopularVoteResponse>> | ||
|
||
@GET("posts/configs/create-post") | ||
suspend fun getPostCategoryConfig(): ApiResult<List<PostCategoryConfig>> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
data/src/main/java/com/susu/data/remote/model/response/PopularVoteResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.susu.data.remote.model.response | ||
|
||
import com.susu.core.model.Vote | ||
import kotlinx.datetime.toKotlinLocalDateTime | ||
import kotlinx.serialization.Serializable | ||
import java.time.LocalDateTime | ||
|
||
@Serializable | ||
data class PopularVoteResponse( | ||
val id: Long, | ||
val category: String, | ||
val content: String, | ||
val count: Int, | ||
val isModified: Boolean, | ||
) | ||
|
||
internal fun PopularVoteResponse.toModel() = Vote( | ||
id = id, | ||
uid = 0, | ||
category = category, | ||
content = content, | ||
isModified = isModified, | ||
count = count, | ||
createdAt = LocalDateTime.now().toKotlinLocalDateTime(), | ||
optionList = listOf(), | ||
) |
15 changes: 15 additions & 0 deletions
15
data/src/main/java/com/susu/data/remote/model/response/PostCategoryConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
10 changes: 10 additions & 0 deletions
10
data/src/main/java/com/susu/data/remote/model/response/VoteListResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.susu.data.remote.model.response | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class VoteListResponse( | ||
val data: List<VoteResponse> = emptyList(), | ||
) | ||
|
||
internal fun VoteListResponse.toModel() = data.map { it.toModel() } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
domain/src/main/java/com/susu/domain/usecase/vote/GetPopularVoteListUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 GetPopularVoteListUseCase @Inject constructor( | ||
private val voteRepository: VoteRepository, | ||
) { | ||
suspend operator fun invoke() = runCatchingIgnoreCancelled { | ||
voteRepository.getPopularVoteList() | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
domain/src/main/java/com/susu/domain/usecase/vote/GetPostCategoryConfigUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
domain/src/main/java/com/susu/domain/usecase/vote/GetVoteListUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.susu.domain.usecase.vote | ||
|
||
import com.susu.core.common.runCatchingIgnoreCancelled | ||
import com.susu.domain.repository.VoteRepository | ||
import javax.inject.Inject | ||
|
||
class GetVoteListUseCase @Inject constructor( | ||
private val voteRepository: VoteRepository, | ||
) { | ||
suspend operator fun invoke(param: Param) = runCatchingIgnoreCancelled { | ||
with(param) { | ||
voteRepository.getVoteList( | ||
content = content, | ||
mine = mine, | ||
sortType = sortType, | ||
categoryId = categoryId, | ||
page = page, | ||
size = size, | ||
sort = sort, | ||
) | ||
} | ||
} | ||
|
||
data class Param( | ||
val content: String?, | ||
val mine: Boolean?, | ||
val sortType: String?, | ||
val categoryId: Int?, | ||
val page: Int?, | ||
val size: Int? = null, | ||
val sort: String?, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed | ||
plugins { | ||
alias(libs.plugins.susu.android.feature.compose) | ||
alias(libs.plugins.kotlin.serialization) | ||
} | ||
|
||
android { | ||
namespace = "com.susu.feature.community" | ||
} | ||
|
||
dependencies { | ||
implementation(libs.kotlinx.serialization.json) | ||
} |
22 changes: 22 additions & 0 deletions
22
feature/community/src/main/java/com/susu/feature/community/community/CommunityContract.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.susu.feature.community.community | ||
|
||
import com.susu.core.model.Category | ||
import com.susu.core.model.Vote | ||
import com.susu.core.ui.base.SideEffect | ||
import com.susu.core.ui.base.UiState | ||
import kotlinx.collections.immutable.PersistentList | ||
import kotlinx.collections.immutable.persistentListOf | ||
|
||
data class CommunityState( | ||
val categoryConfigList: PersistentList<Category> = persistentListOf(), | ||
val selectedCategory: Category? = null, | ||
val popularVoteList: PersistentList<Vote> = persistentListOf(), | ||
val voteList: PersistentList<Vote> = persistentListOf(), | ||
val isCheckedVotePopular: Boolean = false, | ||
val isCheckShowMine: Boolean = false, | ||
val isLoading: Boolean = false, | ||
) : UiState | ||
|
||
sealed interface CommunitySideEffect : SideEffect { | ||
data class HandleException(val throwable: Throwable, val retry: () -> Unit) : CommunitySideEffect | ||
} |
Oops, something went wrong.