-
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.
* [nunu/#43] feat: 로그인/회원가입 api 연결 구현 - Retrofit 이용 - jwt int -> string 변경 * [nunu/#43] feat: LookFragment 구현 - LookFragment의 차트 API RecyclerView에 연동하기 * [nunu/#43] feat: SplashActivity 자동로그인 구현 - jwt Header에 담기 (Retrofit 공식문서 참고) - 성공 시 MainActivity 이동 - 실패 시 LoginActivity 이동 * [nunu/#43] feat: HomeFragment API 연동 - RetrofitInstance 추가 - AlbumApi, Album Response, AlbumService 구현 - HomeFragment 연결
- Loading branch information
1 parent
fd4ed78
commit 75287d1
Showing
28 changed files
with
623 additions
and
23 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
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,9 @@ | ||
package com.example.umc_6th | ||
|
||
import retrofit2.Call | ||
import retrofit2.http.GET | ||
|
||
interface AlbumApi { | ||
@GET("/albums") | ||
fun getAlbums(): Call<AlbumResponse> | ||
} |
20 changes: 20 additions & 0 deletions
20
UMC_6th/app/src/main/java/com/example/umc_6th/AlbumResponse.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,20 @@ | ||
package com.example.umc_6th | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class AlbumResponse( @SerializedName("isSuccess") val isSuccess: Boolean, | ||
@SerializedName("code") val code: Int, | ||
@SerializedName("message") val message: String, | ||
@SerializedName("result") val result: TodayAlbumResult) | ||
|
||
|
||
data class TodayAlbumResult( | ||
@SerializedName("albums") val albums: List<TodayAlbum> | ||
) | ||
|
||
data class TodayAlbum( | ||
@SerializedName("albumIdx") val albumIdx: Int, | ||
@SerializedName("singer") val singer: String, | ||
@SerializedName("title") val title:String, | ||
@SerializedName("coverImgUrl") val coverImgUrl : String | ||
) |
40 changes: 40 additions & 0 deletions
40
UMC_6th/app/src/main/java/com/example/umc_6th/AlbumService.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,40 @@ | ||
package com.example.umc_6th | ||
|
||
import android.util.Log | ||
import retrofit2.Call | ||
import retrofit2.Callback | ||
import retrofit2.Response | ||
|
||
class AlbumService { | ||
private lateinit var homeAlbumView: HomeAlbumView | ||
|
||
fun setHomeAlbumView(homeAlbumView: HomeAlbumView) { | ||
this.homeAlbumView = homeAlbumView | ||
} | ||
|
||
fun getAlbum() { | ||
homeAlbumView.onGetAlbumLoading() | ||
|
||
RetrofitInstance.albumApi.getAlbums().enqueue(object : Callback<AlbumResponse> { | ||
override fun onResponse(call: Call<AlbumResponse>, response: Response<AlbumResponse>) { | ||
if (response.isSuccessful && response.code() == 200) { | ||
val albumResponse: AlbumResponse = response.body()!! | ||
|
||
Log.d("ALBUM-RESPONSE", albumResponse.toString()) | ||
|
||
when (val code = albumResponse.code) { | ||
1000 -> { | ||
homeAlbumView.onGetAlbumSuccess(code, albumResponse.result!!) | ||
} | ||
|
||
else -> homeAlbumView.onGetAlbumFailure(code, albumResponse.message) | ||
} | ||
} | ||
} | ||
|
||
override fun onFailure(call: Call<AlbumResponse>, t: Throwable) { | ||
homeAlbumView.onGetAlbumFailure(400, "네트워크 오류가 발생했습니다.") | ||
} | ||
}) | ||
} | ||
} |
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 | ||
) |
7 changes: 7 additions & 0 deletions
7
UMC_6th/app/src/main/java/com/example/umc_6th/HomeAlbumView.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 | ||
|
||
interface HomeAlbumView { | ||
fun onGetAlbumLoading() | ||
fun onGetAlbumSuccess(code: Int, result: TodayAlbumResult) | ||
fun onGetAlbumFailure(code: Int, 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
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) | ||
} |
Oops, something went wrong.