generated from GO-SOPT-ANDROID/android-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
72 additions
and
38 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
45 changes: 45 additions & 0 deletions
45
app/src/main/java/org/android/go/sopt/presentation/auth/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,45 @@ | ||
package org.android.go.sopt.presentation.auth | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import org.android.go.sopt.data.remote.SignUpRequestDTO | ||
import org.android.go.sopt.data.remote.SignUpResponseDTO | ||
import org.android.go.sopt.module.AuthServicePool | ||
import retrofit2.Call | ||
import retrofit2.Callback | ||
import retrofit2.Response | ||
|
||
class SignUpViewModel : ViewModel() { | ||
private val _signUpResult: MutableLiveData<SignUpResponseDTO> = MutableLiveData() | ||
val signUpResult: LiveData<SignUpResponseDTO> = _signUpResult | ||
|
||
private val _errorResult: MutableLiveData<String> = MutableLiveData() | ||
val errorResult: LiveData<String> = _errorResult | ||
|
||
fun signUp(id: String, password: String, name: String, skill: String) { | ||
AuthServicePool.authService.signUp( | ||
SignUpRequestDTO( | ||
id, | ||
password, | ||
name, | ||
skill | ||
) | ||
).enqueue(object : Callback<SignUpResponseDTO> { | ||
override fun onResponse( | ||
call: Call<SignUpResponseDTO>, | ||
response: Response<SignUpResponseDTO> | ||
) { | ||
if (response.isSuccessful) { | ||
_signUpResult.value = response.body() | ||
} else { | ||
_errorResult.value = response.message() | ||
} | ||
} | ||
|
||
override fun onFailure(call: Call<SignUpResponseDTO>, t: Throwable) { | ||
_errorResult.value = t.toString() | ||
} | ||
}) | ||
} | ||
} |