diff --git a/frontend/app/src/main/java/com/example/speechbuddy/data/local/SymbolDao.kt b/frontend/app/src/main/java/com/example/speechbuddy/data/local/SymbolDao.kt index 130f118c..7dfd13a5 100644 --- a/frontend/app/src/main/java/com/example/speechbuddy/data/local/SymbolDao.kt +++ b/frontend/app/src/main/java/com/example/speechbuddy/data/local/SymbolDao.kt @@ -47,6 +47,9 @@ interface SymbolDao { @Upsert suspend fun upsertAll(symbolEntities: List) - @Query("DELETE FROM symbols") - suspend fun deleteAllSymbols() + @Query("DELETE FROM symbols WHERE isMine = 1") + suspend fun deleteAllMySymbols() + + @Query("UPDATE symbols SET isFavorite = 0 WHERE isFavorite = 1") + suspend fun resetFavoriteSymbols() } \ No newline at end of file diff --git a/frontend/app/src/main/java/com/example/speechbuddy/data/local/UserDao.kt b/frontend/app/src/main/java/com/example/speechbuddy/data/local/UserDao.kt index 36c664e5..d80a7ff1 100644 --- a/frontend/app/src/main/java/com/example/speechbuddy/data/local/UserDao.kt +++ b/frontend/app/src/main/java/com/example/speechbuddy/data/local/UserDao.kt @@ -24,4 +24,7 @@ interface UserDao { @Query("DELETE FROM users WHERE id = :id") suspend fun deleteUserById(id: Int) + + @Query("DELETE FROM users") + suspend fun deleteUserInfo() } \ No newline at end of file diff --git a/frontend/app/src/main/java/com/example/speechbuddy/data/local/WeightRowDao.kt b/frontend/app/src/main/java/com/example/speechbuddy/data/local/WeightRowDao.kt index 042be11d..2e0b8eba 100644 --- a/frontend/app/src/main/java/com/example/speechbuddy/data/local/WeightRowDao.kt +++ b/frontend/app/src/main/java/com/example/speechbuddy/data/local/WeightRowDao.kt @@ -21,7 +21,9 @@ interface WeightRowDao { @Upsert suspend fun upsertAll(weightRowEntities: List) - @Query("DELETE FROM weighttable") - suspend fun deleteAllWeightRows() + @Query("DELETE FROM weighttable WHERE id > 500") + suspend fun deleteMySymbolsWeightRows() + @Query("UPDATE weighttable SET weights = :resetWeights WHERE id < 501") + suspend fun resetOriginalSymbolsWeightRows(resetWeights: List) } diff --git a/frontend/app/src/main/java/com/example/speechbuddy/domain/SessionManager.kt b/frontend/app/src/main/java/com/example/speechbuddy/domain/SessionManager.kt index 63c6ea26..cd6facce 100644 --- a/frontend/app/src/main/java/com/example/speechbuddy/domain/SessionManager.kt +++ b/frontend/app/src/main/java/com/example/speechbuddy/domain/SessionManager.kt @@ -48,7 +48,7 @@ class SessionManager { } } - fun logout() { + fun deleteToken() { CoroutineScope(Dispatchers.Main).launch { _cachedToken.value = null _userId.value = null diff --git a/frontend/app/src/main/java/com/example/speechbuddy/repository/AuthRepository.kt b/frontend/app/src/main/java/com/example/speechbuddy/repository/AuthRepository.kt index 1fa99578..2cda5ca1 100644 --- a/frontend/app/src/main/java/com/example/speechbuddy/repository/AuthRepository.kt +++ b/frontend/app/src/main/java/com/example/speechbuddy/repository/AuthRepository.kt @@ -17,12 +17,9 @@ import com.example.speechbuddy.service.AuthService import com.example.speechbuddy.utils.Resource import com.example.speechbuddy.utils.ResponseCode import com.example.speechbuddy.utils.ResponseHandler -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.map -import kotlinx.coroutines.launch import retrofit2.Response import javax.inject.Inject import javax.inject.Singleton @@ -141,9 +138,6 @@ class AuthRepository @Inject constructor( val refreshToken = sessionManager.cachedToken.value!!.refreshToken!! val result = authService.logout(getAuthHeader(), AuthRefreshRequest(refreshToken)) - CoroutineScope(Dispatchers.IO).launch { - authTokenPrefsManager.clearAuthToken() - } emit(result) } catch (e: Exception) { emit(responseHandler.getConnectionErrorResponse()) @@ -156,9 +150,6 @@ class AuthRepository @Inject constructor( val refreshToken = sessionManager.cachedToken.value!!.refreshToken!! val result = authService.withdraw(getAuthHeader(), AuthRefreshRequest(refreshToken)) - CoroutineScope(Dispatchers.IO).launch { - authTokenPrefsManager.clearAuthToken() - } emit(result) } catch (e: Exception) { emit(responseHandler.getConnectionErrorResponse()) diff --git a/frontend/app/src/main/java/com/example/speechbuddy/repository/SettingsRepository.kt b/frontend/app/src/main/java/com/example/speechbuddy/repository/SettingsRepository.kt index 0935e4db..f71557d6 100644 --- a/frontend/app/src/main/java/com/example/speechbuddy/repository/SettingsRepository.kt +++ b/frontend/app/src/main/java/com/example/speechbuddy/repository/SettingsRepository.kt @@ -83,6 +83,10 @@ class SettingsRepository @Inject constructor( } } + suspend fun resetSettings() { + settingsPrefManager.resetSettings() + } + suspend fun displayBackup(): Flow> = flow { try { diff --git a/frontend/app/src/main/java/com/example/speechbuddy/repository/SymbolRepository.kt b/frontend/app/src/main/java/com/example/speechbuddy/repository/SymbolRepository.kt index e18d1d7d..5875d005 100644 --- a/frontend/app/src/main/java/com/example/speechbuddy/repository/SymbolRepository.kt +++ b/frontend/app/src/main/java/com/example/speechbuddy/repository/SymbolRepository.kt @@ -110,8 +110,12 @@ class SymbolRepository @Inject constructor( fun getNextSymbolId() = symbolDao.getLastSymbol().map { symbol -> symbol.id +1 } - fun clearAllMySymbols() { - /* TODO: 내가 만든 상징들 모두 삭제 */ + suspend fun clearAllMySymbols() { + symbolDao.deleteAllMySymbols() + } + + suspend fun resetFavoriteSymbols() { + symbolDao.resetFavoriteSymbols() } suspend fun insertSymbol(symbol: Symbol) { diff --git a/frontend/app/src/main/java/com/example/speechbuddy/repository/UserRepository.kt b/frontend/app/src/main/java/com/example/speechbuddy/repository/UserRepository.kt index c57ed0d7..13354fae 100644 --- a/frontend/app/src/main/java/com/example/speechbuddy/repository/UserRepository.kt +++ b/frontend/app/src/main/java/com/example/speechbuddy/repository/UserRepository.kt @@ -51,6 +51,10 @@ class UserRepository @Inject constructor( } } + suspend fun deleteUserInfo() { + userDao.deleteUserInfo() + } + private fun returnUnknownError(): Resource { return Resource.error( "Unknown error", null diff --git a/frontend/app/src/main/java/com/example/speechbuddy/repository/WeightTableRepository.kt b/frontend/app/src/main/java/com/example/speechbuddy/repository/WeightTableRepository.kt index 93fc6417..d3997d3b 100644 --- a/frontend/app/src/main/java/com/example/speechbuddy/repository/WeightTableRepository.kt +++ b/frontend/app/src/main/java/com/example/speechbuddy/repository/WeightTableRepository.kt @@ -46,8 +46,9 @@ class WeightTableRepository @Inject constructor( } } - suspend fun deleteAllWeightRows() { - weightRowDao.deleteAllWeightRows() + suspend fun resetAllWeightRows() { + weightRowDao.deleteMySymbolsWeightRows() + weightRowDao.resetOriginalSymbolsWeightRows(List(500) { 0 }) } suspend fun getBackupWeightTableRequest(): BackupWeightTableRequest { diff --git a/frontend/app/src/main/java/com/example/speechbuddy/viewmodel/AccountSettingsViewModel.kt b/frontend/app/src/main/java/com/example/speechbuddy/viewmodel/AccountSettingsViewModel.kt index 1fb80024..64c9211f 100644 --- a/frontend/app/src/main/java/com/example/speechbuddy/viewmodel/AccountSettingsViewModel.kt +++ b/frontend/app/src/main/java/com/example/speechbuddy/viewmodel/AccountSettingsViewModel.kt @@ -4,10 +4,13 @@ import android.os.Build import androidx.annotation.RequiresApi import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.example.speechbuddy.data.local.AuthTokenPrefsManager import com.example.speechbuddy.domain.SessionManager import com.example.speechbuddy.repository.AuthRepository import com.example.speechbuddy.repository.SettingsRepository +import com.example.speechbuddy.repository.SymbolRepository import com.example.speechbuddy.repository.UserRepository +import com.example.speechbuddy.repository.WeightTableRepository import com.example.speechbuddy.ui.models.AccountSettingsAlert import com.example.speechbuddy.ui.models.AccountSettingsUiState import com.example.speechbuddy.utils.ResponseCode @@ -25,8 +28,11 @@ import javax.inject.Inject class AccountSettingsViewModel @Inject internal constructor( private val authRepository: AuthRepository, private val settingsRepository: SettingsRepository, + private val weightTableRepository: WeightTableRepository, + private val symbolRepository: SymbolRepository, private val userRepository: UserRepository, - private val sessionManager: SessionManager + private val sessionManager: SessionManager, + private val authTokenPrefsManager: AuthTokenPrefsManager ) : ViewModel() { private val _uiState = MutableStateFlow(AccountSettingsUiState()) @@ -68,8 +74,13 @@ class AccountSettingsViewModel @Inject internal constructor( authRepository.logout().collect { result -> when (result.code()) { ResponseCode.SUCCESS.value -> { - /* TODO: 디바이스에 저장돼 있는 유저 정보 초기화(토큰 말고) */ - sessionManager.logout() + settingsRepository.resetSettings() + weightTableRepository.resetAllWeightRows() + symbolRepository.clearAllMySymbols() + symbolRepository.resetFavoriteSymbols() + userRepository.deleteUserInfo() + sessionManager.deleteToken() + authTokenPrefsManager.clearAuthToken() hideAlert() } @@ -87,8 +98,13 @@ class AccountSettingsViewModel @Inject internal constructor( authRepository.withdraw().collect { result -> when (result.code()) { ResponseCode.SUCCESS.value -> { - /* TODO: 디바이스에 저장돼 있는 유저 정보 초기화(토큰 말고) */ - sessionManager.logout() + settingsRepository.resetSettings() + weightTableRepository.resetAllWeightRows() + symbolRepository.clearAllMySymbols() + symbolRepository.resetFavoriteSymbols() + userRepository.deleteUserInfo() + sessionManager.deleteToken() + authTokenPrefsManager.clearAuthToken() hideAlert() } diff --git a/frontend/app/src/main/java/com/example/speechbuddy/viewmodel/ResetPasswordViewModel.kt b/frontend/app/src/main/java/com/example/speechbuddy/viewmodel/ResetPasswordViewModel.kt index 0b53e6d8..7985dd6f 100644 --- a/frontend/app/src/main/java/com/example/speechbuddy/viewmodel/ResetPasswordViewModel.kt +++ b/frontend/app/src/main/java/com/example/speechbuddy/viewmodel/ResetPasswordViewModel.kt @@ -107,7 +107,7 @@ class ResetPasswordViewModel @Inject internal constructor( ).collect { result -> when (result.code()) { ResponseCode.SUCCESS.value -> { - sessionManager.logout() + sessionManager.deleteToken() onSuccess() }