-
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
8 changed files
with
118 additions
and
32 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
53 changes: 53 additions & 0 deletions
53
UMC_6th/app/src/main/java/com/example/umc_6th/AuthService.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,53 @@ | ||
package com.example.umc_6th | ||
|
||
import android.util.Log | ||
import retrofit2.Call | ||
import retrofit2.Callback | ||
import retrofit2.Response | ||
|
||
class AuthService { | ||
private lateinit var signUpView: SignUpView | ||
private lateinit var loginView : LoginView | ||
|
||
fun setSignUpView(signUpView: SignUpView) { | ||
this.signUpView = signUpView | ||
} | ||
|
||
fun setLoginView(loginView: LoginView) { | ||
this.loginView = loginView | ||
} | ||
|
||
|
||
fun signUp(user : User) { | ||
RetrofitInstance.authApi.signUp(user).enqueue(object: Callback<BaseResponse> { | ||
override fun onResponse(call: Call<BaseResponse>, response: Response<BaseResponse>) { | ||
Log.d("SignUp-Success", response.toString()) | ||
val response : BaseResponse = response.body()!! | ||
when(response.code) { | ||
1000 -> signUpView.onSignUpSuccess() | ||
else -> signUpView.onSignUpFailure(response.message) | ||
} | ||
} | ||
override fun onFailure(call: Call<BaseResponse>, t: Throwable) { | ||
Log.d("SignUp-Failure", t.message.toString()) | ||
} | ||
}) | ||
Log.d("SignUpActivity", "All Finished") | ||
} | ||
fun login(user : User) { | ||
RetrofitInstance.authApi.login(user).enqueue(object: Callback<BaseResponse> { | ||
override fun onResponse(call: Call<BaseResponse>, response: Response<BaseResponse>) { | ||
Log.d("Login-Success", response.toString()) | ||
val response : BaseResponse = response.body()!! | ||
when(val code = response.code) { | ||
1000 -> loginView.onLoginSuccess(code, response.result!!) | ||
else -> loginView.onLoginFailure(response.message) | ||
} | ||
} | ||
override fun onFailure(call: Call<BaseResponse>, t: Throwable) { | ||
Log.d("Login-Failure", t.message.toString()) | ||
} | ||
}) | ||
Log.d("LoginActivity", "All Finished") | ||
} | ||
} |
14 changes: 11 additions & 3 deletions
14
UMC_6th/app/src/main/java/com/example/umc_6th/BaseResponse.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 |
---|---|---|
@@ -1,7 +1,15 @@ | ||
package com.example.umc_6th | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class BaseResponse( | ||
val isSuccess : Boolean, | ||
val code : Int, | ||
val message : String | ||
@SerializedName("isSuccess") val isSuccess: Boolean, | ||
@SerializedName("code") val code: Int, | ||
@SerializedName("message") val message: String, | ||
@SerializedName("result") val result: Result? | ||
) | ||
|
||
data class Result ( | ||
@SerializedName("userIdx") var userIdx : Int, | ||
@SerializedName("jwt") var jwt : 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.example.umc_6th | ||
|
||
interface LoginView { | ||
fun onLoginSuccess(code : Int, result : Result) | ||
fun onLoginFailure(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.example.umc_6th | ||
|
||
interface SignUpView { | ||
fun onSignUpSuccess() | ||
fun onSignUpFailure(message : String) | ||
} |