From 97f5948656a14a7a339829c82011d6775950b15b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=AA=85=ED=9B=88?= Date: Mon, 25 Nov 2024 17:17:38 +0900 Subject: [PATCH] :recycle: :: Apply Before Commit(Add Expo_Id Response) --- .../data/repository/expo/ExpoRepository.kt | 3 ++- .../data/repository/expo/ExpoRepositoryImpl.kt | 7 +++++-- .../usecase/expo/RegisterExpoInformationUseCase.kt | 5 +++-- .../com/school_of_company/network/api/ExpoAPI.kt | 3 ++- .../network/datasource/expo/ExpoDataSource.kt | 3 ++- .../network/datasource/expo/ExpoDataSourceImpl.kt | 3 ++- .../expo/viewmodel/ExpoViewModel.kt | 14 ++++++-------- .../uistate/RegisterExpoInformationUiState.kt | 4 +++- 8 files changed, 25 insertions(+), 17 deletions(-) diff --git a/core/data/src/main/java/com/school_of_company/data/repository/expo/ExpoRepository.kt b/core/data/src/main/java/com/school_of_company/data/repository/expo/ExpoRepository.kt index e705665c..fd8579f1 100644 --- a/core/data/src/main/java/com/school_of_company/data/repository/expo/ExpoRepository.kt +++ b/core/data/src/main/java/com/school_of_company/data/repository/expo/ExpoRepository.kt @@ -1,5 +1,6 @@ package com.school_of_company.data.repository.expo +import com.school_of_company.model.entity.expo.ExpoIdResponseEntity import com.school_of_company.model.entity.expo.ExpoListResponseEntity import com.school_of_company.model.model.expo.ExpoRequestAndResponseModel import kotlinx.coroutines.flow.Flow @@ -7,7 +8,7 @@ import kotlinx.coroutines.flow.Flow interface ExpoRepository { fun getExpoList() : Flow> fun getExpoInformation(expoId: String) : Flow - fun registerExpoInformation(body: ExpoRequestAndResponseModel) : Flow + fun registerExpoInformation(body: ExpoRequestAndResponseModel) : Flow fun modifyExpoInformation(expoId: String, body: ExpoRequestAndResponseModel) : Flow fun deleteExpoInformation(expoId: String) : Flow } \ No newline at end of file diff --git a/core/data/src/main/java/com/school_of_company/data/repository/expo/ExpoRepositoryImpl.kt b/core/data/src/main/java/com/school_of_company/data/repository/expo/ExpoRepositoryImpl.kt index 3e730e08..5834a1c1 100644 --- a/core/data/src/main/java/com/school_of_company/data/repository/expo/ExpoRepositoryImpl.kt +++ b/core/data/src/main/java/com/school_of_company/data/repository/expo/ExpoRepositoryImpl.kt @@ -1,5 +1,6 @@ package com.school_of_company.data.repository.expo +import com.school_of_company.model.entity.expo.ExpoIdResponseEntity import com.school_of_company.model.entity.expo.ExpoListResponseEntity import com.school_of_company.model.model.expo.ExpoRequestAndResponseModel import com.school_of_company.network.datasource.expo.ExpoDataSource @@ -25,8 +26,10 @@ class ExpoRepositoryImpl @Inject constructor( } } - override fun registerExpoInformation(body: ExpoRequestAndResponseModel): Flow { - return dataSource.registerExpoInformation(body = body.toDto()) + override fun registerExpoInformation(body: ExpoRequestAndResponseModel): Flow { + return dataSource.registerExpoInformation(body = body.toDto()).transform { response -> + emit(response.toEntity()) + } } override fun modifyExpoInformation( diff --git a/core/domain/src/main/java/com/school_of_company/domain/usecase/expo/RegisterExpoInformationUseCase.kt b/core/domain/src/main/java/com/school_of_company/domain/usecase/expo/RegisterExpoInformationUseCase.kt index 9a259171..937765c1 100644 --- a/core/domain/src/main/java/com/school_of_company/domain/usecase/expo/RegisterExpoInformationUseCase.kt +++ b/core/domain/src/main/java/com/school_of_company/domain/usecase/expo/RegisterExpoInformationUseCase.kt @@ -1,13 +1,14 @@ package com.school_of_company.domain.usecase.expo import com.school_of_company.data.repository.expo.ExpoRepository +import com.school_of_company.model.entity.expo.ExpoIdResponseEntity import com.school_of_company.model.model.expo.ExpoRequestAndResponseModel +import kotlinx.coroutines.flow.Flow import javax.inject.Inject class RegisterExpoInformationUseCase @Inject constructor( private val repository: ExpoRepository ) { - operator fun invoke(body: ExpoRequestAndResponseModel) = runCatching { + operator fun invoke(body: ExpoRequestAndResponseModel): Flow = repository.registerExpoInformation(body = body) - } } \ No newline at end of file diff --git a/core/network/src/main/java/com/school_of_company/network/api/ExpoAPI.kt b/core/network/src/main/java/com/school_of_company/network/api/ExpoAPI.kt index 431295ff..66470e9b 100644 --- a/core/network/src/main/java/com/school_of_company/network/api/ExpoAPI.kt +++ b/core/network/src/main/java/com/school_of_company/network/api/ExpoAPI.kt @@ -1,6 +1,7 @@ package com.school_of_company.network.api import com.school_of_company.network.dto.expo.request_response.ExpoRequestAndResponse +import com.school_of_company.network.dto.expo.response.ExpoIdResponse import com.school_of_company.network.dto.expo.response.ExpoListResponse import retrofit2.http.* @@ -17,7 +18,7 @@ interface ExpoAPI { @POST("/expo") suspend fun registerExpoInformation( @Body body: ExpoRequestAndResponse - ) + ) : ExpoIdResponse @PATCH("/expo/{expo_id}") suspend fun modifyExpoInformation( diff --git a/core/network/src/main/java/com/school_of_company/network/datasource/expo/ExpoDataSource.kt b/core/network/src/main/java/com/school_of_company/network/datasource/expo/ExpoDataSource.kt index a0e96fe2..a5b580ac 100644 --- a/core/network/src/main/java/com/school_of_company/network/datasource/expo/ExpoDataSource.kt +++ b/core/network/src/main/java/com/school_of_company/network/datasource/expo/ExpoDataSource.kt @@ -1,13 +1,14 @@ package com.school_of_company.network.datasource.expo import com.school_of_company.network.dto.expo.request_response.ExpoRequestAndResponse +import com.school_of_company.network.dto.expo.response.ExpoIdResponse import com.school_of_company.network.dto.expo.response.ExpoListResponse import kotlinx.coroutines.flow.Flow interface ExpoDataSource { fun getExpoList() : Flow> fun getExpoInformation(expoId: String) : Flow - fun registerExpoInformation(body: ExpoRequestAndResponse) : Flow + fun registerExpoInformation(body: ExpoRequestAndResponse) : Flow fun modifyExpoInformation(expoId: String, body: ExpoRequestAndResponse) : Flow fun deleteExpoInformation(expoId: String) : Flow } \ No newline at end of file diff --git a/core/network/src/main/java/com/school_of_company/network/datasource/expo/ExpoDataSourceImpl.kt b/core/network/src/main/java/com/school_of_company/network/datasource/expo/ExpoDataSourceImpl.kt index 3e924c66..255a599f 100644 --- a/core/network/src/main/java/com/school_of_company/network/datasource/expo/ExpoDataSourceImpl.kt +++ b/core/network/src/main/java/com/school_of_company/network/datasource/expo/ExpoDataSourceImpl.kt @@ -2,6 +2,7 @@ package com.school_of_company.network.datasource.expo import com.school_of_company.network.api.ExpoAPI import com.school_of_company.network.dto.expo.request_response.ExpoRequestAndResponse +import com.school_of_company.network.dto.expo.response.ExpoIdResponse import com.school_of_company.network.dto.expo.response.ExpoListResponse import com.school_of_company.network.util.performApiRequest import kotlinx.coroutines.flow.Flow @@ -16,7 +17,7 @@ class ExpoDataSourceImpl @Inject constructor( override fun getExpoInformation(expoId: String): Flow = performApiRequest { service.getExpoInformation(expoId = expoId) } - override fun registerExpoInformation(body: ExpoRequestAndResponse): Flow = + override fun registerExpoInformation(body: ExpoRequestAndResponse): Flow = performApiRequest { service.registerExpoInformation(body = body) } override fun modifyExpoInformation(expoId: String, body: ExpoRequestAndResponse): Flow = diff --git a/feature/expo/src/main/java/com/school_of_company/expo/viewmodel/ExpoViewModel.kt b/feature/expo/src/main/java/com/school_of_company/expo/viewmodel/ExpoViewModel.kt index ca4bb237..d408db07 100644 --- a/feature/expo/src/main/java/com/school_of_company/expo/viewmodel/ExpoViewModel.kt +++ b/feature/expo/src/main/java/com/school_of_company/expo/viewmodel/ExpoViewModel.kt @@ -114,16 +114,14 @@ class ExpoViewModel @Inject constructor( internal fun registerExpoInformation(body: ExpoRequestAndResponseModel) = viewModelScope.launch { _registerExpoInformationUiState.value = RegisterExpoInformationUiState.Loading registerExpoInformationUseCase(body = body) - .onSuccess { - it.catch { remoteError -> - _registerExpoInformationUiState.value = RegisterExpoInformationUiState.Error(remoteError) - }.collect { - _registerExpoInformationUiState.value = RegisterExpoInformationUiState.Success + .asResult() + .collectLatest { result -> + when (result) { + Result.Loading -> _registerExpoInformationUiState.value = RegisterExpoInformationUiState.Loading + is Result.Success -> _registerExpoInformationUiState.value = RegisterExpoInformationUiState.Success(result.data) + is Result.Error -> _registerExpoInformationUiState.value = RegisterExpoInformationUiState.Error(result.exception) } } - .onFailure { error -> - _registerExpoInformationUiState.value = RegisterExpoInformationUiState.Error(error) - } } internal fun initRegisterExpo() { diff --git a/feature/expo/src/main/java/com/school_of_company/expo/viewmodel/uistate/RegisterExpoInformationUiState.kt b/feature/expo/src/main/java/com/school_of_company/expo/viewmodel/uistate/RegisterExpoInformationUiState.kt index c350695e..f0146094 100644 --- a/feature/expo/src/main/java/com/school_of_company/expo/viewmodel/uistate/RegisterExpoInformationUiState.kt +++ b/feature/expo/src/main/java/com/school_of_company/expo/viewmodel/uistate/RegisterExpoInformationUiState.kt @@ -1,7 +1,9 @@ package com.school_of_company.expo.viewmodel.uistate +import com.school_of_company.model.entity.expo.ExpoIdResponseEntity + sealed interface RegisterExpoInformationUiState { object Loading : RegisterExpoInformationUiState - object Success : RegisterExpoInformationUiState + data class Success(val data: ExpoIdResponseEntity): RegisterExpoInformationUiState data class Error(val exception: Throwable) : RegisterExpoInformationUiState } \ No newline at end of file