generated from NOW-SOPT-ANDROID/now-sopt-android-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
125 additions
and
71 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
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
6 changes: 6 additions & 0 deletions
6
app/src/main/java/com/sopt/now/compose/data/model/SignInState.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,6 @@ | ||
package com.sopt.now.compose.data.model | ||
|
||
data class SignInState( | ||
val isSuccess: Boolean, | ||
val message: String, | ||
) |
6 changes: 6 additions & 0 deletions
6
app/src/main/java/com/sopt/now/compose/data/model/SignUpState.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,6 @@ | ||
package com.sopt.now.compose.data.model | ||
|
||
data class SignUpState( | ||
val isSuccess: Boolean, | ||
val message: 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
58 changes: 58 additions & 0 deletions
58
app/src/main/java/com/sopt/now/compose/ui/signUp/SignUpViewModel.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,58 @@ | ||
package com.sopt.now.compose.ui.signUp | ||
|
||
import android.util.Log | ||
import androidx.lifecycle.ViewModel | ||
import com.sopt.now.compose.data.model.RequestSignUpDto | ||
import com.sopt.now.compose.data.model.ResponseSignUpDto | ||
import com.sopt.now.compose.data.model.SignUpState | ||
import com.sopt.now.compose.data.module.ServicePool | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.flow.update | ||
import retrofit2.Call | ||
import retrofit2.Callback | ||
import retrofit2.Response | ||
|
||
|
||
class SignUpViewModel : ViewModel() { | ||
private val authService by lazy { ServicePool.authService } | ||
|
||
private val _signUpState = MutableStateFlow(SignUpState(isSuccess = false, message = "")) | ||
val signUpState = _signUpState.asStateFlow() | ||
|
||
fun signUp(request: RequestSignUpDto) { | ||
authService.signUp(request).enqueue( | ||
object : Callback<ResponseSignUpDto> { | ||
override fun onResponse( | ||
call: Call<ResponseSignUpDto>, | ||
response: Response<ResponseSignUpDto>, | ||
) { | ||
if (response.isSuccessful) { | ||
val userId = response.headers()["location"] | ||
_signUpState.update { | ||
SignUpState( | ||
isSuccess = true, | ||
message = "가입된 유저 아이디는 $userId" | ||
) | ||
} | ||
} else { | ||
val error = response.code() | ||
_signUpState.update { | ||
SignUpState( | ||
isSuccess = false, | ||
message = "회원가입 실패 : $error" | ||
) | ||
} | ||
} | ||
} | ||
|
||
override fun onFailure(call: Call<ResponseSignUpDto>, t: Throwable) { | ||
_signUpState.update { | ||
SignUpState(isSuccess = false, message = "서버 에러") | ||
} | ||
Log.d("SignUp", "${t.message}") | ||
} | ||
}, | ||
) | ||
} | ||
} |
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