Skip to content

Commit

Permalink
Merge branch 'develop' into feature/MZ-174-add-ledger-ui
Browse files Browse the repository at this point in the history
# Conflicts:
#	core/ui/src/main/res/values/strings.xml
  • Loading branch information
jinukeu committed Jan 12, 2024
2 parents cc3c3b0 + c7eac6f commit 06f79cf
Show file tree
Hide file tree
Showing 27 changed files with 877 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ fun SusuProgressAppBar(
fun SusuProgressAppBarPreview() {
val entireStep = 6
var currentStep by remember { mutableStateOf(1) }

SusuTheme {
Column(
verticalArrangement = Arrangement.spacedBy(20.dp),
Expand Down
7 changes: 7 additions & 0 deletions core/model/src/main/java/com/susu/core/model/Term.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.susu.core.model

data class Term(
val id: Int,
val title: String,
val isEssential: Boolean,
)
8 changes: 8 additions & 0 deletions core/model/src/main/java/com/susu/core/model/TermDetail.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.susu.core.model

data class TermDetail(
val id: Int,
val title: String,
val isEssential: Boolean,
val description: String,
)
1 change: 1 addition & 0 deletions core/model/src/main/java/com/susu/core/model/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ package com.susu.core.model
data class User(
val name: String,
val gender: String,
val termAgreement: List<Int>,
val birth: Int,
)
3 changes: 3 additions & 0 deletions core/ui/src/main/java/com/susu/core/ui/Consts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ val alignList
stringResource(id = R.string.word_align_high_amount),
stringResource(id = R.string.word_align_low_amount),
)

const val USER_NAME_MAX_LENGTH = 10
val nameRegex = Regex("[a-zA-Z가-힣]{0,10}")
5 changes: 5 additions & 0 deletions core/ui/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@
<string name="word_date">날짜</string>
<string name="content_description_add_button">더하기 버튼</string>
<string name="word_input_yourself">직접 입력</string>
<string name="word_male">남성</string>
<string name="word_female">여성</string>
<string name="word_birth">출생년도</string>
<string name="word_next">다음</string>
<string name="word_done">완료</string>
</resources>
7 changes: 7 additions & 0 deletions data/src/main/java/com/susu/data/data/di/RepositoryModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package com.susu.data.data.di
import com.susu.data.data.repository.LedgerRecentSearchRepositoryImpl
import com.susu.data.data.repository.LoginRepositoryImpl
import com.susu.data.data.repository.SignUpRepositoryImpl
import com.susu.data.data.repository.TermRepositoryImpl
import com.susu.data.data.repository.TokenRepositoryImpl
import com.susu.domain.repository.LedgerRecentSearchRepository
import com.susu.domain.repository.LoginRepository
import com.susu.domain.repository.SignUpRepository
import com.susu.domain.repository.TermRepository
import com.susu.domain.repository.TokenRepository
import dagger.Binds
import dagger.Module
Expand Down Expand Up @@ -36,4 +38,9 @@ abstract class RepositoryModule {
abstract fun bindLedgerRecentSearchRepository(
ledgerRecentSearchRepositoryImpl: LedgerRecentSearchRepositoryImpl,
): LedgerRecentSearchRepository

@Binds
abstract fun bindTermRepository(
termRepositoryImpl: TermRepositoryImpl,
): TermRepository
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.susu.data.data.repository

import com.susu.core.model.Term
import com.susu.core.model.TermDetail
import com.susu.data.remote.api.TermService
import com.susu.data.remote.model.response.toModel
import com.susu.domain.repository.TermRepository
import javax.inject.Inject

class TermRepositoryImpl @Inject constructor(
private val termService: TermService,
) : TermRepository {
override suspend fun getTerms(): List<Term> = termService.getTerms().getOrThrow().map { it.toModel() }

override suspend fun getTermDetail(id: Int): TermDetail = termService.getTermDetail(id).getOrThrow().toModel()
}
15 changes: 15 additions & 0 deletions data/src/main/java/com/susu/data/remote/api/TermService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.susu.data.remote.api

import com.susu.data.remote.model.response.TermDetailResponse
import com.susu.data.remote.model.response.TermResponse
import com.susu.data.remote.retrofit.ApiResult
import retrofit2.http.GET
import retrofit2.http.Path

interface TermService {
@GET("terms")
suspend fun getTerms(): ApiResult<List<TermResponse>>

@GET("terms/{id}")
suspend fun getTermDetail(@Path("id") id: Int): ApiResult<TermDetailResponse>
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.susu.data.remote.di

import com.susu.data.remote.api.SignUpService
import com.susu.data.remote.api.TermService
import com.susu.data.remote.api.TokenService
import com.susu.data.remote.api.UserService
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import retrofit2.Retrofit
import retrofit2.create
import javax.inject.Singleton

@Module
Expand All @@ -31,4 +33,10 @@ object ApiServiceModule {
fun provideTokenService(@AuthRetrofit retrofit: Retrofit): TokenService {
return retrofit.create(TokenService::class.java)
}

@Singleton
@Provides
fun providesTermService(retrofit: Retrofit): TermService {
return retrofit.create(TermService::class.java)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import kotlinx.serialization.Serializable
@Serializable
data class UserRequest(
val name: String,
val gender: String,
val birth: Int,
val gender: String?,
val termAgreement: List<Int>,
val birth: Int?,
)

fun User.toData() = UserRequest(
name = name,
gender = gender,
birth = birth,
gender = gender.ifEmpty { null },
birth = if (birth < 0) null else birth,
termAgreement = termAgreement,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.susu.data.remote.model.response

import com.susu.core.model.Term
import com.susu.core.model.TermDetail
import kotlinx.serialization.Serializable

@Serializable
data class TermResponse(
val id: Int,
val title: String,
val isEssential: Boolean,
)

@Serializable
data class TermDetailResponse(
val id: Int,
val title: String,
val description: String,
val isEssential: Boolean,
)

fun TermResponse.toModel(): Term = Term(
id = id,
title = title,
isEssential = isEssential,
)

fun TermDetailResponse.toModel(): TermDetail = TermDetail(
id = id,
title = title,
description = description,
isEssential = isEssential,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.susu.domain.repository

import com.susu.core.model.Term
import com.susu.core.model.TermDetail

interface TermRepository {
suspend fun getTerms(): List<Term>
suspend fun getTermDetail(id: Int): TermDetail
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.susu.domain.usecase.loginsignup

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

class GetTermDetailUseCase @Inject constructor(
private val termRepository: TermRepository,
) {

suspend operator fun invoke(termId: Int) = runCatchingIgnoreCancelled {
termRepository.getTermDetail(termId)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.susu.domain.usecase.loginsignup

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

class GetTermsUseCase @Inject constructor(
private val termRepository: TermRepository,
) {

suspend operator fun invoke() = runCatchingIgnoreCancelled {
termRepository.getTerms()
}
}
Original file line number Diff line number Diff line change
@@ -1,52 +1,44 @@
package com.susu.feature.loginsignup.navigation

import androidx.compose.foundation.layout.PaddingValues
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavOptions
import androidx.navigation.compose.composable
import com.susu.core.ui.SnackbarToken
import com.susu.feature.loginsignup.VoteRoute
import com.susu.feature.loginsignup.login.LoginRoute
import com.susu.feature.loginsignup.signup.SignUpScreen
import com.susu.feature.loginsignup.signup.SignUpRoute

@Suppress("unused")
fun NavController.navigateLoginSignup(navOptions: NavOptions) {
navigate(LoginSignupRoute.Parent.route, navOptions)
}

fun NavGraphBuilder.loginSignupNavGraph(
navController: NavController,
padding: PaddingValues,
navigateToLogin: () -> Unit,
navigateToSignUp: () -> Unit,
navigateToReceived: () -> Unit,
onShowToast: (SnackbarToken) -> Unit,
) {
composable(route = LoginSignupRoute.Parent.Vote.route) {
VoteRoute(
navigateToLogin = {
navController.navigate(LoginSignupRoute.Parent.Login.route) {
popUpTo(
route = LoginSignupRoute.Parent.Vote.route,
) {
inclusive = true
}
}
},
navigateToLogin = navigateToLogin,
)
}
composable(route = LoginSignupRoute.Parent.Login.route) {
LoginRoute(
navigateToReceived = navigateToReceived,
navigateToSignUp = {
navController.navigate(LoginSignupRoute.Parent.SignUp.route) {
popUpTo(
route = LoginSignupRoute.Parent.SignUp.route,
) {
inclusive = true
}
}
},
navigateToSignUp = navigateToSignUp,
)
}
composable(route = LoginSignupRoute.Parent.SignUp.route) {
SignUpScreen(
SignUpRoute(
padding = padding,
navigateToReceived = navigateToReceived,
navigateToLogin = navigateToLogin,
onShowToast = onShowToast,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,53 @@
package com.susu.feature.loginsignup.signup

import androidx.annotation.StringRes
import com.susu.core.ui.base.SideEffect
import com.susu.core.ui.base.UiState
import com.susu.feature.loginsignup.R

sealed interface SignUpContract {
sealed class SignUpEffect : SideEffect {
data object NavigateToReceived : SignUpEffect()
data class ShowToast(val msg: String) : SignUpEffect()
}
sealed interface SignUpEffect : SideEffect {
data object NavigateToLogin : SignUpEffect
data object NavigateToReceived : SignUpEffect
data class ShowToast(val msg: String) : SignUpEffect
}

data class SignUpState(
val isLoading: Boolean = false,
val currentStep: SignUpStep = SignUpStep.TERMS,
val agreedTerms: List<Int> = emptyList(),
val name: String = "",
val isNameValid: Boolean = true,
val gender: Gender = Gender.NONE,
val birth: Int = -1,
) : UiState

enum class SignUpStep(
@StringRes val appBarTitle: Int?,
@StringRes val description: Int?,
@StringRes val bottomButtonText: Int,
) {
TERMS(
appBarTitle = R.string.signup_term_title,
description = R.string.signup_term_description,
bottomButtonText = com.susu.core.ui.R.string.word_next,
),
TERM_DETAIL(
appBarTitle = R.string.signup_term_detail_title,
description = null,
bottomButtonText = R.string.signup_term_agree,
),
NAME(
appBarTitle = null,
description = R.string.signup_name_description,
bottomButtonText = com.susu.core.ui.R.string.word_next,
),
ADDITIONAL(
appBarTitle = null,
description = R.string.signup_additional_description,
bottomButtonText = com.susu.core.ui.R.string.word_done,
),
}

data class SignUpState(
val name: String = "",
val gender: String = "M",
val birth: String = "0",
) : UiState
enum class Gender(val content: String) {
NONE(""), MALE("M"), FEMALE("F")
}
Loading

0 comments on commit 06f79cf

Please sign in to comment.