diff --git a/data/src/main/java/kr/genti/data/dataSource/GenerateDataSource.kt b/data/src/main/java/kr/genti/data/dataSource/GenerateDataSource.kt index 75d1089f..aab6e40f 100644 --- a/data/src/main/java/kr/genti/data/dataSource/GenerateDataSource.kt +++ b/data/src/main/java/kr/genti/data/dataSource/GenerateDataSource.kt @@ -17,5 +17,12 @@ interface GenerateDataSource { suspend fun postGenerateReport(request: ReportRequestDto): BaseResponse - suspend fun postResetState(id: Int): BaseResponse + suspend fun postGenerateRate( + responseId: Int, + star: Int, + ): BaseResponse + + suspend fun postVerifyGenerateState(responseId: Int): BaseResponse + + suspend fun getCanceledToReset(requestId: String): BaseResponse } diff --git a/data/src/main/java/kr/genti/data/dataSourceImpl/GenerateDataSourceImpl.kt b/data/src/main/java/kr/genti/data/dataSourceImpl/GenerateDataSourceImpl.kt index 13d37af5..3f036488 100644 --- a/data/src/main/java/kr/genti/data/dataSourceImpl/GenerateDataSourceImpl.kt +++ b/data/src/main/java/kr/genti/data/dataSourceImpl/GenerateDataSourceImpl.kt @@ -25,5 +25,13 @@ data class GenerateDataSourceImpl override suspend fun postGenerateReport(request: ReportRequestDto): BaseResponse = generateService.postGenerateReport(request) - override suspend fun postResetState(id: Int): BaseResponse = generateService.postResetState(id) + override suspend fun postGenerateRate( + responseId: Int, + star: Int, + ): BaseResponse = generateService.postGenerateRate(responseId, star) + + override suspend fun postVerifyGenerateState(responseId: Int): BaseResponse = + generateService.postVerifyGenerateState(responseId) + + override suspend fun getCanceledToReset(requestId: String): BaseResponse = generateService.getCanceledToReset(requestId) } diff --git a/data/src/main/java/kr/genti/data/dto/response/GenerateStatusDto.kt b/data/src/main/java/kr/genti/data/dto/response/GenerateStatusDto.kt index a94466a9..04abf79c 100644 --- a/data/src/main/java/kr/genti/data/dto/response/GenerateStatusDto.kt +++ b/data/src/main/java/kr/genti/data/dto/response/GenerateStatusDto.kt @@ -8,7 +8,7 @@ import kr.genti.domain.enums.GenerateStatus @Serializable data class GenerateStatusDto( @SerialName("pictureGenerateRequestId") - val pictureGenerateRequestId: Long, + val pictureGenerateRequestId: Long?, @SerialName("status") val status: GenerateStatus, @SerialName("pictureGenerateResponse") diff --git a/data/src/main/java/kr/genti/data/repositoryImpl/GenerateRepositoryImpl.kt b/data/src/main/java/kr/genti/data/repositoryImpl/GenerateRepositoryImpl.kt index e641bef2..9c074a38 100644 --- a/data/src/main/java/kr/genti/data/repositoryImpl/GenerateRepositoryImpl.kt +++ b/data/src/main/java/kr/genti/data/repositoryImpl/GenerateRepositoryImpl.kt @@ -38,8 +38,21 @@ class GenerateRepositoryImpl generateDataSource.postGenerateReport(request.toDto()).response } - override suspend fun postResetState(id: Int): Result = + override suspend fun postGenerateRate( + responseId: Int, + star: Int, + ): Result = runCatching { - generateDataSource.postResetState(id).response + generateDataSource.postGenerateRate(responseId, star).response + } + + override suspend fun postVerifyGenerateState(responseId: Int): Result = + runCatching { + generateDataSource.postVerifyGenerateState(responseId).response + } + + override suspend fun getCanceledToReset(requestId: String): Result = + runCatching { + generateDataSource.getCanceledToReset(requestId).response } } diff --git a/data/src/main/java/kr/genti/data/service/GenerateService.kt b/data/src/main/java/kr/genti/data/service/GenerateService.kt index 03c4853a..05810fe2 100644 --- a/data/src/main/java/kr/genti/data/service/GenerateService.kt +++ b/data/src/main/java/kr/genti/data/service/GenerateService.kt @@ -27,8 +27,19 @@ interface GenerateService { @Body request: ReportRequestDto, ): BaseResponse + @POST("api/v1/users/picture-generate-responses/{pictureGenerateResponseId}/rate") + suspend fun postGenerateRate( + @Path("pictureGenerateResponseId") responseId: Int, + @Query("star") star: Int, + ): BaseResponse + @POST("api/v1/users/picture-generate-responses/{pictureGenerateResponseId}/verify") - suspend fun postResetState( - @Path("pictureGenerateResponseId") id: Int, + suspend fun postVerifyGenerateState( + @Path("pictureGenerateResponseId") responseId: Int, + ): BaseResponse + + @GET("api/v1/users/picture-generate-requests/{pictureGenerateRequestId}/confirm-cancel-status") + suspend fun getCanceledToReset( + @Path("pictureGenerateRequestId") requestId: String, ): BaseResponse } diff --git a/domain/src/main/kotlin/kr/genti/domain/entity/response/GenerateStatusModel.kt b/domain/src/main/kotlin/kr/genti/domain/entity/response/GenerateStatusModel.kt index e106af04..cd946bd2 100644 --- a/domain/src/main/kotlin/kr/genti/domain/entity/response/GenerateStatusModel.kt +++ b/domain/src/main/kotlin/kr/genti/domain/entity/response/GenerateStatusModel.kt @@ -3,7 +3,7 @@ package kr.genti.domain.entity.response import kr.genti.domain.enums.GenerateStatus data class GenerateStatusModel( - val pictureGenerateRequestId: Long, + val pictureGenerateRequestId: Long?, val status: GenerateStatus, val pictureGenerateResponse: GenerateResponseModel?, ) { diff --git a/domain/src/main/kotlin/kr/genti/domain/repository/GenerateRepository.kt b/domain/src/main/kotlin/kr/genti/domain/repository/GenerateRepository.kt index 290387d9..e538f4d7 100644 --- a/domain/src/main/kotlin/kr/genti/domain/repository/GenerateRepository.kt +++ b/domain/src/main/kotlin/kr/genti/domain/repository/GenerateRepository.kt @@ -16,5 +16,12 @@ interface GenerateRepository { suspend fun postGenerateReport(request: ReportRequestModel): Result - suspend fun postResetState(id: Int): Result + suspend fun postGenerateRate( + responseId: Int, + star: Int, + ): Result + + suspend fun postVerifyGenerateState(responseId: Int): Result + + suspend fun getCanceledToReset(requestId: String): Result } diff --git a/presentation/src/main/java/kr/genti/presentation/main/MainViewModel.kt b/presentation/src/main/java/kr/genti/presentation/main/MainViewModel.kt index 7da1decc..27653207 100644 --- a/presentation/src/main/java/kr/genti/presentation/main/MainViewModel.kt +++ b/presentation/src/main/java/kr/genti/presentation/main/MainViewModel.kt @@ -34,7 +34,7 @@ class MainViewModel viewModelScope.launch { generateRepository.getGenerateStatus() .onSuccess { - currentStatus = GenerateStatus.CANCELED + currentStatus = it.status newPicture = it } .onFailure { @@ -45,11 +45,12 @@ class MainViewModel fun postResetStateToServer() { viewModelScope.launch { - generateRepository.postResetState( - newPicture.pictureGenerateResponse?.pictureGenerateResponseId?.toInt() ?: -1, + generateRepository.getCanceledToReset( + newPicture.pictureGenerateRequestId.toString(), ) .onSuccess { _postResetResult.emit(true) + getGenerateStatusFromServer() } .onFailure { _postResetResult.emit(false) diff --git a/presentation/src/main/java/kr/genti/presentation/result/finished/FinishedRatingDialog.kt b/presentation/src/main/java/kr/genti/presentation/result/finished/FinishedRatingDialog.kt index 9ce27afa..89e08ad7 100644 --- a/presentation/src/main/java/kr/genti/presentation/result/finished/FinishedRatingDialog.kt +++ b/presentation/src/main/java/kr/genti/presentation/result/finished/FinishedRatingDialog.kt @@ -43,19 +43,19 @@ class FinishedRatingDialog : initSkipBtnListener() initSubmitBtnListener() - observeResetResult() + observeVerifyResult() + observeRateResult() } private fun initSkipBtnListener() { binding.btnSkip.setOnSingleClickListener { - viewModel.postResetStateToServer() + viewModel.postVerifyGenerateStateToServer() } } private fun initSubmitBtnListener() { binding.btnSubmit.setOnSingleClickListener { - // TODO: 서버통신 - navigateToMain() + viewModel.postGenerateRateToServer(binding.ratingBar.rating.toInt()) } } @@ -67,8 +67,18 @@ class FinishedRatingDialog : dismiss() } - private fun observeResetResult() { - viewModel.postResetResult.flowWithLifecycle(lifecycle).onEach { result -> + private fun observeVerifyResult() { + viewModel.postVerifyResult.flowWithLifecycle(lifecycle).onEach { result -> + if (result) { + navigateToMain() + } else { + toast(stringOf(R.string.error_msg)) + } + }.launchIn(lifecycleScope) + } + + private fun observeRateResult() { + viewModel.postRateResult.flowWithLifecycle(lifecycle).onEach { result -> if (result) { navigateToMain() } else { diff --git a/presentation/src/main/java/kr/genti/presentation/result/finished/FinishedViewModel.kt b/presentation/src/main/java/kr/genti/presentation/result/finished/FinishedViewModel.kt index 4b3a657c..a5374988 100644 --- a/presentation/src/main/java/kr/genti/presentation/result/finished/FinishedViewModel.kt +++ b/presentation/src/main/java/kr/genti/presentation/result/finished/FinishedViewModel.kt @@ -36,8 +36,11 @@ class FinishedViewModel private val _postReportResult = MutableSharedFlow() val postReportResult: SharedFlow = _postReportResult - private val _postResetResult = MutableSharedFlow() - val postResetResult: SharedFlow = _postResetResult + private val _postRateResult = MutableSharedFlow() + val postRateResult: SharedFlow = _postRateResult + + private val _postVerifyResult = MutableSharedFlow() + val postVerifyResult: SharedFlow = _postVerifyResult fun checkWritten() { isWritten.value = errorReport.value?.isNotEmpty() @@ -47,6 +50,21 @@ class FinishedViewModel isRatio23 = finishedImage.pictureRatio?.name == PictureRatio.RATIO_2_3.name } + fun postGenerateRateToServer(star: Int) { + viewModelScope.launch { + generateRepository.postGenerateRate( + finishedImage.id.toInt(), + star, + ) + .onSuccess { + _postRateResult.emit(true) + } + .onFailure { + _postRateResult.emit(false) + } + } + } + fun postGenerateReportToServer() { viewModelScope.launch { generateRepository.postGenerateReport( @@ -64,14 +82,14 @@ class FinishedViewModel } } - fun postResetStateToServer() { + fun postVerifyGenerateStateToServer() { viewModelScope.launch { - generateRepository.postResetState(finishedImage.id.toInt()) + generateRepository.postVerifyGenerateState(finishedImage.id.toInt()) .onSuccess { - _postResetResult.emit(true) + _postVerifyResult.emit(true) } .onFailure { - _postResetResult.emit(false) + _postVerifyResult.emit(false) } } }