This repository has been archived by the owner on Oct 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
πͺ μΉ΄μΉ΄μ€ λ° μλ² νμνν΄ κΈ°λ₯ ꡬν (#82)
* [feat] homeνλ©΄ κ°λ μ νν λ μ§ μ΄κΈ°ν * [feat] Home νλ©΄ μΌκΈ°κ° μμ μ λ μ΄μμ μμ * [style] signIn, mypage μμ μμ * [feat] νμ νν΄ κΈ°λ₯ μμ * [style] home νλ©΄ μμ * [feat] splash νλ©΄ μμ± * [feat] Splash νλ©΄ μ¬μ€μ * [feat] νμνν΄ μ dataStore μμ
- Loading branch information
1 parent
a117758
commit 5e6733b
Showing
21 changed files
with
326 additions
and
41 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
9 changes: 9 additions & 0 deletions
9
Nabi/data/src/main/java/com/nabi/data/model/auth/WithdrawResponseDTO.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,9 @@ | ||
package com.nabi.data.model.auth | ||
|
||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class WithdrawResponseDTO( | ||
@SerializedName("message") | ||
val 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
10 changes: 10 additions & 0 deletions
10
Nabi/domain/src/main/java/com/nabi/domain/usecase/auth/WithdrawUseCase.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,10 @@ | ||
package com.nabi.domain.usecase.auth | ||
|
||
import com.nabi.domain.repository.AuthRepository | ||
|
||
class WithdrawUseCase(private val repository: AuthRepository) { | ||
|
||
suspend operator fun invoke(accessToken: String): Result<String> { | ||
return repository.withdraw("Bearer $accessToken") | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
Nabi/domain/src/main/java/com/nabi/domain/usecase/datastore/ClearUserDataUseCase.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.nabi.domain.usecase.datastore | ||
|
||
import com.nabi.domain.model.auth.NicknameInfo | ||
import com.nabi.domain.repository.AuthRepository | ||
import com.nabi.domain.repository.DataStoreRepository | ||
|
||
class ClearUserDataUseCase(private val repository: DataStoreRepository) { | ||
|
||
suspend operator fun invoke(): Result<Boolean> { | ||
return repository.clearUserData() | ||
} | ||
} |
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
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
71 changes: 71 additions & 0 deletions
71
Nabi/presentation/src/main/java/com/nabi/nabi/views/myPage/MyPageViewModel.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,71 @@ | ||
package com.nabi.nabi.views.myPage | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.nabi.domain.usecase.auth.WithdrawUseCase | ||
import com.nabi.domain.usecase.datastore.ClearUserDataUseCase | ||
import com.nabi.domain.usecase.datastore.GetAccessTokenUseCase | ||
import com.nabi.nabi.utils.LoggerUtils | ||
import com.nabi.nabi.utils.UiState | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class MyPageViewModel @Inject constructor( | ||
private val withdrawUseCase: WithdrawUseCase, | ||
private val clearUserDataUseCase: ClearUserDataUseCase, | ||
private val getAccessTokenUseCase: GetAccessTokenUseCase | ||
) : ViewModel() { | ||
|
||
private val _withdrawState = MutableLiveData<UiState<String>>(UiState.Loading) | ||
val withdrawState: LiveData<UiState<String>> get() = _withdrawState | ||
|
||
private val _clearState = MutableLiveData<UiState<Boolean>>(UiState.Loading) | ||
val clearState: LiveData<UiState<Boolean>> get() = _clearState | ||
|
||
|
||
fun withdraw() { | ||
_withdrawState.value = UiState.Loading | ||
|
||
viewModelScope.launch { | ||
val accessToken = getAccessTokenUseCase.invoke().getOrNull().orEmpty() | ||
|
||
try { | ||
withdrawUseCase(accessToken) | ||
.onSuccess { | ||
_withdrawState.value = UiState.Success(it) | ||
} | ||
.onFailure { e -> | ||
LoggerUtils.e("Withdraw failed: ${e.message}") | ||
_withdrawState.value = UiState.Failure(message = e.message.toString()) | ||
} | ||
} catch (e: Exception) { | ||
LoggerUtils.e("Withdraw exception: ${e.message}") | ||
_withdrawState.value = UiState.Failure(message = e.message.toString()) | ||
} | ||
} | ||
} | ||
|
||
fun clearData() { | ||
_clearState.value = UiState.Loading | ||
|
||
viewModelScope.launch { | ||
try { | ||
clearUserDataUseCase() | ||
.onSuccess { | ||
_clearState.value = UiState.Success(it) | ||
} | ||
.onFailure { e -> | ||
LoggerUtils.e("Clear User Data failed: ${e.message}") | ||
_clearState.value = UiState.Failure(message = e.message.toString()) | ||
} | ||
} catch (e: Exception) { | ||
LoggerUtils.e("Clear User Data: ${e.message}") | ||
_clearState.value = UiState.Failure(message = e.message.toString()) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.