-
Notifications
You must be signed in to change notification settings - Fork 0
[Mission] 9주차 미션 제출 #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kang4094
wants to merge
3
commits into
Backy/main
Choose a base branch
from
Backy/#92
base: Backy/main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
backy/week4/app/src/main/java/com/rkdgudrn4094/week2/AuthResponse.kt
This file contains hidden or 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.rkdgudrn4094.week2 | ||
|
|
||
| import com.google.gson.annotations.SerializedName | ||
|
|
||
| data class AuthResponse( | ||
| @SerializedName(value="status") val status: Boolean, | ||
| @SerializedName(value="code") val code: String, | ||
| @SerializedName(value="message") val message: String, | ||
| @SerializedName(value="data") val data: LoginData? | ||
| ) | ||
|
|
||
| data class LoginData( | ||
| @SerializedName(value="name") val name: String, | ||
| @SerializedName(value="memberId") val memberId: Int, | ||
| @SerializedName(value="accessToken") var accessToken: String | ||
| ) |
18 changes: 18 additions & 0 deletions
18
backy/week4/app/src/main/java/com/rkdgudrn4094/week2/AuthRetrofitInterface.kt
This file contains hidden or 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,18 @@ | ||
| package com.rkdgudrn4094.week2 | ||
|
|
||
| import retrofit2.Call | ||
| import retrofit2.http.Body | ||
| import retrofit2.http.GET | ||
| import retrofit2.http.Header | ||
| import retrofit2.http.POST | ||
|
|
||
| interface AuthRetrofitInterface { | ||
| @POST("signup") | ||
| fun signUp(@Body user: User): Call<AuthResponse> | ||
|
|
||
| @POST("login") | ||
| fun login(@Body user: User):Call<AuthResponse> | ||
|
|
||
| @GET("test") | ||
| fun test(@Header("Authorization") token: String): Call<TestResponse> | ||
| } |
119 changes: 119 additions & 0 deletions
119
backy/week4/app/src/main/java/com/rkdgudrn4094/week2/AuthService.kt
This file contains hidden or 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,119 @@ | ||
| package com.rkdgudrn4094.week2 | ||
|
|
||
| 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 | ||
| private lateinit var testView: TestView | ||
|
|
||
| fun setSignUpView(signUpView: SignUpView){ | ||
| this.signUpView = signUpView | ||
| } | ||
| fun setLoginView(loginView: LoginView){ | ||
| this.loginView = loginView | ||
| } | ||
| fun setTestView(testView: TestView){ | ||
| this.testView = testView | ||
| } | ||
|
|
||
| fun signUp(user: User){ | ||
| val authService = getRetrofit().create(AuthRetrofitInterface::class.java) | ||
| authService.signUp(user).enqueue(object: Callback<AuthResponse>{ | ||
| override fun onResponse( | ||
| call: Call<AuthResponse?>, | ||
| response: Response<AuthResponse?> | ||
| ) { | ||
| Log.d("SIGNUP/SUCCESS", response.toString()) | ||
|
|
||
| val resp: AuthResponse = response.body()!! | ||
|
|
||
| if(::signUpView.isInitialized){ | ||
| when(resp.code){ | ||
| "COMMON201"->signUpView.onSignUpSuccess() | ||
| else->signUpView.onSignUpFailure() | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| override fun onFailure( | ||
| call: Call<AuthResponse?>, | ||
| t: Throwable | ||
| ) { | ||
| Log.d("SIGNUP/FAILURE", t.message.toString()) | ||
| } | ||
|
|
||
|
|
||
| }) | ||
|
|
||
| Log.d("SIGNUP", "HELLOOO") | ||
| } | ||
|
|
||
| fun login(user: User){ | ||
| val authService = getRetrofit().create(AuthRetrofitInterface::class.java) | ||
| authService.login(user).enqueue(object: Callback<AuthResponse>{ | ||
| override fun onResponse( | ||
| call: Call<AuthResponse?>, | ||
| response: Response<AuthResponse?> | ||
| ) { | ||
| Log.d("LOGIN/SUCCESS", response.toString()) | ||
|
|
||
| val resp: AuthResponse = response.body()!! | ||
| val code = resp.code | ||
| if(::loginView.isInitialized){ | ||
| when(code){ | ||
| "COMMON200_1"->loginView.onLoginSuccess(code, resp.data!!) | ||
| else->loginView.onLoginFailure() | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| override fun onFailure( | ||
| call: Call<AuthResponse?>, | ||
| t: Throwable | ||
| ) { | ||
| Log.d("LOGIN/FAILURE", t.message.toString()) | ||
| } | ||
| }) | ||
|
|
||
| Log.d("LOGIN", "HELLOOO") | ||
| } | ||
|
|
||
| fun test(token: String){ | ||
| val bearerToken = if (token.startsWith("Bearer ")) token else "Bearer $token" | ||
|
|
||
| val authService = getRetrofit().create(AuthRetrofitInterface::class.java) | ||
| authService.test(bearerToken).enqueue(object: Callback<TestResponse>{ | ||
| override fun onResponse( | ||
| call: Call<TestResponse?>, | ||
| response: Response<TestResponse?> | ||
| ) { | ||
| Log.d("TEST/SUCCESS", response.toString()) | ||
|
|
||
| val resp: TestResponse = response.body()!! | ||
| val code = resp.code | ||
| if(::testView.isInitialized){ | ||
| when(code){ | ||
| "COMMON200_1"->testView.onTestSuccess(resp.message) | ||
| else->testView.onTestFailure() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| override fun onFailure( | ||
| call: Call<TestResponse?>, | ||
| t: Throwable | ||
| ) { | ||
| Log.d("TEST/FAILURE", t.message.toString()) | ||
| } | ||
|
|
||
| }) | ||
|
|
||
| Log.d("LOGIN", "HELLOOO") | ||
| } | ||
| } |
This file contains hidden or 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
backy/week4/app/src/main/java/com/rkdgudrn4094/week2/LoginView.kt
This file contains hidden or 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.rkdgudrn4094.week2 | ||
|
|
||
| interface LoginView { | ||
| fun onLoginSuccess(code: String, data: LoginData) | ||
| fun onLoginFailure() | ||
| } |
This file contains hidden or 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
backy/week4/app/src/main/java/com/rkdgudrn4094/week2/NetworkModule.kt
This file contains hidden or 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.rkdgudrn4094.week2 | ||
|
|
||
| import retrofit2.Retrofit | ||
| import retrofit2.converter.gson.GsonConverterFactory | ||
|
|
||
| const val BASE_URL = "http://43.200.73.115:8080/" | ||
|
|
||
| fun getRetrofit(): Retrofit{ | ||
| val retrofit = Retrofit.Builder().baseUrl(BASE_URL) | ||
| .addConverterFactory(GsonConverterFactory.create()).build() | ||
|
|
||
| return retrofit | ||
| } | ||
| /* | ||
| class NetworkModule { | ||
| }*/ | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
작성하신 BASE_URL을 보니 IP 주소를 상수에 그대로 적으셨는데, 프로젝트를 할 때는 보통 저렇게 하지 않습니다. Git 같은 곳에 올릴 때 서버가 노출되면 보안상 좋지 않기 때문에 보통은 local.properties라는 파일에 숨겨두고, build.gradle을 통해 불러오는 방식을 씁니다! 나중에 한번 찾아보시면 좋을 것 같아요~