Skip to content

Commit

Permalink
[MERGE] #88 -> develop
Browse files Browse the repository at this point in the history
[FEAT/#88] ํšŒ์›๊ฐ€์ž… ๋ทฐ / ์„œ๋ฒ„ํ†ต์‹  ๊ตฌํ˜„
  • Loading branch information
leeeyubin authored Jul 17, 2024
2 parents 824946a + 3d70026 commit 3c0a58c
Show file tree
Hide file tree
Showing 23 changed files with 246 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.foundation.lazy.grid.itemsIndexed
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Text
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
Expand All @@ -33,11 +34,13 @@ import kotlinx.coroutines.launch
fun SignUpBottomSheet(
modifier: Modifier = Modifier,
onDismiss: () -> Unit,
onSaveClick: () -> Unit
onSaveClick: (Int) -> Unit
) {
val scope = rememberCoroutineScope()
val sheetState = rememberModalBottomSheetState()

var selectedImageIndex by remember { mutableIntStateOf(-1) }

TerningBasicBottomSheet(
content = {
Column {
Expand All @@ -50,7 +53,11 @@ fun SignUpBottomSheet(
bottom = 25.dp
),
)
RadioButtonGroup()
RadioButtonGroup(
onOptionSelected = { index ->
selectedImageIndex = index
}
)
Spacer(modifier = modifier.padding(bottom = 24.dp))
RoundButton(
style = TerningTheme.typography.button0,
Expand All @@ -61,7 +68,7 @@ fun SignUpBottomSheet(
scope.launch { sheetState.hide() }
.invokeOnCompletion {
if (!sheetState.isVisible) {
onSaveClick()
onSaveClick(selectedImageIndex)
}
}
},
Expand All @@ -77,7 +84,8 @@ fun SignUpBottomSheet(

@Composable
fun RadioButtonGroup(
modifier: Modifier = Modifier
modifier: Modifier = Modifier,
onOptionSelected: (Int) -> Unit
) {
val options = listOf(
R.drawable.ic_character1,
Expand All @@ -97,7 +105,7 @@ fun RadioButtonGroup(
modifier = modifier
.padding(horizontal = 42.dp)
) {
items(options) { option ->
itemsIndexed(options) { index, option ->
Image(
painter = painterResource(
id = if (option == selectedOption) R.drawable.ic_selected_character
Expand All @@ -107,6 +115,7 @@ fun RadioButtonGroup(
modifier = modifier
.aspectRatio(1f)
.noRippleClickable {
onOptionSelected(index)
selectedOption = option
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ fun NameTextField(
onValueChange: (String) -> Unit,
hint: String,
drawLineColor: Color,
@StringRes
helperMessage: Int,
@StringRes helperMessage: Int,
helperColor: Color,
helperIcon: Int? = null,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ fun TerningBasicTextField(
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(4.dp),
modifier = modifier.padding(top = 5.dp)
) {
helperIcon?.let {
Icon(
Expand Down
11 changes: 10 additions & 1 deletion data/src/main/java/com/terning/data/datasource/AuthDataSource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@ package com.terning.data.datasource

import com.terning.data.dto.BaseResponse
import com.terning.data.dto.request.SignInRequestDto
import com.terning.data.dto.request.SignUpRequestDto
import com.terning.data.dto.response.SignInResponseDto
import com.terning.data.dto.response.SignUpResponseDto

interface AuthDataSource {

suspend fun postSignIn(
authorization: String,
platform: SignInRequestDto
request: SignInRequestDto
): BaseResponse<SignInResponseDto>

suspend fun postSignUp(
authId: String,
request: SignUpRequestDto
): BaseResponse<SignUpResponseDto>

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,23 @@ package com.terning.data.datasourceimpl
import com.terning.data.datasource.AuthDataSource
import com.terning.data.dto.BaseResponse
import com.terning.data.dto.request.SignInRequestDto
import com.terning.data.dto.request.SignUpRequestDto
import com.terning.data.dto.response.SignInResponseDto
import com.terning.data.dto.response.SignUpResponseDto
import com.terning.data.service.AuthService
import javax.inject.Inject

class AuthDataSourceImpl @Inject constructor(
private val authService: AuthService
) : AuthDataSource {

override suspend fun postSignIn(
authorization: String,
platform: SignInRequestDto
): BaseResponse<SignInResponseDto> = authService.postSignIn(authorization, platform)
request: SignInRequestDto
): BaseResponse<SignInResponseDto> = authService.postSignIn(authorization, request)

override suspend fun postSignUp(
authId: String,
request: SignUpRequestDto
): BaseResponse<SignUpResponseDto> = authService.postSignUp(authId, request)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.terning.data.dto.request

import com.terning.domain.entity.request.SignUpRequestModel
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class SignUpRequestDto(
@SerialName("name")
val name: String,
@SerialName("profileImage")
val profileImage: Int,
@SerialName("authType")
val authType: String
)

fun SignUpRequestModel.toSignUpRequestDto(): SignUpRequestDto =
SignUpRequestDto(
name = name,
profileImage = profileImage,
authType = authType
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@ import kotlinx.serialization.Serializable
@Serializable
data class SignInResponseDto(
@SerialName("accessToken")
val accessToken: String,
val accessToken: String?,
@SerialName("refreshToken")
val refreshToken: String,
val refreshToken: String?,
@SerialName("userId")
val userId: Long,
val userId: Long?,
@SerialName("authId")
val authId: String,
@SerialName("authType")
val authType: String,
) {
fun toSignInModel() = SignInResponseModel(
accessToken = accessToken,
refreshToken = refreshToken,
userId = userId,
authId = authId,
authType = authType
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.terning.data.dto.response

import com.terning.domain.entity.response.SignUpResponseModel
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class SignUpResponseDto(
@SerialName("accessToken")
val accessToken: String,
@SerialName("refreshToken")
val refreshToken: String,
@SerialName("userId")
val userId: Long,
@SerialName("authType")
val authType: String,
) {
fun toSignUpModel() = SignUpResponseModel(
accessToken = accessToken,
refreshToken = refreshToken,
userId = userId,
authType = authType
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,35 @@ package com.terning.data.repositoryimpl

import com.terning.data.datasource.AuthDataSource
import com.terning.data.dto.request.toSignInRequestDto
import com.terning.data.dto.request.toSignUpRequestDto
import com.terning.domain.entity.request.SignInRequestModel
import com.terning.domain.entity.request.SignUpRequestModel
import com.terning.domain.entity.response.SignInResponseModel
import com.terning.domain.entity.response.SignUpResponseModel
import com.terning.domain.repository.AuthRepository
import javax.inject.Inject

class AuthRepositoryImpl @Inject constructor(
private val authDataSource: AuthDataSource
) : AuthRepository {

override suspend fun postSignIn(
authorization: String,
request: SignInRequestModel
): Result<SignInResponseModel> = kotlin.runCatching {
): Result<SignInResponseModel> = runCatching {
authDataSource.postSignIn(
authorization,
request.toSignInRequestDto()
).result.toSignInModel()
}

override suspend fun postSignUp(
authId: String,
request: SignUpRequestModel
): Result<SignUpResponseModel> = runCatching {
authDataSource.postSignUp(
authId,
request.toSignUpRequestDto()
).result.toSignUpModel()
}
}
9 changes: 9 additions & 0 deletions data/src/main/java/com/terning/data/service/AuthService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@ package com.terning.data.service

import com.terning.data.dto.BaseResponse
import com.terning.data.dto.request.SignInRequestDto
import com.terning.data.dto.request.SignUpRequestDto
import com.terning.data.dto.response.SignInResponseDto
import com.terning.data.dto.response.SignUpResponseDto
import retrofit2.http.Body
import retrofit2.http.Header
import retrofit2.http.POST

interface AuthService {

@POST("api/v1/auth/sign-in")
suspend fun postSignIn(
@Header("Authorization") authorization: String,
@Body body: SignInRequestDto,
): BaseResponse<SignInResponseDto>

@POST("api/v1/auth/sign-up")
suspend fun postSignUp(
@Header("authId") authId: String,
@Body body: SignUpRequestDto,
): BaseResponse<SignUpResponseDto>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.terning.domain.entity.request

data class SignUpRequestModel (
val name : String,
val profileImage : Int,
val authType : String
)
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.terning.domain.entity.response

data class SignInResponseModel(
val accessToken : String? ,
val refreshToken : String?,
val userId : Long,
val accessToken: String?,
val refreshToken: String?,
val userId: Long?,
val authId: String,
val authType: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.terning.domain.entity.response

data class SignUpResponseModel(
val accessToken: String,
val refreshToken: String,
val userId: Long,
val authType: String
)
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
package com.terning.domain.repository

import com.terning.domain.entity.request.SignInRequestModel
import com.terning.domain.entity.request.SignUpRequestModel
import com.terning.domain.entity.response.SignInResponseModel
import com.terning.domain.entity.response.SignUpResponseModel

interface AuthRepository {

suspend fun postSignIn(
authorization: String,
request: SignInRequestModel
): Result<SignInResponseModel>

suspend fun postSignUp(
authId: String,
request: SignUpRequestModel
): Result<SignUpResponseModel>

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
Expand All @@ -18,12 +17,12 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.LocalLifecycleOwner
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.flowWithLifecycle
import androidx.navigation.NavHostController
import com.terning.core.designsystem.theme.TerningPointTheme
import com.terning.core.extension.toast
import com.terning.feature.R
import com.terning.feature.home.home.navigation.navigateHome
import com.terning.feature.onboarding.signin.component.KakaoButton
import com.terning.feature.onboarding.signup.navigation.navigateSignUp

Expand All @@ -34,14 +33,13 @@ fun SignInRoute(
) {
val context = LocalContext.current
val lifecycleOwner = LocalLifecycleOwner.current
val signInState by viewModel.signInState.collectAsStateWithLifecycle(lifecycleOwner = lifecycleOwner)

LaunchedEffect(viewModel.signInSideEffects, lifecycleOwner) {
viewModel.signInSideEffects.flowWithLifecycle(lifecycle = lifecycleOwner.lifecycle)
.collect { sideEffect ->
when (sideEffect) {
is SignInSideEffect.ShowToast -> context.toast(sideEffect.message)
is SignInSideEffect.NavigateToHome -> navController.navigateSignUp()
is SignInSideEffect.NavigateToHome -> navController.navigateHome()
is SignInSideEffect.NavigateSignUp -> navController.navigateSignUp()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import androidx.annotation.StringRes

sealed class SignInSideEffect {
data object NavigateToHome : SignInSideEffect()
data object NavigateSignUp : SignInSideEffect()
data class NavigateSignUp(val authId: String) : SignInSideEffect()
data class ShowToast(@StringRes val message: Int) : SignInSideEffect()
}

This file was deleted.

Loading

0 comments on commit 3c0a58c

Please sign in to comment.