Skip to content

Commit

Permalink
[MERGE] #119 -> develop
Browse files Browse the repository at this point in the history
[FEAT/#119] λ§ˆμ΄νŽ˜μ΄μ§€ 정보 μ„œλ²„ν†΅μ‹  κ΅¬ν˜„
  • Loading branch information
leeeyubin authored Jul 17, 2024
2 parents 2effe98 + 118b69d commit 473f11e
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.terning.data.datasource

import com.terning.data.dto.BaseResponse
import com.terning.data.dto.NonDataBaseResponse
import com.terning.data.dto.response.MyPageResponseDto

interface MyPageDataSource {
suspend fun postLogout(): NonDataBaseResponse

suspend fun deleteQuit(): NonDataBaseResponse

suspend fun getProfile(): BaseResponse<MyPageResponseDto>
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.terning.data.datasourceimpl

import com.terning.data.datasource.MyPageDataSource
import com.terning.data.dto.BaseResponse
import com.terning.data.dto.NonDataBaseResponse
import com.terning.data.dto.response.MyPageResponseDto
import com.terning.data.service.MyPageService
import javax.inject.Inject

Expand All @@ -11,4 +13,6 @@ class MyPageDataSourceImpl @Inject constructor(
override suspend fun postLogout(): NonDataBaseResponse = myPageService.postLogout()

override suspend fun deleteQuit(): NonDataBaseResponse = myPageService.deleteQuit()

override suspend fun getProfile(): BaseResponse<MyPageResponseDto> = myPageService.getProfile()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.terning.data.dto.response

import com.terning.domain.entity.response.MyPageProfileModel
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class MyPageResponseDto(
@SerialName("name")
val name: String,
@SerialName("authType")
val authType: String
)

fun MyPageResponseDto.toMyPageProfileModel() = MyPageProfileModel(name = name, authType = authType)
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.terning.data.repositoryimpl

import com.terning.data.datasource.MyPageDataSource
import com.terning.data.dto.response.toMyPageProfileModel
import com.terning.domain.entity.response.MyPageProfileModel
import com.terning.domain.repository.MyPageRepository
import javax.inject.Inject

Expand All @@ -13,7 +15,12 @@ class MyPageRepositoryImpl @Inject constructor(
}

override suspend fun deleteQuit(): Result<Unit> =
runCatching{
runCatching {
myPageDataSource.deleteQuit()
}

override suspend fun getProfile(): Result<MyPageProfileModel> =
runCatching {
myPageDataSource.getProfile().result.toMyPageProfileModel()
}
}
6 changes: 6 additions & 0 deletions data/src/main/java/com/terning/data/service/MyPageService.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.terning.data.service

import com.terning.data.dto.BaseResponse
import com.terning.data.dto.NonDataBaseResponse
import com.terning.data.dto.response.MyPageResponseDto
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.POST

interface MyPageService {
Expand All @@ -10,4 +13,7 @@ interface MyPageService {

@DELETE("api/v1/auth/withdraw")
suspend fun deleteQuit(): NonDataBaseResponse

@GET("api/v1/mypage/profile")
suspend fun getProfile(): BaseResponse<MyPageResponseDto>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.terning.domain.entity.response

data class MyPageProfileModel(
val name: String,
val authType: String
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.terning.domain.repository

import com.terning.domain.entity.response.MyPageProfileModel

interface MyPageRepository {
suspend fun postLogout() : Result<Unit>
suspend fun postLogout(): Result<Unit>

suspend fun deleteQuit(): Result<Unit>

suspend fun deleteQuit() : Result<Unit>
suspend fun getProfile(): Result<MyPageProfileModel>
}
26 changes: 22 additions & 4 deletions feature/src/main/java/com/terning/feature/mypage/MyPageRoute.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ fun MyPageRoute(
var showLogoutBottomSheet by remember { mutableStateOf(false) }
var showQuitBottomSheet by remember { mutableStateOf(false) }

var name by remember { mutableStateOf(state.name) }
var authType by remember { mutableStateOf(state.authType) }

if (showLogoutBottomSheet) {
MyPageLogoutBottomSheet(
onDismiss = { showLogoutBottomSheet = false },
Expand All @@ -64,7 +67,7 @@ fun MyPageRoute(
)
}

when (state.isSuccess) {
when (state.isLogoutAndQuitSuccess) {
is UiState.Success -> {
viewModel.restartApp(context)
}
Expand All @@ -74,16 +77,31 @@ fun MyPageRoute(
is UiState.Failure -> {}
}

when (state.isGetSuccess) {
is UiState.Success -> {
name = state.name
authType = state.authType
}

is UiState.Loading -> {}
is UiState.Empty -> {}
is UiState.Failure -> {}
}

MyPageScreen(
onLogoutClick = { showLogoutBottomSheet = true },
onQuitClick = { showQuitBottomSheet = true }
onQuitClick = { showQuitBottomSheet = true },
name = name,
authType = authType
)
}

@Composable
fun MyPageScreen(
onLogoutClick: () -> Unit,
onQuitClick: () -> Unit
onQuitClick: () -> Unit,
name: String = "",
authType: String = ""
) {
Scaffold(
modifier = Modifier,
Expand All @@ -96,7 +114,7 @@ fun MyPageScreen(
modifier = Modifier.padding(top = paddingValues.calculateTopPadding())
) {
Text(
text = stringResource(id = R.string.my_page_name, "λ‚¨μ§€μš°"),
text = stringResource(id = R.string.my_page_name, name),
modifier = Modifier.padding(
top = 21.dp,
start = 24.dp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ package com.terning.feature.mypage
import com.terning.core.state.UiState

data class MyPageState(
val isSuccess: UiState<Boolean> = UiState.Loading
val isLogoutAndQuitSuccess: UiState<Boolean> = UiState.Loading,
val isGetSuccess : UiState<Boolean> = UiState.Loading,
val name: String = "",
val authType: String = ""
)
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class MyPageViewModel @Inject constructor(
private val tokenRepository: TokenRepository
) : ViewModel() {

init {
getProfile()
}

private val _state: MutableStateFlow<MyPageState> = MutableStateFlow(MyPageState())
val state: StateFlow<MyPageState> get() = _state.asStateFlow()

Expand All @@ -33,7 +37,8 @@ class MyPageViewModel @Inject constructor(
if (error == null) {
postLogout()
} else {
_state.value = _state.value.copy(isSuccess = UiState.Failure(error.toString()))
_state.value =
_state.value.copy(isLogoutAndQuitSuccess = UiState.Failure(error.toString()))
}
}
}
Expand All @@ -42,9 +47,10 @@ class MyPageViewModel @Inject constructor(
viewModelScope.launch {
myPageRepository.postLogout().onSuccess {
tokenRepository.clearInfo()
_state.value = _state.value.copy(isSuccess = UiState.Success(true))
_state.value = _state.value.copy(isLogoutAndQuitSuccess = UiState.Success(true))
}.onFailure {
_state.value = _state.value.copy(isSuccess = UiState.Failure(it.toString()))
_state.value =
_state.value.copy(isLogoutAndQuitSuccess = UiState.Failure(it.toString()))
}
}
}
Expand All @@ -65,7 +71,8 @@ class MyPageViewModel @Inject constructor(
if (error == null) {
deleteQuit()
} else {
_state.value = _state.value.copy(isSuccess = UiState.Failure(error.toString()))
_state.value =
_state.value.copy(isLogoutAndQuitSuccess = UiState.Failure(error.toString()))
}
}
}
Expand All @@ -74,10 +81,26 @@ class MyPageViewModel @Inject constructor(
viewModelScope.launch {
myPageRepository.deleteQuit().onSuccess {
tokenRepository.clearInfo()
_state.value = _state.value.copy(isSuccess = UiState.Success(true))
_state.value = _state.value.copy(isLogoutAndQuitSuccess = UiState.Success(true))
}.onFailure {
_state.value =
_state.value.copy(isLogoutAndQuitSuccess = UiState.Failure(it.toString()))
}
}
}

private fun getProfile() {
viewModelScope.launch {
myPageRepository.getProfile().onSuccess { response ->
_state.value = _state.value.copy(
isGetSuccess = UiState.Success(true),
name = response.name,
authType = response.authType
)
}.onFailure {
_state.value = _state.value.copy(isSuccess = UiState.Failure(it.toString()))
_state.value = _state.value.copy(isGetSuccess = UiState.Failure(it.toString()))
}
}
}

}

0 comments on commit 473f11e

Please sign in to comment.