-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Week4 #8
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4์ฃผ์ฐจ ์๋ฒํต์ ๋ง์ด ํ๋ค์์ํ
๋ฐ ๊ณ ์ ๋ง์์ต๋๋คใ
ใ
ํฉ๋์ธ๋ฏธ๋๋ ํ์ดํ
!
interface UserRegistrationService { | ||
@POST("/user") | ||
suspend fun postUserRegistration( | ||
@Body userRequest: RequestUserRegistrationData | ||
): Response<ResponseUserRegistration> | ||
} | ||
|
||
interface LoginService { | ||
@POST("/login") | ||
suspend fun postLogin( | ||
@Body loginRequeset: RequestLoginData | ||
): Response<ResponseLogin> | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋ค๋ฅธ ์๋น์ค๋ผ๋ฉด ๋ค๋ฅธ ํ์ผ๋ก ๋ถ๋ฆฌํ๋๊ฒ ๋์ ๊ฒ ๊ฐ์์
์๋๋ฉด ๊ฐ์ ํ์ผ๋ช
Auth์ ๋ง์ถฐ์ AuthService๋ก ํ ๋ค์ ๊ฐ์ ์๋น์ค ๋ด์ ๋๊ฐ์ ํจ์๋ฅผ ๋ฃ๋ ๋ฐฉ๋ฒ๋ ์๊ฒ ์ฃ ?
interface AuthService {
@POST("/user")
suspend fun postUserRegistration(
@Body userRequest: RequestUserRegistrationData
): Response<ResponseUserRegistration>
@POST("/login")
suspend fun postLogin(
@Body loginRequeset: RequestLoginData
): Response<ResponseLogin>
}
์ด๋ฐ ์์ผ๋ฃจ์!
@Serializable | ||
data class RequestUserRegistrationData( | ||
@SerialName("username") | ||
val userName: String, | ||
@SerialName("password") | ||
val password: String, | ||
@SerialName("hobby") | ||
val hobby: String | ||
) | ||
|
||
@Serializable | ||
data class ResponseUserRegistration( | ||
@SerialName("result") | ||
val result: ResultUserNo | ||
) | ||
|
||
@Serializable | ||
data class ResultUserNo( | ||
@SerialName("no") | ||
val no: Int | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DTO๊ฐ์ ๊ฒฝ์ฐ๋ ์ด๋ฆ์ Dto๋ผ๊ณ ๋ช
์ํด์ฃผ๋ ๊ฒ์ด ์ข์ต๋๋ค
๋ํ Response, Request๋ฑ์ ๋ณดํต์ ๋ค๋ฅธ ํ์ผ๋ก ๋นผ๋ ํธ์
๋๋ค.
@Serializable | |
data class RequestUserRegistrationData( | |
@SerialName("username") | |
val userName: String, | |
@SerialName("password") | |
val password: String, | |
@SerialName("hobby") | |
val hobby: String | |
) | |
@Serializable | |
data class ResponseUserRegistration( | |
@SerialName("result") | |
val result: ResultUserNo | |
) | |
@Serializable | |
data class ResultUserNo( | |
@SerialName("no") | |
val no: Int | |
) | |
@Serializable | |
data class RequestUserRegistrationDto( | |
@SerialName("username") | |
val userName: String, | |
@SerialName("password") | |
val password: String, | |
@SerialName("hobby") | |
val hobby: String | |
) | |
@Serializable | |
data class ResponseUserRegistrationDto( | |
@SerialName("result") | |
val result: ResultUserNo | |
) | |
@Serializable | |
data class ResponseUserRegistrationDto( | |
@SerialName("no") | |
val no: Int | |
) |
์ด๋ฐ์์ผ๋ก์! ๊ฐ๊ฐ Dto๋ ๋ค๋ฅธ ํ์ผ์ ๋ฃ์ด์ฃผ์๋๊ฒ ์กฐ๊ธ ๋ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค.
๊ทธ๋ ๊ฒ ํ๋ฉด ์ฃผ์์ผ๋ก ํด๋น Dto๋ค์ ๋๋ ์ฃผ๋ ๊ฒ๋ ํ์ ์๊ฒ ์ฃ ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์๋ง ํจํค์ง๋ช ์ด dto์ฌ์ dto๋ฅผ ๋ถ์ด๋ ๊ฒ์ ์ถ์ฒํด์ฃผ์ ๊ฒ ๊ฐ์์, ์ด ๋ถ๋ถ์ ์ถ ํ ํ ์ปจ๋ฒค์ ์ ์ธ์ฐ๊ณ ๊ฐ ๋ ์ด์ด์ ์๋ง๋ suffix๋ฅผ ๋ถ์ฌ์ฃผ๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค.
@@ -25,14 +34,30 @@ enum class BottomNavItem(val icon: ImageVector, val description: String) { | |||
PROFILE(Icons.Default.AccountCircle, "๋ด ์ ๋ณด") | |||
} | |||
|
|||
@SuppressLint("UnrememberedMutableState") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ด๊ฑด ์ ์ฌ์ฉํ์ ๊ฑด๊ฐ์ฉ?
fun SignInScreen( | ||
signViewModel: SignViewModel, | ||
onNavigateToMain: () -> Unit, | ||
onNavigateToSignUp: () -> Unit | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ปดํฌ์ ๋ธ ํจ์๊ฐ ๋ทฐ๋ชจ๋ธ์ ์ธ์๋ก ๋ฐ๊ฒ ๋๋ฉด ํด๋น ์คํฌ๋ฆฐ์ ๋ทฐ๋ชจ๋ธ์ ๊ฐํ๊ฒ ๊ฒฐํฉ๋๊ฒ ์ฃ ? ๊ทธ๋ฌ๋ฉด ์ปดํฌ์ ๋ธ ํจ์์ ์ฌ์ฌ์ฉ์ ์ ํํ๋ ๊ฒฝ์ฐ๊ฐ ์๊ธธ ์ ์์ต๋๋ค. ๋ํ UI์ ๋น์ง๋์ค ๋ก์ง ๊ฐ์ ๊ฒฝ๊ณ๊ฐ ํ๋ ค์ง ์๋ ์๊ฒ ์ต๋๋ค!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๊ตฟ! ๋ค๋ง ์ ๋ Screen๋จ์ ์ด๋์ ๋ ํฐ ๋ฒ์ฃผ์ UI๋ผ๊ณ ์๊ฐํด์ ๋์์ง๋ ์๋ค๊ณ ๋ณด๋ ์
์ฅ์ด๊ธดํฉ๋๋ค.
์ฆ SignInScreen์ ๋ค๋ฅธ ViewModel์ ์ฐธ์กฐํ์ฌ, ํน์ ViewModel ์์ด ์ฌํ์ฉํ๋ ๊ฒฝ์ฐ๋ ์์ ๊ฒ ๊ฐ์ต๋๋ค.
๋ฌผ๋ก ์ปดํฌ๋ํธ๋จ์์๋ ๊ธ๋ฌผ์ด์ง๋ง์ ํํณ
/** Validate inputs for sign-up */ | ||
fun validateSignUpInputs(username: String, password: String, hobby: String): Boolean { | ||
return username.length <= 8 && password.length <= 8 && hobby.length <= 8 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ด๊ฑด ์๋ฒ์์ ๊ฒ์ฆํด์ฃผ๋ ๋ถ๋ถ์ด๋ผ ์ฌ๊ธฐ์๋ ๋ฐ๋ก ํ์ํ์ง ์์ ๊ฒ ๊ฐ์ต๋๋ค!
์๋ฒ์์ ๋ด๋ ค์ฃผ๋ ์๋ฌ์ฝ๋๋ฅผ ํตํด ์๋ฌํธ๋ค๋ง์ ํด๋ณด์๋ ๊ฒ๋ ์ข์ ๊ฒ ๊ฐ์์ฉ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4์ฃผ์ฐจ ์ ๋ง ๊ณ ์ํ์ จ์ต๋๋ค..! ํ์ฃผํ์ฃผ๊ฐ ํด๋น ์ฃผ๊ฐ ์ ์ผ ์ด๋ ต๋ค๊ณ ํ๋ ๊ฐฑ์ ํ๋ ์ฃผ์ฐจ์ธ ๊ฒ ๊ฐ๋ค์...ใ ใ ์ธ๋ฏธ๋ ๋ ๋ฐฐ์ด ํต์ ๋ฐํ์ผ๋ก ์ ๊ตฌํํด์ฃผ์ ๊ฒ ๊ฐ์ต๋๋ค! ํฉ์ธ๋์ ์ ํฌ ๋ฐฐ์ด ์ฝ๋ ๋ฐํ์ผ๋ก ์ด์ฌํ ํ์ ํด๋ด์ ์์์์~!
interface HobbyService { | ||
@GET("/user/my-hobby") | ||
suspend fun getHobby( | ||
@Header("token") token: String? | ||
): Response<ResponseMyHobbyData> | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ํ์ฌ ๋ช ์ธ์์๋ ์ด๋ ๊ฒ Header๋ฅผ ์ง์ ๋ช ์ํด์ ๋ณด๋ด๋ ๊ฒ์ผ๋ก ๋์์์ง๋ง, ์ค์ ํ๋ก์ ํธ์์๋ interceptor์ ํ ํฐ์ ์ ์ํ๋ ๋ฐฉ๋ฒ๋ ๋ง์ด ์ฌ์ฉํ๋๋ผ๊ตฌ์! ํ๋ฒ ์ฐพ์๋ณด์๋ ๊ฒ๋ ์ข์ ๊ฒ ๊ฐ์์!
<string name="hobby_label">์ทจ๋ฏธ๋ฅผ ์ ๋ ฅํด์ฃผ์ธ์.</string> | ||
<string name="sign_up_hobby_hint">์ทจ๋ฏธ๋ฅผ ์ ๋ ฅํด์ฃผ์ธ์.</string> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๊ฐ์ ๊ฐ์ผ๋ก ์ฌ์ฉํ ์ ์์ ๊ฒ ๊ฐ์์!
/** Validate inputs for sign-up */ | ||
fun validateSignUpInputs(username: String, password: String, hobby: String): Boolean { | ||
return username.length <= 8 && password.length <= 8 && hobby.length <= 8 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ ๋ ํด๋ผ์ด์ธํธ์์ ์์ธ์ฒ๋ฆฌ๋ฅผ ์งํํ์ง๋ง.. ๋ช
์ธ๋ฅผ ํ์ธํด๋ณด๋ ๊ฒ์ฆ์ด ์๋๋ผ๊ตฌ์!
์ค๋ฅ ์ฝ๋์ ๋ฐ๋ผ ์์ธ์ฒ๋ฆฌ ์ถ๊ฐํ๋ฉด ์ข์ ๊ฒ ๊ฐ์์
val response = loginService.postLogin(request) // Hilt๋ก ์ฃผ์ ๋ ์๋น์ค ์ฌ์ฉ | ||
if (response.isSuccessful) { | ||
response.body()?.let { | ||
val token = it.result.token | ||
Log.d("SignViewModel", "๋ก๊ทธ์ธ ์ฑ๊ณต, ํ ํฐ: $token") // ์ฑ๊ณต ์๋ต ๋ก๊ทธ | ||
preferences.edit().putString("auth_token", token).apply() | ||
onSuccess() | ||
} ?: onFailure("์๋ฒ ์๋ต์ด ๋น์ด์์ต๋๋ค.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sharedpreference ์ ํ ํฐ์ ์ ์ฅํ๋ ๋ฐฉ๋ฒ์ด๊ตฐ์! ํ ํฐ์ ์ ์ฅํ๊ณ ์ฌ์ฉํ๋ ์ฝ๋๋ ์ถํ์ ๋ฐ๋ณต๋๋ header๋ ํ์ํ๋ ์์ ์์๋ ์ฐ์ผ ๊ฐ๋ฅ์ฑ์ด ์์ด ๊ฐ์ฒดํ ์์ผ๋ ์ข์ ๊ฒ ๊ฐ์์ฉ
Text( | ||
text = email, | ||
text = hobby.ifEmpty { "sport" }, // ์ด๊ธฐ ๊ฐ ๋ฐ ์ ๋ฐ์ดํธ๋ ๊ฐ ๋ฐ์ | ||
fontSize = 15.sp, | ||
color = Color.White, | ||
fontWeight = FontWeight.Bold, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hobby ๊ฐ ๋น์ด์์ ๋ sport๋ก ๋ช ์ํ์ ์ด์ ๊ฐ ์์๊น์?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์๋
ํ์ธ์ ์ธํธ๋!! ใ
ใ
๋ ๋ฆ์ด์ ์ฃ์กํฉ๋๋ค!
๋ท ๋ถ๋ถ์ ๋ชป๋ด์... ํน์๋ ์ถ๊ฐ์ ์ผ๋ก ๊ถ๊ธํ ๋ถ๋ถ ์์ผ๋ฉด ์ธ์ ๋ ๋ต๊ธ ๋จ๊ฒจ์ฃผ์ธ์!
4์ฃผ์ฐจ๋ ๊ณ ์๋ง์ผ์ จ์ต๋๋ค!
onSuccess: () -> Unit, | ||
onFailure: () -> Unit, | ||
onFailure: () -> Unit, // @Composable ์ ๊ฑฐ | ||
modifier: Modifier = Modifier, | ||
buttonColor: Color = Color.Blue | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ด ์ฃผ์์ ์ถ๊ฐํ๊ฒ ๋์ ํ์คํ ๋ฆฌ๊ฐ ๊ถ๊ธํฉ๋๋ค.
@Serializable | ||
data class RequestUserRegistrationData( | ||
@SerialName("username") | ||
val userName: String, | ||
@SerialName("password") | ||
val password: String, | ||
@SerialName("hobby") | ||
val hobby: String | ||
) | ||
|
||
@Serializable | ||
data class ResponseUserRegistration( | ||
@SerialName("result") | ||
val result: ResultUserNo | ||
) | ||
|
||
@Serializable | ||
data class ResultUserNo( | ||
@SerialName("no") | ||
val no: Int | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์๋ง ํจํค์ง๋ช ์ด dto์ฌ์ dto๋ฅผ ๋ถ์ด๋ ๊ฒ์ ์ถ์ฒํด์ฃผ์ ๊ฒ ๊ฐ์์, ์ด ๋ถ๋ถ์ ์ถ ํ ํ ์ปจ๋ฒค์ ์ ์ธ์ฐ๊ณ ๊ฐ ๋ ์ด์ด์ ์๋ง๋ suffix๋ฅผ ๋ถ์ฌ์ฃผ๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค.
) { | ||
MyHeader(email = signViewModel.email) | ||
MyHeader(hobby = hobby) // ์ต์ hobby ๊ฐ์ ์ ๋ฌ | ||
Spacer(modifier = Modifier.height(20.dp)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ธ์๋ก ๋๊ธฐ๋ ๊ฒฝ์ฐ ์ต์ ๊ฐ์ ์ ๋ฌํ๋ค๋ผ๊ธฐ ๋ณด๋ค๋ ์ ํํ๋ state์ธ hobby๋ฅผ ์ ๋ฌํด์ ํญ์ ์ต์ ๊ฐ์ผ๋ก ๋ฆฌ์ปดํฌ์ง์ ์ ๋ณด์ฅํจ ์ด ๋ง์ ๊ฒ ๊ฐ์์
fun SignInScreen( | ||
signViewModel: SignViewModel, | ||
onNavigateToMain: () -> Unit, | ||
onNavigateToSignUp: () -> Unit | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๊ตฟ! ๋ค๋ง ์ ๋ Screen๋จ์ ์ด๋์ ๋ ํฐ ๋ฒ์ฃผ์ UI๋ผ๊ณ ์๊ฐํด์ ๋์์ง๋ ์๋ค๊ณ ๋ณด๋ ์
์ฅ์ด๊ธดํฉ๋๋ค.
์ฆ SignInScreen์ ๋ค๋ฅธ ViewModel์ ์ฐธ์กฐํ์ฌ, ํน์ ViewModel ์์ด ์ฌํ์ฉํ๋ ๊ฒฝ์ฐ๋ ์์ ๊ฒ ๊ฐ์ต๋๋ค.
๋ฌผ๋ก ์ปดํฌ๋ํธ๋จ์์๋ ๊ธ๋ฌผ์ด์ง๋ง์ ํํณ
) { | ||
SignUpHeader(onNavigateToSignIn) | ||
SignUpTobBar (onNavigateToSignIn) | ||
Spacer(modifier = Modifier.height(20.dp)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋์ด์ฐ๊ธฐ๊ฐ ์๋ค์
if (usernameError) { | ||
Text( | ||
text = "8์๋ณด๋ค ํฌ๋ฉด ์๋ฉ๋๋ค.", | ||
color = Color.Red, | ||
modifier = Modifier.padding(top = 4.dp) | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ ๊ธ์ ๋ค์ํ ํ์ฅํจ์๊ฐ ์๋๋ฐ ์ฐธ๊ณ ํด๋ณด๋ฉด ์ข์ ๊ฒ ๊ฐ์์ ใ
.ใ
Medium: https://proandroiddev.com/top-5-extension-functions-every-jetpack-compose-developer-should-have-cbf2c50d557c
coroutineScope.launch { | ||
withContext(Dispatchers.Main) { | ||
snackbarHostState.showSnackbar("ํ์๊ฐ์ ์ฑ๊ณต") // ๋ฉ์ธ ์ค๋ ๋์์ ํธ์ถ | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
coroutineScope.launch ๋ ๊ธฐ๋ณธ์ ์ผ๋ก ์ด๋ค ์ค๋ ๋์ธ๊ฐ์?
withContext(Dispatchers.Main) { | ||
snackbarHostState.showSnackbar("์ ๋ ฅ ๊ฐ์ ํ์ธํด์ฃผ์ธ์.") // ๋ฉ์ธ ์ค๋ ๋์์ ํธ์ถ | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์๊ธฐ๋! Context Switching์ ๋น์ฉ์ด ๋ง์ด ๋๋ ์์ ์ด๋ ํญ์ ์ ์ํด์ ์ฌ์ฉํด๋ณด๋ฉด ์ข์ ๊ฒ ๊ฐ์์, ๊ผญ Context Switching์ด ํ์ํ ์ํฉ์ธ์ง..!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๊ณ ์ํ์ จ์ต๋๋ค ~ ํฉ๋ ์ธ๋ฏธ๋๋ ํ์ดํ !
alias(libs.plugins.kotlin.serialization) | ||
id("kotlin-kapt") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
id์ alias์ ์ฐจ์ด์ ์ ๋ฌด์์ผ๊น์!
//hilt | ||
implementation(libs.hilt.android.v2511) | ||
kapt(libs.hilt.compiler.v2511) | ||
implementation(libs.androidx.hilt.navigation.compose) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ํํธ๋ฅผ ์ฌ์ฉํ์ จ๋ค์! ํํธ๋ฅผ ์ฌ์ฉํ์ ๋์ ์ด์ ์ ๋ญ๊น์?
object ApiFactory { | ||
private const val BASE_URL: String = BuildConfig.BASE_URL | ||
|
||
@Provides |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
) | ||
|
||
@Serializable | ||
data class ResponseUserRegistration( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ง๊ธ ๋ณด๋ฉด ์๋ต ๊ฐ์ฒด์์ ๋์ผํ ํํ๊ฐ ์ฌ์ฉ๋๋๋ฐ์, ์ด ๊ฒฝ์ฐ Base๊ฐ ๋๋ Response๋ฅผ ๋ง๋ค์ด์ ์ฌ์ฉํ ์๋ ์์ต๋๋ค!
Related issue ๐
Work Description โ๏ธ
Screenshot ๐ธ
Uploading แแ ชแแ งแซ
2024-11-15.11.58.11.mov
2024-11-15.11.58.39.mov
Uncompleted Tasks ๐
To Reviewers ๐ข