-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat:add api(users/verify-email, users/temporary-join) * feat:add api(auth) * feat:add api(user/join) except profileImg * feat:add api(auth/mobile) & tokenManager * feat:add api(users/me)
- Loading branch information
1 parent
f071c65
commit 6566882
Showing
28 changed files
with
672 additions
and
45 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
52 changes: 52 additions & 0 deletions
52
src/mobile/app/src/main/java/com/smilegate/Easel/data/TokenManager.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.smilegate.Easel.data | ||
|
||
import android.content.Context | ||
import android.content.SharedPreferences | ||
|
||
object TokenManager { | ||
private const val PREF_NAME = "TokenPrefs" | ||
private const val KEY_ACCESS_TOKEN = "accessToken" | ||
private const val KEY_REFRESH_TOKEN = "refreshToken" | ||
|
||
private var sharedPreferences: SharedPreferences? = null | ||
|
||
// SharedPreferences 인스턴스 가져오기 | ||
private fun getSharedPreferences(context: Context): SharedPreferences { | ||
if (sharedPreferences == null) { | ||
sharedPreferences = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE) | ||
} | ||
return sharedPreferences!! | ||
} | ||
|
||
// AccessToken 저장 | ||
fun saveAccessToken(context: Context, accessToken: String) { | ||
val editor = getSharedPreferences(context).edit() | ||
editor.putString(KEY_ACCESS_TOKEN, accessToken) | ||
editor.apply() | ||
} | ||
|
||
// RefreshToken 저장 | ||
fun saveRefreshToken(context: Context, refreshToken: String) { | ||
val editor = getSharedPreferences(context).edit() | ||
editor.putString(KEY_REFRESH_TOKEN, refreshToken) | ||
editor.apply() | ||
} | ||
|
||
// AccessToken 가져오기 | ||
fun getAccessToken(context: Context): String? { | ||
return getSharedPreferences(context).getString(KEY_ACCESS_TOKEN, null) | ||
} | ||
|
||
// RefreshToken 가져오기 | ||
fun getRefreshToken(context: Context): String? { | ||
return getSharedPreferences(context).getString(KEY_REFRESH_TOKEN, null) | ||
} | ||
|
||
// 토큰 삭제 | ||
fun clearTokens(context: Context) { | ||
val editor = getSharedPreferences(context).edit() | ||
editor.remove(KEY_ACCESS_TOKEN) | ||
editor.remove(KEY_REFRESH_TOKEN) | ||
editor.apply() | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/mobile/app/src/main/java/com/smilegate/Easel/domain/api/ApiService.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,42 @@ | ||
package com.smilegate.Easel.domain.api | ||
|
||
import com.smilegate.Easel.domain.model.auth.EmailAuth | ||
import com.smilegate.Easel.domain.model.auth.EmailRequest | ||
import com.smilegate.Easel.domain.model.auth.EmailResponse | ||
import com.smilegate.Easel.domain.model.join.JoinRequest | ||
import com.smilegate.Easel.domain.model.join.TemporaryJoinRequest | ||
import com.smilegate.Easel.domain.model.join.VerifyUsernameRequest | ||
import com.smilegate.Easel.domain.model.join.VerifyUsernameResponse | ||
import com.smilegate.Easel.domain.model.login.LoginRequest | ||
import com.smilegate.Easel.domain.model.login.LoginResponse | ||
import com.smilegate.Easel.domain.model.user.UserProfileResponse | ||
import okhttp3.ResponseBody | ||
import retrofit2.Response | ||
import retrofit2.http.Body | ||
import retrofit2.http.GET | ||
import retrofit2.http.Header | ||
import retrofit2.http.POST | ||
|
||
interface ApiService { | ||
@POST("api/auth") | ||
suspend fun sendCode(@Body request: EmailAuth): Response<ResponseBody> | ||
|
||
@POST("api/users/verify-email") | ||
suspend fun verifyEmail(@Body request: EmailRequest): Response<EmailResponse> | ||
|
||
@POST("api/users/temporary-join") | ||
suspend fun temporaryJoin(@Body request: TemporaryJoinRequest): Response<Unit> | ||
|
||
@POST("api/users/verify-username") | ||
suspend fun verifyUsername(@Body request: VerifyUsernameRequest): Response<VerifyUsernameResponse> | ||
|
||
@POST("api/users/join") | ||
suspend fun joinUser(@Body joinRequest: JoinRequest): Response<Unit> | ||
|
||
@POST("api/auth/mobile") | ||
suspend fun login(@Body loginRequest: LoginRequest): Response<LoginResponse> | ||
|
||
@GET("api/users/me") | ||
suspend fun getUserProfile(@Header("Authorization") token: String): Response<UserProfileResponse> | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
src/mobile/app/src/main/java/com/smilegate/Easel/domain/model/auth/EmailAuth.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,6 @@ | ||
package com.smilegate.Easel.domain.model.auth | ||
|
||
data class EmailAuth( | ||
val email: String, | ||
val payload: String, | ||
) |
5 changes: 5 additions & 0 deletions
5
src/mobile/app/src/main/java/com/smilegate/Easel/domain/model/auth/EmailRequest.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,5 @@ | ||
package com.smilegate.Easel.domain.model.auth | ||
|
||
data class EmailRequest( | ||
val email: String | ||
) |
5 changes: 5 additions & 0 deletions
5
src/mobile/app/src/main/java/com/smilegate/Easel/domain/model/auth/EmailResponse.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,5 @@ | ||
package com.smilegate.Easel.domain.model.auth | ||
|
||
data class EmailResponse( | ||
val isDuplicated: Boolean | ||
) |
11 changes: 11 additions & 0 deletions
11
src/mobile/app/src/main/java/com/smilegate/Easel/domain/model/join/JoinRequest.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,11 @@ | ||
package com.smilegate.Easel.domain.model.join | ||
|
||
data class JoinRequest( | ||
val email: String, | ||
val password: String, | ||
val username: String, | ||
val nickname: String, | ||
val introduce: String? = null, | ||
val profileImagePath: String? = null, | ||
val websitePath: String? = null | ||
) |
6 changes: 6 additions & 0 deletions
6
src/mobile/app/src/main/java/com/smilegate/Easel/domain/model/join/TemporaryJoinRequest.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,6 @@ | ||
package com.smilegate.Easel.domain.model.join | ||
|
||
data class TemporaryJoinRequest( | ||
val email: String, | ||
val nickname: String | ||
) |
5 changes: 5 additions & 0 deletions
5
src/mobile/app/src/main/java/com/smilegate/Easel/domain/model/join/VerifyUserNameRequest.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,5 @@ | ||
package com.smilegate.Easel.domain.model.join | ||
|
||
data class VerifyUsernameRequest( | ||
val username: String, | ||
) |
5 changes: 5 additions & 0 deletions
5
src/mobile/app/src/main/java/com/smilegate/Easel/domain/model/join/VerifyUserNameResponse.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,5 @@ | ||
package com.smilegate.Easel.domain.model.join | ||
|
||
data class VerifyUsernameResponse( | ||
val isDuplicated: Boolean, | ||
) |
6 changes: 6 additions & 0 deletions
6
src/mobile/app/src/main/java/com/smilegate/Easel/domain/model/login/LoginRequest.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,6 @@ | ||
package com.smilegate.Easel.domain.model.login | ||
|
||
data class LoginRequest( | ||
val email: String, | ||
val password: String | ||
) |
6 changes: 6 additions & 0 deletions
6
src/mobile/app/src/main/java/com/smilegate/Easel/domain/model/login/LoginResponse.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,6 @@ | ||
package com.smilegate.Easel.domain.model.login | ||
|
||
data class LoginResponse( | ||
val accessToken: String, | ||
val refreshToken: String | ||
) |
13 changes: 13 additions & 0 deletions
13
src/mobile/app/src/main/java/com/smilegate/Easel/domain/model/user/UserProfileResponse.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,13 @@ | ||
package com.smilegate.Easel.domain.model.user | ||
|
||
data class UserProfileResponse( | ||
val backgroundImagePath: String, | ||
val profileImagePath: String, | ||
val nickname: String, | ||
val username: String, | ||
val introduce: String, | ||
val websitePath: String, | ||
val joinedAt: String, | ||
val followingCount: Long, | ||
val followerCount: Long | ||
) |
29 changes: 29 additions & 0 deletions
29
src/mobile/app/src/main/java/com/smilegate/Easel/domain/repository/JoinRepository.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,29 @@ | ||
package com.smilegate.Easel.domain.repository | ||
|
||
import android.util.Log | ||
import com.smilegate.Easel.domain.api.ApiService | ||
import com.smilegate.Easel.domain.model.join.JoinRequest | ||
|
||
class JoinRepository(private val apiService: ApiService) { | ||
|
||
suspend fun joinUser(joinRequest: JoinRequest) { | ||
try { | ||
val response = apiService.joinUser(joinRequest) | ||
|
||
if (response.isSuccessful) { | ||
// 성공적으로 응답을 받았을 때의 처리 | ||
// 여기에서는 특별히 할 일이 없다면 그냥 지나가도 됩니다. | ||
} else { | ||
// 서버로부터 오류 응답을 받았을 때의 처리 | ||
// 예를 들어, 오류 메시지를 출력하거나 특정 동작을 수행할 수 있습니다. | ||
val errorBody = response.errorBody()?.string() | ||
Log.e("UserRepository", "Error: $errorBody") | ||
Log.e("UserRepository","Failed to join user. Response code: ${response.code()}") | ||
} | ||
} catch (e: Exception) { | ||
// 네트워크 오류 등 예외 발생 시의 처리 | ||
Log.e("UserRepository", "Error: ${e.message}", e) | ||
Log.e("UserRepository","Failed to join user. Error: ${e.message}") | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/mobile/app/src/main/java/com/smilegate/Easel/domain/repository/SendCodeRepository.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.smilegate.Easel.domain.repository | ||
|
||
import android.util.Log | ||
import androidx.lifecycle.MutableLiveData | ||
import com.smilegate.Easel.domain.api.ApiService | ||
import com.smilegate.Easel.domain.model.auth.EmailAuth | ||
import java.io.IOException | ||
|
||
class SendCodeRepository(private val apiService: ApiService) { | ||
private val _codeLiveData = MutableLiveData<String?>() | ||
private val codeLiveData: MutableLiveData<String?> = _codeLiveData | ||
|
||
suspend fun sendCode(email: String, payload: String) { | ||
val request = EmailAuth(email, payload) | ||
try { | ||
val response = apiService.sendCode(request) | ||
if (response.isSuccessful) { | ||
// 성공적인 응답 처리 | ||
val responseBody = response.body()?.string() | ||
if (responseBody != null) { | ||
codeLiveData.postValue(responseBody) | ||
} else { | ||
// 서버가 빈 응답을 반환한 경우 처리 | ||
} | ||
} else { | ||
// 실패한 응답 처리 | ||
val errorMessage = response.errorBody()?.string() | ||
if (!errorMessage.isNullOrEmpty()) { | ||
Log.e("SendCodeRepository", "Error: $errorMessage") | ||
} else { | ||
Log.e("SendCodeRepository", "Failed to send code. Response code: ${response.code()}") | ||
} | ||
} | ||
} catch (e: IOException) { | ||
Log.e("SendCodeRepository", "Network error: ${e.message}") | ||
} catch (e: Exception) { | ||
Log.e("SendCodeRepository", "Unexpected error: ${e.message}") | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/mobile/app/src/main/java/com/smilegate/Easel/domain/repository/UserRepository.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,12 @@ | ||
package com.smilegate.Easel.domain.repository | ||
|
||
import com.smilegate.Easel.domain.api.ApiService | ||
import com.smilegate.Easel.domain.model.auth.EmailRequest | ||
|
||
class UserRepository(private val apiService: ApiService) { | ||
suspend fun verifyEmail(email: String): Boolean { | ||
val request = EmailRequest(email) | ||
val response = apiService.verifyEmail(request) | ||
return response.isSuccessful && response.body()?.isDuplicated == false | ||
} | ||
} |
Oops, something went wrong.