From 4bea7b95633a4d9e68dde73a7481a60807af3dc4 Mon Sep 17 00:00:00 2001 From: Sangho Kim Date: Fri, 5 Jul 2024 04:13:28 +0900 Subject: [PATCH 1/7] =?UTF-8?q?[ADD/#68]=20=EC=83=9D=EC=84=B1=20=EC=8B=A0?= =?UTF-8?q?=EA=B3=A0=20=EC=84=9C=EB=B2=84=ED=86=B5=EC=8B=A0=20domain=20?= =?UTF-8?q?=EB=AA=A8=EB=93=88=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kr/genti/data/dto/request/CreateRequestDto.kt | 4 ++-- .../data/dto/request/{KeyDto.kt => KeyRequestDto.kt} | 6 +++--- .../domain/entity/request/CreateRequestModel.kt | 4 ++-- .../request/{KeyModel.kt => KeyRequestModel.kt} | 2 +- .../domain/entity/request/ReportRequestModel.kt | 6 ++++++ .../kr/genti/domain/repository/GenerateRepository.kt | 3 +++ .../presentation/main/create/CreateViewModel.kt | 12 ++++++------ 7 files changed, 23 insertions(+), 14 deletions(-) rename data/src/main/java/kr/genti/data/dto/request/{KeyDto.kt => KeyRequestDto.kt} (58%) rename domain/src/main/kotlin/kr/genti/domain/entity/request/{KeyModel.kt => KeyRequestModel.kt} (69%) create mode 100644 domain/src/main/kotlin/kr/genti/domain/entity/request/ReportRequestModel.kt diff --git a/data/src/main/java/kr/genti/data/dto/request/CreateRequestDto.kt b/data/src/main/java/kr/genti/data/dto/request/CreateRequestDto.kt index 8675c004..313bc27c 100644 --- a/data/src/main/java/kr/genti/data/dto/request/CreateRequestDto.kt +++ b/data/src/main/java/kr/genti/data/dto/request/CreateRequestDto.kt @@ -12,9 +12,9 @@ data class CreateRequestDto( @SerialName("prompt") val prompt: String, @SerialName("posePicture") - val posePicture: KeyDto?, + val posePicture: KeyRequestDto?, @SerialName("facePictureList") - val facePictureList: List, + val facePictureList: List, @SerialName("cameraAngle") val cameraAngle: CameraAngle, @SerialName("shotCoverage") diff --git a/data/src/main/java/kr/genti/data/dto/request/KeyDto.kt b/data/src/main/java/kr/genti/data/dto/request/KeyRequestDto.kt similarity index 58% rename from data/src/main/java/kr/genti/data/dto/request/KeyDto.kt rename to data/src/main/java/kr/genti/data/dto/request/KeyRequestDto.kt index 23be4568..40c557e8 100644 --- a/data/src/main/java/kr/genti/data/dto/request/KeyDto.kt +++ b/data/src/main/java/kr/genti/data/dto/request/KeyRequestDto.kt @@ -2,12 +2,12 @@ package kr.genti.data.dto.request import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable -import kr.genti.domain.entity.request.KeyModel +import kr.genti.domain.entity.request.KeyRequestModel @Serializable -data class KeyDto( +data class KeyRequestDto( @SerialName("key") val key: String?, ) -fun KeyModel.toDto() = KeyDto(key) +fun KeyRequestModel.toDto() = KeyRequestDto(key) diff --git a/domain/src/main/kotlin/kr/genti/domain/entity/request/CreateRequestModel.kt b/domain/src/main/kotlin/kr/genti/domain/entity/request/CreateRequestModel.kt index ce4bb341..742e7ae3 100644 --- a/domain/src/main/kotlin/kr/genti/domain/entity/request/CreateRequestModel.kt +++ b/domain/src/main/kotlin/kr/genti/domain/entity/request/CreateRequestModel.kt @@ -6,8 +6,8 @@ import kr.genti.domain.enums.ShotCoverage data class CreateRequestModel( val prompt: String, - val posePicture: KeyModel?, - val facePictureList: List, + val posePicture: KeyRequestModel?, + val facePictureList: List, val cameraAngle: CameraAngle, val shotCoverage: ShotCoverage, val pictureRatio: PictureRatio, diff --git a/domain/src/main/kotlin/kr/genti/domain/entity/request/KeyModel.kt b/domain/src/main/kotlin/kr/genti/domain/entity/request/KeyRequestModel.kt similarity index 69% rename from domain/src/main/kotlin/kr/genti/domain/entity/request/KeyModel.kt rename to domain/src/main/kotlin/kr/genti/domain/entity/request/KeyRequestModel.kt index 0e9c4b95..98f286c3 100644 --- a/domain/src/main/kotlin/kr/genti/domain/entity/request/KeyModel.kt +++ b/domain/src/main/kotlin/kr/genti/domain/entity/request/KeyRequestModel.kt @@ -1,5 +1,5 @@ package kr.genti.domain.entity.request -data class KeyModel( +data class KeyRequestModel( val key: String?, ) diff --git a/domain/src/main/kotlin/kr/genti/domain/entity/request/ReportRequestModel.kt b/domain/src/main/kotlin/kr/genti/domain/entity/request/ReportRequestModel.kt new file mode 100644 index 00000000..1096b402 --- /dev/null +++ b/domain/src/main/kotlin/kr/genti/domain/entity/request/ReportRequestModel.kt @@ -0,0 +1,6 @@ +package kr.genti.domain.entity.request + +data class ReportRequestModel( + val pictureGenerateResponseId: Long, + val content: String, +) 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 cbb7d7bd..168d68e6 100644 --- a/domain/src/main/kotlin/kr/genti/domain/repository/GenerateRepository.kt +++ b/domain/src/main/kotlin/kr/genti/domain/repository/GenerateRepository.kt @@ -1,5 +1,6 @@ package kr.genti.domain.repository +import kr.genti.domain.entity.request.ReportRequestModel import kr.genti.domain.entity.response.GenerateStatusModel import kr.genti.domain.entity.response.PicturePagedListModel @@ -12,4 +13,6 @@ interface GenerateRepository { sortBy: String?, direction: String?, ): Result + + suspend fun postGenerateReport(request: ReportRequestModel): Result } diff --git a/presentation/src/main/java/kr/genti/presentation/main/create/CreateViewModel.kt b/presentation/src/main/java/kr/genti/presentation/main/create/CreateViewModel.kt index fc41e654..c1652f74 100644 --- a/presentation/src/main/java/kr/genti/presentation/main/create/CreateViewModel.kt +++ b/presentation/src/main/java/kr/genti/presentation/main/create/CreateViewModel.kt @@ -9,7 +9,7 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.launch import kr.genti.core.state.UiState import kr.genti.domain.entity.request.CreateRequestModel -import kr.genti.domain.entity.request.KeyModel +import kr.genti.domain.entity.request.KeyRequestModel import kr.genti.domain.entity.request.S3RequestModel import kr.genti.domain.entity.response.ImageFileModel import kr.genti.domain.entity.response.ImageFileModel.Companion.emptyImageFileModel @@ -51,8 +51,8 @@ class CreateViewModel val totalGeneratingState: StateFlow> = _totalGeneratingState private var uploadCheckList = mutableListOf(false, false, false, true) - private var plusImageS3Key = KeyModel(null) - private var imageS3KeyList = listOf() + private var plusImageS3Key = KeyRequestModel(null) + private var imageS3KeyList = listOf() fun modCurrentPercent(amount: Int) { _currentPercent.value += amount @@ -99,7 +99,7 @@ class CreateViewModel ), ) .onSuccess { uriModel -> - plusImageS3Key = KeyModel(uriModel.s3Key) + plusImageS3Key = KeyRequestModel(uriModel.s3Key) postSingleImage(uriModel) }.onFailure { _totalGeneratingState.value = UiState.Failure(it.message.toString()) @@ -117,7 +117,7 @@ class CreateViewModel S3RequestModel(FileType.USER_UPLOADED_IMAGE, imageList[2].name), ), ).onSuccess { uriList -> - imageS3KeyList = uriList.map { KeyModel(it.s3Key) } + imageS3KeyList = uriList.map { KeyRequestModel(it.s3Key) } postMultiImage(uriList) }.onFailure { _totalGeneratingState.value = UiState.Failure(it.message.toString()) @@ -129,7 +129,7 @@ class CreateViewModel viewModelScope.launch { uploadRepository.uploadImage(s3urlModel.url, plusImage.url) .onSuccess { - plusImageS3Key = KeyModel(s3urlModel.s3Key) + plusImageS3Key = KeyRequestModel(s3urlModel.s3Key) uploadCheckList[3] = true checkAllUploadFinished() }.onFailure { From 1722d3a6ded1bc27565dcc2f48e1b62e85adc8a5 Mon Sep 17 00:00:00 2001 From: Sangho Kim Date: Fri, 5 Jul 2024 04:17:58 +0900 Subject: [PATCH 2/7] =?UTF-8?q?[FIX/#68]=20RequestDto=EC=97=90=20companion?= =?UTF-8?q?=20object=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/dto/request/CreateRequestDto.kt | 25 +++++++++++-------- .../genti/data/dto/request/KeyRequestDto.kt | 8 +++--- .../kr/genti/data/dto/request/S3RequestDto.kt | 8 +++--- .../genti/data/dto/request/TokenRequestDto.kt | 8 +++--- .../data/repositoryImpl/AuthRepositoryImpl.kt | 2 +- .../repositoryImpl/CreateRepositoryImpl.kt | 3 ++- 6 files changed, 32 insertions(+), 22 deletions(-) diff --git a/data/src/main/java/kr/genti/data/dto/request/CreateRequestDto.kt b/data/src/main/java/kr/genti/data/dto/request/CreateRequestDto.kt index 313bc27c..f50f5795 100644 --- a/data/src/main/java/kr/genti/data/dto/request/CreateRequestDto.kt +++ b/data/src/main/java/kr/genti/data/dto/request/CreateRequestDto.kt @@ -2,6 +2,7 @@ package kr.genti.data.dto.request import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +import kr.genti.data.dto.request.KeyRequestDto.Companion.toDto import kr.genti.domain.entity.request.CreateRequestModel import kr.genti.domain.enums.CameraAngle import kr.genti.domain.enums.PictureRatio @@ -21,14 +22,16 @@ data class CreateRequestDto( val shotCoverage: ShotCoverage, @SerialName("pictureRatio") val pictureRatio: PictureRatio, -) - -fun CreateRequestModel.toDto() = - CreateRequestDto( - prompt, - posePicture?.toDto(), - facePictureList.map { it.toDto() }, - cameraAngle, - shotCoverage, - pictureRatio, - ) +) { + companion object { + fun CreateRequestModel.toDto() = + CreateRequestDto( + prompt, + posePicture?.toDto(), + facePictureList.map { it.toDto() }, + cameraAngle, + shotCoverage, + pictureRatio, + ) + } +} diff --git a/data/src/main/java/kr/genti/data/dto/request/KeyRequestDto.kt b/data/src/main/java/kr/genti/data/dto/request/KeyRequestDto.kt index 40c557e8..e6d038e1 100644 --- a/data/src/main/java/kr/genti/data/dto/request/KeyRequestDto.kt +++ b/data/src/main/java/kr/genti/data/dto/request/KeyRequestDto.kt @@ -8,6 +8,8 @@ import kr.genti.domain.entity.request.KeyRequestModel data class KeyRequestDto( @SerialName("key") val key: String?, -) - -fun KeyRequestModel.toDto() = KeyRequestDto(key) +) { + companion object { + fun KeyRequestModel.toDto() = KeyRequestDto(key) + } +} diff --git a/data/src/main/java/kr/genti/data/dto/request/S3RequestDto.kt b/data/src/main/java/kr/genti/data/dto/request/S3RequestDto.kt index bc4cd26a..40fdb0db 100644 --- a/data/src/main/java/kr/genti/data/dto/request/S3RequestDto.kt +++ b/data/src/main/java/kr/genti/data/dto/request/S3RequestDto.kt @@ -11,6 +11,8 @@ data class S3RequestDto( val fileType: FileType, @SerialName("fileName") val fileName: String, -) - -fun S3RequestModel.toDto() = S3RequestDto(fileType, fileName) +) { + companion object { + fun S3RequestModel.toDto() = S3RequestDto(fileType, fileName) + } +} diff --git a/data/src/main/java/kr/genti/data/dto/request/TokenRequestDto.kt b/data/src/main/java/kr/genti/data/dto/request/TokenRequestDto.kt index 662d0b39..0ef113a0 100644 --- a/data/src/main/java/kr/genti/data/dto/request/TokenRequestDto.kt +++ b/data/src/main/java/kr/genti/data/dto/request/TokenRequestDto.kt @@ -8,6 +8,8 @@ import kr.genti.domain.entity.request.TokenRequestModel data class TokenRequestDto( @SerialName("userId") val userId: Long, -) - -fun TokenRequestModel.toDto() = TokenRequestDto(userId) +) { + companion object { + fun TokenRequestModel.toDto() = TokenRequestDto(userId) + } +} diff --git a/data/src/main/java/kr/genti/data/repositoryImpl/AuthRepositoryImpl.kt b/data/src/main/java/kr/genti/data/repositoryImpl/AuthRepositoryImpl.kt index 9b4b0ec9..bd137e1c 100644 --- a/data/src/main/java/kr/genti/data/repositoryImpl/AuthRepositoryImpl.kt +++ b/data/src/main/java/kr/genti/data/repositoryImpl/AuthRepositoryImpl.kt @@ -1,7 +1,7 @@ package kr.genti.data.repositoryImpl import kr.genti.data.dataSource.AuthDataSource -import kr.genti.data.dto.request.toDto +import kr.genti.data.dto.request.TokenRequestDto.Companion.toDto import kr.genti.domain.entity.request.TokenRequestModel import kr.genti.domain.entity.response.AuthTokenModel import kr.genti.domain.repository.AuthRepository diff --git a/data/src/main/java/kr/genti/data/repositoryImpl/CreateRepositoryImpl.kt b/data/src/main/java/kr/genti/data/repositoryImpl/CreateRepositoryImpl.kt index abca9407..e94d1640 100644 --- a/data/src/main/java/kr/genti/data/repositoryImpl/CreateRepositoryImpl.kt +++ b/data/src/main/java/kr/genti/data/repositoryImpl/CreateRepositoryImpl.kt @@ -1,7 +1,8 @@ package kr.genti.data.repositoryImpl import kr.genti.data.dataSource.CreateDataSource -import kr.genti.data.dto.request.toDto +import kr.genti.data.dto.request.CreateRequestDto.Companion.toDto +import kr.genti.data.dto.request.S3RequestDto.Companion.toDto import kr.genti.domain.entity.request.CreateRequestModel import kr.genti.domain.entity.request.S3RequestModel import kr.genti.domain.entity.response.S3PresignedUrlModel From 97d9120ddd1f3e1fe7358ba97d611e420721b2c1 Mon Sep 17 00:00:00 2001 From: Sangho Kim Date: Fri, 5 Jul 2024 04:26:46 +0900 Subject: [PATCH 3/7] =?UTF-8?q?[ADD/#68]=20=EC=83=9D=EC=84=B1=20=EC=8B=A0?= =?UTF-8?q?=EA=B3=A0=20=EC=84=9C=EB=B2=84=ED=86=B5=EC=8B=A0=20data=20?= =?UTF-8?q?=EB=AA=A8=EB=93=88=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../genti/data/dataSource/GenerateDataSource.kt | 3 +++ .../dataSourceImpl/GenerateDataSourceImpl.kt | 4 ++++ .../genti/data/dto/request/ReportRequestDto.kt | 17 +++++++++++++++++ .../repositoryImpl/GenerateRepositoryImpl.kt | 7 +++++++ .../kr/genti/data/service/GenerateService.kt | 8 ++++++++ 5 files changed, 39 insertions(+) create mode 100644 data/src/main/java/kr/genti/data/dto/request/ReportRequestDto.kt 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 b8700034..01827ffe 100644 --- a/data/src/main/java/kr/genti/data/dataSource/GenerateDataSource.kt +++ b/data/src/main/java/kr/genti/data/dataSource/GenerateDataSource.kt @@ -1,6 +1,7 @@ package kr.genti.data.dataSource import kr.genti.data.dto.BaseResponse +import kr.genti.data.dto.request.ReportRequestDto import kr.genti.data.dto.response.GenerateStatusDto import kr.genti.data.dto.response.PicturePagedListDto @@ -13,4 +14,6 @@ interface GenerateDataSource { sortBy: String?, direction: String?, ): BaseResponse + + suspend fun postGenerateReport(request: ReportRequestDto): 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 674ee0a7..e85671e5 100644 --- a/data/src/main/java/kr/genti/data/dataSourceImpl/GenerateDataSourceImpl.kt +++ b/data/src/main/java/kr/genti/data/dataSourceImpl/GenerateDataSourceImpl.kt @@ -2,6 +2,7 @@ package kr.genti.data.dataSourceImpl import kr.genti.data.dataSource.GenerateDataSource import kr.genti.data.dto.BaseResponse +import kr.genti.data.dto.request.ReportRequestDto import kr.genti.data.dto.response.GenerateStatusDto import kr.genti.data.dto.response.PicturePagedListDto import kr.genti.data.service.GenerateService @@ -20,4 +21,7 @@ data class GenerateDataSourceImpl sortBy: String?, direction: String?, ): BaseResponse = generateService.getGeneratedPictureList(page, size, sortBy, direction) + + override suspend fun postGenerateReport(request: ReportRequestDto): BaseResponse = + generateService.postGenerateReport(request) } diff --git a/data/src/main/java/kr/genti/data/dto/request/ReportRequestDto.kt b/data/src/main/java/kr/genti/data/dto/request/ReportRequestDto.kt new file mode 100644 index 00000000..2fafb777 --- /dev/null +++ b/data/src/main/java/kr/genti/data/dto/request/ReportRequestDto.kt @@ -0,0 +1,17 @@ +package kr.genti.data.dto.request + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +import kr.genti.domain.entity.request.ReportRequestModel + +@Serializable +data class ReportRequestDto( + @SerialName("pictureGenerateResponseId") + val pictureGenerateResponseId: Long, + @SerialName("content") + val content: String, +) { + companion object { + fun ReportRequestModel.toDto() = ReportRequestDto(pictureGenerateResponseId, content) + } +} 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 7a6c1696..63d7b795 100644 --- a/data/src/main/java/kr/genti/data/repositoryImpl/GenerateRepositoryImpl.kt +++ b/data/src/main/java/kr/genti/data/repositoryImpl/GenerateRepositoryImpl.kt @@ -1,6 +1,8 @@ package kr.genti.data.repositoryImpl import kr.genti.data.dataSource.GenerateDataSource +import kr.genti.data.dto.request.ReportRequestDto.Companion.toDto +import kr.genti.domain.entity.request.ReportRequestModel import kr.genti.domain.entity.response.GenerateStatusModel import kr.genti.domain.entity.response.PicturePagedListModel import kr.genti.domain.repository.GenerateRepository @@ -30,4 +32,9 @@ class GenerateRepositoryImpl direction, ).response.toModel() } + + override suspend fun postGenerateReport(request: ReportRequestModel): Result = + runCatching { + generateDataSource.postGenerateReport(request.toDto()).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 f7b03345..6b38326b 100644 --- a/data/src/main/java/kr/genti/data/service/GenerateService.kt +++ b/data/src/main/java/kr/genti/data/service/GenerateService.kt @@ -1,9 +1,12 @@ package kr.genti.data.service import kr.genti.data.dto.BaseResponse +import kr.genti.data.dto.request.ReportRequestDto import kr.genti.data.dto.response.GenerateStatusDto import kr.genti.data.dto.response.PicturePagedListDto +import retrofit2.http.Body import retrofit2.http.GET +import retrofit2.http.POST import retrofit2.http.Query interface GenerateService { @@ -17,4 +20,9 @@ interface GenerateService { @Query("sortBy") sortBy: String?, @Query("direction") direction: String?, ): BaseResponse + + @POST("/api/users/reports") + suspend fun postGenerateReport( + @Body request: ReportRequestDto, + ): BaseResponse } From 30efc3452c581ba9be81a76dbb49b50800009b2a Mon Sep 17 00:00:00 2001 From: Sangho Kim Date: Fri, 5 Jul 2024 04:33:32 +0900 Subject: [PATCH 4/7] =?UTF-8?q?[ADD/#68]=20=EC=83=9D=EC=84=B1=20=EC=8B=A0?= =?UTF-8?q?=EA=B3=A0=20=EC=84=9C=EB=B2=84=ED=86=B5=EC=8B=A0=20viewModel=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../result/finished/FinishedViewModel.kt | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) 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 401a6b19..9670fe00 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 @@ -2,16 +2,22 @@ package kr.genti.presentation.result.finished import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.MutableSharedFlow +import kotlinx.coroutines.flow.SharedFlow +import kotlinx.coroutines.launch +import kr.genti.domain.entity.request.ReportRequestModel import kr.genti.domain.entity.response.ImageModel import kr.genti.domain.enums.PictureRatio +import kr.genti.domain.repository.GenerateRepository import javax.inject.Inject @HiltViewModel class FinishedViewModel @Inject constructor( - // private val profileRepository: ProfileRepository, + private val generateRepository: GenerateRepository, ) : ViewModel() { val errorReport = MutableLiveData() @@ -26,7 +32,25 @@ class FinishedViewModel var isRatio23 = true + private val _postReportResult = MutableSharedFlow() + val postReportResult: SharedFlow = _postReportResult + fun setPictureRatio() { isRatio23 = finishedImage.pictureRatio?.name == PictureRatio.RATIO_2_3.name } + + fun postGenerateReport( + responseId: Long, + content: String, + ) { + viewModelScope.launch { + generateRepository.postGenerateReport(ReportRequestModel(responseId, content)) + .onSuccess { + _postReportResult.emit(true) + } + .onFailure { + _postReportResult.emit(false) + } + } + } } From b82fb9270e21fb24ce7c189eec61309cb630509f Mon Sep 17 00:00:00 2001 From: Sangho Kim Date: Fri, 5 Jul 2024 05:06:08 +0900 Subject: [PATCH 5/7] =?UTF-8?q?[FEAT/#68]=20=EC=83=9D=EC=84=B1=20=EC=8B=A0?= =?UTF-8?q?=EA=B3=A0=20=EC=84=9C=EB=B2=84=ED=86=B5=EC=8B=A0=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../result/finished/FinishedErrorDialog.kt | 31 ++++++++++++++----- .../result/finished/FinishedViewModel.kt | 12 ++++--- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/presentation/src/main/java/kr/genti/presentation/result/finished/FinishedErrorDialog.kt b/presentation/src/main/java/kr/genti/presentation/result/finished/FinishedErrorDialog.kt index 3b0d036d..51f8d207 100644 --- a/presentation/src/main/java/kr/genti/presentation/result/finished/FinishedErrorDialog.kt +++ b/presentation/src/main/java/kr/genti/presentation/result/finished/FinishedErrorDialog.kt @@ -7,10 +7,16 @@ import android.view.View import android.view.WindowManager import androidx.core.view.isVisible import androidx.fragment.app.activityViewModels +import androidx.lifecycle.flowWithLifecycle +import androidx.lifecycle.lifecycleScope +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach import kr.genti.core.base.BaseDialog import kr.genti.core.extension.hideKeyboard import kr.genti.core.extension.setGusianBlur import kr.genti.core.extension.setOnSingleClickListener +import kr.genti.core.extension.stringOf +import kr.genti.core.extension.toast import kr.genti.presentation.R import kr.genti.presentation.databinding.DialogFinishedErrorBinding @@ -36,9 +42,11 @@ class FinishedErrorDialog : ) { super.onViewCreated(view, savedInstanceState) + binding.vm = viewModel initExitBtnListener() initSubmitBtnListener() setHideKeyboard(view) + observeReportResult() } private fun initExitBtnListener() { @@ -51,13 +59,7 @@ class FinishedErrorDialog : private fun initSubmitBtnListener() { binding.btnSubmit.setOnSingleClickListener { - // TODO: 서버통신 - requireContext().hideKeyboard(requireView()) - with(binding) { - layoutErrorInput.isVisible = false - layoutErrorOutput.isVisible = true - viewOutside.setOnSingleClickListener { dismiss() } - } + viewModel.postGenerateReport() } } @@ -71,6 +73,21 @@ class FinishedErrorDialog : } } + private fun observeReportResult() { + viewModel.postReportResult.flowWithLifecycle(lifecycle).onEach { result -> + if (result) { + requireContext().hideKeyboard(requireView()) + with(binding) { + layoutErrorInput.isVisible = false + layoutErrorOutput.isVisible = true + viewOutside.setOnSingleClickListener { dismiss() } + } + } else { + toast(stringOf(R.string.error_msg)) + } + }.launchIn(lifecycleScope) + } + override fun onDismiss(dialog: DialogInterface) { super.onDismiss(dialog) requireActivity().window.decorView.rootView.setGusianBlur(null) 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 9670fe00..8e8b3c39 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 @@ -39,12 +39,14 @@ class FinishedViewModel isRatio23 = finishedImage.pictureRatio?.name == PictureRatio.RATIO_2_3.name } - fun postGenerateReport( - responseId: Long, - content: String, - ) { + fun postGenerateReport() { viewModelScope.launch { - generateRepository.postGenerateReport(ReportRequestModel(responseId, content)) + generateRepository.postGenerateReport( + ReportRequestModel( + finishedImage.id, + errorReport.value.orEmpty(), + ), + ) .onSuccess { _postReportResult.emit(true) } From e42579d6bc7fdde58b2f9b78c54ee86f6bd588ba Mon Sep 17 00:00:00 2001 From: Sangho Kim Date: Fri, 5 Jul 2024 05:15:33 +0900 Subject: [PATCH 6/7] =?UTF-8?q?[ADD/#68]=20=EC=98=A4=EB=A5=98=20=EC=8B=A0?= =?UTF-8?q?=EA=B3=A0=EB=B7=B0=20=EB=B2=84=ED=8A=BC=20=ED=99=9C=EC=84=B1?= =?UTF-8?q?=ED=99=94=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../genti/presentation/result/finished/FinishedViewModel.kt | 5 +++++ presentation/src/main/res/layout/dialog_finished_error.xml | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) 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 8e8b3c39..f58d7d4b 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 @@ -20,6 +20,7 @@ class FinishedViewModel private val generateRepository: GenerateRepository, ) : ViewModel() { val errorReport = MutableLiveData() + val isWritten = MutableLiveData(false) var finishedImage = ImageModel( @@ -35,6 +36,10 @@ class FinishedViewModel private val _postReportResult = MutableSharedFlow() val postReportResult: SharedFlow = _postReportResult + fun checkWritten() { + isWritten.value = errorReport.value?.isNotEmpty() + } + fun setPictureRatio() { isRatio23 = finishedImage.pictureRatio?.name == PictureRatio.RATIO_2_3.name } diff --git a/presentation/src/main/res/layout/dialog_finished_error.xml b/presentation/src/main/res/layout/dialog_finished_error.xml index 4ede50db..66d4a9c4 100644 --- a/presentation/src/main/res/layout/dialog_finished_error.xml +++ b/presentation/src/main/res/layout/dialog_finished_error.xml @@ -103,6 +103,7 @@ android:id="@+id/et_error_input" style="@style/TextAppearance.Genti.BodySmall" android:layout_width="0dp" + android:afterTextChanged="@{(text) -> vm.checkWritten()}" android:layout_height="wrap_content" android:layout_marginHorizontal="45dp" android:layout_marginTop="20dp" @@ -120,11 +121,12 @@ android:layout_height="wrap_content" android:layout_marginTop="20dp" android:layout_marginEnd="45dp" - android:background="@drawable/shape_green1_fill_6_rect" + android:background="@drawable/sel_btn" + android:enabled="@{vm.isWritten}" android:paddingHorizontal="35dp" android:paddingVertical="6dp" android:text="@string/finished_error_input_btn_submit" - android:textColor="@color/white" + android:textColor="@{vm.isWritten() == true ? @color/white : @color/black}" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toBottomOf="@id/et_error_input" /> From 421330ca9138aa18743de1832a815c33019464c8 Mon Sep 17 00:00:00 2001 From: Sangho Kim Date: Fri, 5 Jul 2024 06:21:16 +0900 Subject: [PATCH 7/7] =?UTF-8?q?[FIX/#68]=20StateFlow=EC=97=90=20DistinctUn?= =?UTF-8?q?tilChanged=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../genti/presentation/main/feed/FeedFragment.kt | 16 +++++++++------- .../presentation/main/profile/ProfileFragment.kt | 3 ++- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/presentation/src/main/java/kr/genti/presentation/main/feed/FeedFragment.kt b/presentation/src/main/java/kr/genti/presentation/main/feed/FeedFragment.kt index 05e6cfe2..4be262c6 100644 --- a/presentation/src/main/java/kr/genti/presentation/main/feed/FeedFragment.kt +++ b/presentation/src/main/java/kr/genti/presentation/main/feed/FeedFragment.kt @@ -8,6 +8,7 @@ import androidx.lifecycle.flowWithLifecycle import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.RecyclerView import dagger.hilt.android.AndroidEntryPoint +import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kr.genti.core.base.BaseFragment @@ -91,13 +92,14 @@ class FeedFragment() : BaseFragment(R.layout.fragment_feed) } private fun observeGetExampleItemsState() { - viewModel.getExampleItemsState.flowWithLifecycle(lifecycle).onEach { state -> - when (state) { - is UiState.Success -> adapter.addItemList(state.data) - is UiState.Failure -> toast(stringOf(R.string.error_msg)) - else -> return@onEach - } - }.launchIn(lifecycleScope) + viewModel.getExampleItemsState.flowWithLifecycle(lifecycle).distinctUntilChanged() + .onEach { state -> + when (state) { + is UiState.Success -> adapter.addItemList(state.data) + is UiState.Failure -> toast(stringOf(R.string.error_msg)) + else -> return@onEach + } + }.launchIn(lifecycleScope) } override fun onDestroyView() { diff --git a/presentation/src/main/java/kr/genti/presentation/main/profile/ProfileFragment.kt b/presentation/src/main/java/kr/genti/presentation/main/profile/ProfileFragment.kt index 09a5d58e..a46b957a 100644 --- a/presentation/src/main/java/kr/genti/presentation/main/profile/ProfileFragment.kt +++ b/presentation/src/main/java/kr/genti/presentation/main/profile/ProfileFragment.kt @@ -10,6 +10,7 @@ import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import dagger.hilt.android.AndroidEntryPoint +import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kr.genti.core.base.BaseFragment @@ -116,7 +117,7 @@ class ProfileFragment() : BaseFragment(R.layout.fragment } private fun observePictureListPageState() { - viewModel.getPictureListState.flowWithLifecycle(lifecycle).onEach { state -> + viewModel.getPictureListState.flowWithLifecycle(lifecycle).distinctUntilChanged().onEach { state -> when (state) { is UiState.Success -> { setLayoutEmpty(false)