Skip to content

Commit

Permalink
[feat] #23 feat : 회원 탈퇴 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
plashdof committed Oct 4, 2024
1 parent 549daa8 commit 8b2317e
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.masshow.data.model.request

data class UserSimpleInfoQuery(
val userId: Long,
val nickname: String
)
8 changes: 8 additions & 0 deletions data/src/main/java/com/masshow/data/remote/AuthApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package com.masshow.data.remote

import com.masshow.data.model.request.LoginRequest
import com.masshow.data.model.request.SignupRequest
import com.masshow.data.model.request.UserSimpleInfoQuery
import com.masshow.data.model.response.BaseResponse
import com.masshow.data.model.response.LoginResponse
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.POST
import retrofit2.http.Query

interface AuthApi {

Expand All @@ -19,4 +22,9 @@ interface AuthApi {
suspend fun signup(
@Body body: SignupRequest
): Response<BaseResponse<LoginResponse>>

@DELETE("/user/account")
suspend fun withdrawal(
@Query("userSimpleInfo") userSimpleInfo : UserSimpleInfoQuery
): Response<BaseResponse<Unit>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.masshow.data.repository
import com.masshow.data.model.BaseState
import com.masshow.data.model.request.LoginRequest
import com.masshow.data.model.request.SignupRequest
import com.masshow.data.model.request.UserSimpleInfoQuery
import com.masshow.data.model.response.LoginResponse

interface AuthRepository {
Expand All @@ -15,6 +16,10 @@ interface AuthRepository {
body: SignupRequest
): BaseState<LoginResponse?>

suspend fun withdrawal(
query: UserSimpleInfoQuery
): BaseState<Unit?>

suspend fun getAccessToken(): String?
suspend fun getRefreshToken(): String?
suspend fun getUserId(): Long?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.masshow.data.Constants
import com.masshow.data.model.BaseState
import com.masshow.data.model.request.LoginRequest
import com.masshow.data.model.request.SignupRequest
import com.masshow.data.model.request.UserSimpleInfoQuery
import com.masshow.data.model.response.LoginResponse
import com.masshow.data.model.runRemote
import com.masshow.data.remote.AuthApi
Expand Down Expand Up @@ -38,6 +39,10 @@ class AuthRepositoryImpl @Inject constructor(
api.signup(body)
}

override suspend fun withdrawal(query: UserSimpleInfoQuery): BaseState<Unit?> = runRemote {
api.withdrawal(query)
}

override suspend fun getAccessToken(): String? {
return dataStore.data.map { prefs ->
prefs[ACCESS_TOKEN_KEY]
Expand Down Expand Up @@ -111,7 +116,7 @@ class AuthRepositoryImpl @Inject constructor(
}

override suspend fun clear() {
dataStore.edit{ prefs ->
dataStore.edit { prefs ->
prefs.clear()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.masshow.presentation.ui.main.mypage

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.masshow.data.model.BaseState
import com.masshow.data.model.request.UserSimpleInfoQuery
import com.masshow.data.repository.AuthRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableSharedFlow
Expand Down Expand Up @@ -33,7 +35,24 @@ class MyPageViewModel @Inject constructor(
}

fun withdrawal() {

viewModelScope.launch {
authRepository.getUserId()?.let { id ->
authRepository.getNick()?.let { nick ->
authRepository.withdrawal(UserSimpleInfoQuery(id, nick)).let {
when (it) {
is BaseState.Success -> {
_event.emit(MyPageEvent.ShowToastMessage("회원 탈퇴 성공"))
_event.emit(MyPageEvent.NavigateToLogin)
}

is BaseState.Error -> {
_event.emit(MyPageEvent.ShowToastMessage(it.message))
}
}
}
}
}
}
}

fun navigateToBack() {
Expand Down

0 comments on commit 8b2317e

Please sign in to comment.