Skip to content

Commit

Permalink
Merge pull request #52 from YAPP-Github/feature/MZ-111-signup
Browse files Browse the repository at this point in the history
Feature/mz 111 약관 동의, 회원가입 UI
  • Loading branch information
yangsooplus authored Jan 12, 2024
2 parents ee0a912 + 123019f commit c7eac6f
Show file tree
Hide file tree
Showing 27 changed files with 883 additions and 116 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package com.susu.core.designsystem.component.appbar

import android.util.Log
import androidx.annotation.DrawableRes
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Button
import androidx.compose.material3.Icon
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
Expand All @@ -16,41 +12,22 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.susu.core.designsystem.R
import com.susu.core.designsystem.component.appbar.icon.BackIcon
import com.susu.core.designsystem.theme.SusuTheme
import com.susu.core.ui.extension.susuClickable

@Composable
fun SusuProgressAppBar(
modifier: Modifier = Modifier,
@DrawableRes leftIcon: Int? = null,
leftIconContentDescription: String? = null,
leftIconPadding: Dp = SusuTheme.spacing.spacing_xs,
leftIcon: @Composable () -> Unit = {},
currentStep: Int,
entireStep: Int,
progressBar: ProgressBarStyle = ProgressBarStyle.SusuProgressBar,
onClickBackButton: () -> Unit,
) {
BasicAppBar(
modifier = modifier,
leftIcon = {
leftIcon?.let {
Icon(
painter = painterResource(id = leftIcon),
contentDescription = leftIconContentDescription,
modifier = Modifier
.susuClickable(
rippleEnabled = true,
onClick = onClickBackButton,
)
.padding(leftIconPadding),
)
}
},
leftIcon = leftIcon,
title = {
LinearProgressIndicator(
progress = { currentStep / entireStep.toFloat() },
Expand All @@ -72,19 +49,16 @@ fun SusuProgressAppBar(
fun SusuProgressAppBarPreview() {
val entireStep = 6
var currentStep by remember { mutableStateOf(1) }

SusuTheme {
Column(
verticalArrangement = Arrangement.spacedBy(20.dp),
) {
SusuProgressAppBar(
leftIcon = R.drawable.ic_arrow_left,
leftIconContentDescription = "뒤로가기",
leftIcon = {
BackIcon()
},
currentStep = currentStep,
entireStep = entireStep,
onClickBackButton = {
Log.d("확인", "왼쪽 뒤로가기 클릭")
},
)
Button(
onClick = {
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 @@ -18,4 +18,9 @@
<string name="word_category">카테고리</string>
<string name="word_date">날짜</string>
<string name="content_description_add_button">더하기 버튼</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
Loading

0 comments on commit c7eac6f

Please sign in to comment.