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/#68] 생성완료뷰 / 오류 신고 서버통신 #70

Merged
merged 7 commits into from
Jul 4, 2024
Merged
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -13,4 +14,6 @@ interface GenerateDataSource {
sortBy: String?,
direction: String?,
): BaseResponse<PicturePagedListDto>

suspend fun postGenerateReport(request: ReportRequestDto): BaseResponse<Boolean>
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,4 +21,7 @@ data class GenerateDataSourceImpl
sortBy: String?,
direction: String?,
): BaseResponse<PicturePagedListDto> = generateService.getGeneratedPictureList(page, size, sortBy, direction)

override suspend fun postGenerateReport(request: ReportRequestDto): BaseResponse<Boolean> =
generateService.postGenerateReport(request)
}
29 changes: 16 additions & 13 deletions data/src/main/java/kr/genti/data/dto/request/CreateRequestDto.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -12,23 +13,25 @@ data class CreateRequestDto(
@SerialName("prompt")
val prompt: String,
@SerialName("posePicture")
val posePicture: KeyDto?,
val posePicture: KeyRequestDto?,
@SerialName("facePictureList")
val facePictureList: List<KeyDto>,
val facePictureList: List<KeyRequestDto>,
@SerialName("cameraAngle")
val cameraAngle: CameraAngle,
@SerialName("shotCoverage")
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,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ 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)
) {
companion object {
fun KeyRequestModel.toDto() = KeyRequestDto(key)
}
}
17 changes: 17 additions & 0 deletions data/src/main/java/kr/genti/data/dto/request/ReportRequestDto.kt
Original file line number Diff line number Diff line change
@@ -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)
}
}
8 changes: 5 additions & 3 deletions data/src/main/java/kr/genti/data/dto/request/S3RequestDto.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -30,4 +32,9 @@ class GenerateRepositoryImpl
direction,
).response.toModel()
}

override suspend fun postGenerateReport(request: ReportRequestModel): Result<Boolean> =
runCatching {
generateDataSource.postGenerateReport(request.toDto()).response
}
}
8 changes: 8 additions & 0 deletions data/src/main/java/kr/genti/data/service/GenerateService.kt
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -17,4 +20,9 @@ interface GenerateService {
@Query("sortBy") sortBy: String?,
@Query("direction") direction: String?,
): BaseResponse<PicturePagedListDto>

@POST("/api/users/reports")
suspend fun postGenerateReport(
@Body request: ReportRequestDto,
): BaseResponse<Boolean>
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import kr.genti.domain.enums.ShotCoverage

data class CreateRequestModel(
val prompt: String,
val posePicture: KeyModel?,
val facePictureList: List<KeyModel>,
val posePicture: KeyRequestModel?,
val facePictureList: List<KeyRequestModel>,
val cameraAngle: CameraAngle,
val shotCoverage: ShotCoverage,
val pictureRatio: PictureRatio,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package kr.genti.domain.entity.request

data class KeyModel(
data class KeyRequestModel(
val key: String?,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package kr.genti.domain.entity.request

data class ReportRequestModel(
val pictureGenerateResponseId: Long,
val content: String,
)
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -12,4 +13,6 @@ interface GenerateRepository {
sortBy: String?,
direction: String?,
): Result<PicturePagedListModel>

suspend fun postGenerateReport(request: ReportRequestModel): Result<Boolean>
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -51,8 +51,8 @@ class CreateViewModel
val totalGeneratingState: StateFlow<UiState<Boolean>> = _totalGeneratingState

private var uploadCheckList = mutableListOf(false, false, false, true)
private var plusImageS3Key = KeyModel(null)
private var imageS3KeyList = listOf<KeyModel>()
private var plusImageS3Key = KeyRequestModel(null)
private var imageS3KeyList = listOf<KeyRequestModel>()

fun modCurrentPercent(amount: Int) {
_currentPercent.value += amount
Expand Down Expand Up @@ -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())
Expand All @@ -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())
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -91,13 +92,14 @@ class FeedFragment() : BaseFragment<FragmentFeedBinding>(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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -116,7 +117,7 @@ class ProfileFragment() : BaseFragment<FragmentProfileBinding>(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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -36,9 +42,11 @@ class FinishedErrorDialog :
) {
super.onViewCreated(view, savedInstanceState)

binding.vm = viewModel
initExitBtnListener()
initSubmitBtnListener()
setHideKeyboard(view)
observeReportResult()
}

private fun initExitBtnListener() {
Expand All @@ -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()
}
}

Expand All @@ -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)
Expand Down
Loading
Loading