Skip to content

Commit

Permalink
♻️ :: Apply Before Commit(Add Expo_Id Response)
Browse files Browse the repository at this point in the history
  • Loading branch information
audgns10 committed Nov 25, 2024
1 parent a63a495 commit 97f5948
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
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

interface ExpoRepository {
fun getExpoList() : Flow<List<ExpoListResponseEntity>>
fun getExpoInformation(expoId: String) : Flow<ExpoRequestAndResponseModel>
fun registerExpoInformation(body: ExpoRequestAndResponseModel) : Flow<Unit>
fun registerExpoInformation(body: ExpoRequestAndResponseModel) : Flow<ExpoIdResponseEntity>
fun modifyExpoInformation(expoId: String, body: ExpoRequestAndResponseModel) : Flow<Unit>
fun deleteExpoInformation(expoId: String) : Flow<Unit>
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -25,8 +26,10 @@ class ExpoRepositoryImpl @Inject constructor(
}
}

override fun registerExpoInformation(body: ExpoRequestAndResponseModel): Flow<Unit> {
return dataSource.registerExpoInformation(body = body.toDto())
override fun registerExpoInformation(body: ExpoRequestAndResponseModel): Flow<ExpoIdResponseEntity> {
return dataSource.registerExpoInformation(body = body.toDto()).transform { response ->
emit(response.toEntity())
}
}

override fun modifyExpoInformation(
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ExpoIdResponseEntity> =
repository.registerExpoInformation(body = body)
}
}
Original file line number Diff line number Diff line change
@@ -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.*

Expand All @@ -17,7 +18,7 @@ interface ExpoAPI {
@POST("/expo")
suspend fun registerExpoInformation(
@Body body: ExpoRequestAndResponse
)
) : ExpoIdResponse

@PATCH("/expo/{expo_id}")
suspend fun modifyExpoInformation(
Expand Down
Original file line number Diff line number Diff line change
@@ -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<List<ExpoListResponse>>
fun getExpoInformation(expoId: String) : Flow<ExpoRequestAndResponse>
fun registerExpoInformation(body: ExpoRequestAndResponse) : Flow<Unit>
fun registerExpoInformation(body: ExpoRequestAndResponse) : Flow<ExpoIdResponse>
fun modifyExpoInformation(expoId: String, body: ExpoRequestAndResponse) : Flow<Unit>
fun deleteExpoInformation(expoId: String) : Flow<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,7 +17,7 @@ class ExpoDataSourceImpl @Inject constructor(
override fun getExpoInformation(expoId: String): Flow<ExpoRequestAndResponse> =
performApiRequest { service.getExpoInformation(expoId = expoId) }

override fun registerExpoInformation(body: ExpoRequestAndResponse): Flow<Unit> =
override fun registerExpoInformation(body: ExpoRequestAndResponse): Flow<ExpoIdResponse> =
performApiRequest { service.registerExpoInformation(body = body) }

override fun modifyExpoInformation(expoId: String, body: ExpoRequestAndResponse): Flow<Unit> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 97f5948

Please sign in to comment.