Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT/#83] 생성완료뷰 / 별점 API 구현 #84

Merged
merged 7 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,12 @@ interface GenerateDataSource {

suspend fun postGenerateReport(request: ReportRequestDto): BaseResponse<Boolean>

suspend fun postResetState(id: Int): BaseResponse<Boolean>
suspend fun postGenerateRate(
responseId: Int,
star: Int,
): BaseResponse<Boolean>

suspend fun postVerifyGenerateState(responseId: Int): BaseResponse<Boolean>

suspend fun getCanceledToReset(requestId: String): BaseResponse<Boolean>
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,13 @@ data class GenerateDataSourceImpl
override suspend fun postGenerateReport(request: ReportRequestDto): BaseResponse<Boolean> =
generateService.postGenerateReport(request)

override suspend fun postResetState(id: Int): BaseResponse<Boolean> = generateService.postResetState(id)
override suspend fun postGenerateRate(
responseId: Int,
star: Int,
): BaseResponse<Boolean> = generateService.postGenerateRate(responseId, star)

override suspend fun postVerifyGenerateState(responseId: Int): BaseResponse<Boolean> =
generateService.postVerifyGenerateState(responseId)

override suspend fun getCanceledToReset(requestId: String): BaseResponse<Boolean> = generateService.getCanceledToReset(requestId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,21 @@ class GenerateRepositoryImpl
generateDataSource.postGenerateReport(request.toDto()).response
}

override suspend fun postResetState(id: Int): Result<Boolean> =
override suspend fun postGenerateRate(
responseId: Int,
star: Int,
): Result<Boolean> =
runCatching {
generateDataSource.postResetState(id).response
generateDataSource.postGenerateRate(responseId, star).response
}

override suspend fun postVerifyGenerateState(responseId: Int): Result<Boolean> =
runCatching {
generateDataSource.postVerifyGenerateState(responseId).response
}

override suspend fun getCanceledToReset(requestId: String): Result<Boolean> =
runCatching {
generateDataSource.getCanceledToReset(requestId).response
}
}
15 changes: 13 additions & 2 deletions data/src/main/java/kr/genti/data/service/GenerateService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,19 @@ interface GenerateService {
@Body request: ReportRequestDto,
): BaseResponse<Boolean>

@POST("api/v1/users/picture-generate-responses/{pictureGenerateResponseId}/rate")
suspend fun postGenerateRate(
@Path("pictureGenerateResponseId") responseId: Int,
@Query("star") star: Int,
): BaseResponse<Boolean>

@POST("api/v1/users/picture-generate-responses/{pictureGenerateResponseId}/verify")
suspend fun postResetState(
@Path("pictureGenerateResponseId") id: Int,
suspend fun postVerifyGenerateState(
@Path("pictureGenerateResponseId") responseId: Int,
): BaseResponse<Boolean>

@GET("api/v1/users/picture-generate-requests/{pictureGenerateRequestId}/confirm-cancel-status")
suspend fun getCanceledToReset(
@Path("pictureGenerateRequestId") requestId: String,
): BaseResponse<Boolean>
}
Original file line number Diff line number Diff line change
Expand Up @@ -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?,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,12 @@ interface GenerateRepository {

suspend fun postGenerateReport(request: ReportRequestModel): Result<Boolean>

suspend fun postResetState(id: Int): Result<Boolean>
suspend fun postGenerateRate(
responseId: Int,
star: Int,
): Result<Boolean>

suspend fun postVerifyGenerateState(responseId: Int): Result<Boolean>

suspend fun getCanceledToReset(requestId: String): Result<Boolean>
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class MainViewModel
viewModelScope.launch {
generateRepository.getGenerateStatus()
.onSuccess {
currentStatus = GenerateStatus.CANCELED
currentStatus = it.status
newPicture = it
}
.onFailure {
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ class FinishedViewModel
private val _postReportResult = MutableSharedFlow<Boolean>()
val postReportResult: SharedFlow<Boolean> = _postReportResult

private val _postResetResult = MutableSharedFlow<Boolean>()
val postResetResult: SharedFlow<Boolean> = _postResetResult
private val _postRateResult = MutableSharedFlow<Boolean>()
val postRateResult: SharedFlow<Boolean> = _postRateResult

private val _postVerifyResult = MutableSharedFlow<Boolean>()
val postVerifyResult: SharedFlow<Boolean> = _postVerifyResult

fun checkWritten() {
isWritten.value = errorReport.value?.isNotEmpty()
Expand All @@ -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(
Expand All @@ -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)
}
}
}
Expand Down
Loading