Skip to content

Commit

Permalink
πŸ”— :: (#402) λ””λ°”μ΄μŠ€ 토큰 μ‚­μ œ api μΆ”κ°€
Browse files Browse the repository at this point in the history
  • Loading branch information
parkuiery authored Oct 26, 2024
2 parents 02ba52d + 7e449d8 commit 08d04cc
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface UserRepository {

fun getRefreshExpiresAt(): String

fun signOut()
suspend fun signOut()

suspend fun saveDeviceToken(deviceToken: String)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class UserRepositoryImpl @Inject constructor(
return localUserDataSource.getRefreshExpiresAt()
}

override fun signOut() {
override suspend fun signOut() {
remoteUserDataSource.deleteDeviceToken()
localUserDataSource.clearUserInformation()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import javax.inject.Inject
class SignOutUseCase @Inject constructor(
private val userRepository: UserRepository,
) {
operator fun invoke() = runCatching {
suspend operator fun invoke() = runCatching {
userRepository.signOut()
}
}
4 changes: 4 additions & 0 deletions core/network/src/main/java/team/retum/network/api/UserApi.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package team.retum.network.api

import retrofit2.http.Body
import retrofit2.http.PATCH
import retrofit2.http.POST
import team.retum.network.di.RequestUrls
import team.retum.network.model.request.user.SignInRequest
Expand All @@ -11,4 +12,7 @@ interface UserApi {
suspend fun signIn(
@Body signInRequest: SignInRequest,
): TokenResponse

@PATCH(RequestUrls.Users.deviceToken)
suspend fun deleteDeviceToken()
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ import team.retum.network.model.response.TokenResponse

interface RemoteUserDataSource {
suspend fun signIn(signInRequest: SignInRequest): TokenResponse

suspend fun deleteDeviceToken()
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@ class RemoteUserDataSourceImpl @Inject constructor(
userApi.signIn(signInRequest = signInRequest)
}
}

override suspend fun deleteDeviceToken() {
return RequestHandler<Unit>().request {
userApi.deleteDeviceToken()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ internal object RequestUrls {

const val login = "$path/login"
const val token = "$path/token"
const val deviceToken = "$path/device-token"
}

data object Auth {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ internal fun MyPage(
navigateToLanding()
}

is MyPageSideEffect.FailSignOut -> {
JobisToast.create(
context = context,
message = context.getString(R.string.toast_fail_sign_out),
drawable = JobisIcon.Error,
).show()
}

is MyPageSideEffect.BadEditProfileImage -> {
JobisToast.create(
context = context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,12 @@ internal class MyPageViewModel @Inject constructor(
}

internal fun onSignOutClick() {
signOutUseCase().onSuccess {
postSideEffect(MyPageSideEffect.SuccessSignOut)
viewModelScope.launch(Dispatchers.IO) {
signOutUseCase().onSuccess {
postSideEffect(MyPageSideEffect.SuccessSignOut)
}.onFailure {
postSideEffect(MyPageSideEffect.FailSignOut)
}
}
}

Expand Down Expand Up @@ -137,6 +141,7 @@ internal data class MyPageState(

internal sealed interface MyPageSideEffect {
data object SuccessSignOut : MyPageSideEffect
data object FailSignOut : MyPageSideEffect
data object SuccessEditProfileImage : MyPageSideEffect
data object BadEditProfileImage : MyPageSideEffect
}
1 change: 1 addition & 0 deletions feature/mypage/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<string name="modal_button_withdrawal">νšŒμ›νƒˆν‡΄</string>
<string name="toast_update_later">μΆ”ν›„ μ—…λ°μ΄νŠΈ 될 μ˜ˆμ •μ΄μ—μš”</string>

<string name="toast_fail_sign_out">λ‘œκ·Έμ•„μ›ƒ 처리 쀑 λ¬Έμ œκ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€</string>
<string name="toast_bad_request_edit_image">잘λͺ»λœ μš”μ²­μ΄μ—μš”</string>
<string name="toast_success_edit_profile_image">ν”„λ‘œν•„μ΄ μ„±κ³΅μ μœΌλ‘œ μ—…λ°μ΄νŠΈ λ˜μ—ˆμ–΄μš”</string>
</resources>

0 comments on commit 08d04cc

Please sign in to comment.