-
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.
Showing
14 changed files
with
184 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
7 changes: 7 additions & 0 deletions
7
UMC_6th/app/src/main/java/com/example/umc_6th/ApiRepository.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,7 @@ | ||
package com.example.umc_6th | ||
|
||
class ApiRepository { | ||
companion object { | ||
const val BASE_URL = "https://edu-api-test.softsquared.com" | ||
} | ||
} |
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,13 @@ | ||
package com.example.umc_6th | ||
|
||
import retrofit2.Call | ||
import retrofit2.http.Body | ||
import retrofit2.http.POST | ||
|
||
interface AuthApi { | ||
@POST("/users") | ||
fun signUp(@Body user : User) : Call<BaseResponse> | ||
|
||
@POST("/users/login") | ||
fun login(@Body user : User) : Call<BaseResponse> | ||
} |
52 changes: 52 additions & 0 deletions
52
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,52 @@ | ||
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") | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.example.umc_6th | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class BaseResponse( | ||
@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
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
16 changes: 16 additions & 0 deletions
16
UMC_6th/app/src/main/java/com/example/umc_6th/RetrofitInstance.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,16 @@ | ||
package com.example.umc_6th | ||
|
||
import retrofit2.Retrofit | ||
import retrofit2.converter.gson.GsonConverterFactory | ||
|
||
class RetrofitInstance { | ||
companion object { | ||
private val retrofit by lazy { | ||
Retrofit.Builder() | ||
.baseUrl(ApiRepository.BASE_URL) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.build() | ||
} | ||
val authApi = retrofit.create(AuthApi::class.java) | ||
} | ||
} |
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) | ||
} |