From 840c52d1c83442e5de08ea4dacbc09f6a841bc47 Mon Sep 17 00:00:00 2001 From: gaeun Date: Sun, 3 Sep 2023 16:29:49 +0900 Subject: [PATCH] =?UTF-8?q?[REFACTOR/#68]=20=ED=9A=8C=EA=B3=A0=EC=83=81?= =?UTF-8?q?=EC=84=B8=EC=A1=B0=ED=9A=8C=20=EB=B7=B0=20Dto=20->=20Entity=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/response/ResponseDetailRetroDto.kt | 16 ++++++++++++- .../data/repository/MyPageRepositoryImpl.kt | 11 ++++++--- .../puzzlingaos/domain/entity/DetailRetro.kt | 14 +++++++++++ .../domain/repository/MyPageRepository.kt | 4 ++-- .../detailRetrospect/DetailRetroAdapter.kt | 7 +++--- .../detailRetrospect/DetailRetroFragment.kt | 2 +- .../detailRetrospect/DetailRetroViewModel.kt | 24 ++++++++----------- 7 files changed, 54 insertions(+), 24 deletions(-) create mode 100644 app/src/main/java/com/puzzling/puzzlingaos/domain/entity/DetailRetro.kt diff --git a/app/src/main/java/com/puzzling/puzzlingaos/data/model/response/ResponseDetailRetroDto.kt b/app/src/main/java/com/puzzling/puzzlingaos/data/model/response/ResponseDetailRetroDto.kt index 34352f02..c2de2f4f 100644 --- a/app/src/main/java/com/puzzling/puzzlingaos/data/model/response/ResponseDetailRetroDto.kt +++ b/app/src/main/java/com/puzzling/puzzlingaos/data/model/response/ResponseDetailRetroDto.kt @@ -1,5 +1,6 @@ package com.puzzling.puzzlingaos.data.model.response +import com.puzzling.puzzlingaos.domain.entity.DetailRetro import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -12,7 +13,7 @@ data class ResponseDetailRetroDto( @SerialName("message") val message: String, @SerialName("data") - val data: Data?, + val data: Data, ) { @Serializable data class Data( @@ -42,5 +43,18 @@ data class ResponseDetailRetroDto( val content: String, ) } + + fun toDetailRetro() = reviews.map { reviews -> + DetailRetro( + reviewId = reviews.reviewId, + reviewDay = reviews.reviewDay, + reviewDate = reviews.reviewDate, + reviewTemplateId = reviews.reviewTemplateId, + content = reviews.contents?.map { content -> + DetailRetro.Content(content.title, content.content) + }, + + ) + } } } diff --git a/app/src/main/java/com/puzzling/puzzlingaos/data/repository/MyPageRepositoryImpl.kt b/app/src/main/java/com/puzzling/puzzlingaos/data/repository/MyPageRepositoryImpl.kt index ed029f13..9f8f89dd 100644 --- a/app/src/main/java/com/puzzling/puzzlingaos/data/repository/MyPageRepositoryImpl.kt +++ b/app/src/main/java/com/puzzling/puzzlingaos/data/repository/MyPageRepositoryImpl.kt @@ -1,8 +1,8 @@ package com.puzzling.puzzlingaos.data.repository -import com.puzzling.puzzlingaos.data.model.response.ResponseDetailRetroDto import com.puzzling.puzzlingaos.data.model.response.ResponseMyRetroListDto import com.puzzling.puzzlingaos.data.source.remote.MyPageDataSource +import com.puzzling.puzzlingaos.domain.entity.DetailRetro import com.puzzling.puzzlingaos.domain.repository.MyPageRepository import javax.inject.Inject @@ -17,7 +17,12 @@ class MyPageRepositoryImpl @Inject constructor(private val myPageDataSource: MyP projectId: Int, startDate: String, endDate: String, - ): ResponseDetailRetroDto { - return myPageDataSource.getMyDetailReview(memberId, projectId, startDate, endDate) + ): Result> = runCatching { + myPageDataSource.getMyDetailReview( + memberId, + projectId, + startDate, + endDate, + ).data.toDetailRetro() } } diff --git a/app/src/main/java/com/puzzling/puzzlingaos/domain/entity/DetailRetro.kt b/app/src/main/java/com/puzzling/puzzlingaos/domain/entity/DetailRetro.kt new file mode 100644 index 00000000..44e5d153 --- /dev/null +++ b/app/src/main/java/com/puzzling/puzzlingaos/domain/entity/DetailRetro.kt @@ -0,0 +1,14 @@ +package com.puzzling.puzzlingaos.domain.entity + +data class DetailRetro( + val reviewId: Int?, + val reviewDay: String, + val reviewDate: String, + val reviewTemplateId: Int?, + val content: List?, +) { + data class Content( + val title: String, + val content: String, + ) +} diff --git a/app/src/main/java/com/puzzling/puzzlingaos/domain/repository/MyPageRepository.kt b/app/src/main/java/com/puzzling/puzzlingaos/domain/repository/MyPageRepository.kt index 678869c4..26e24e2d 100644 --- a/app/src/main/java/com/puzzling/puzzlingaos/domain/repository/MyPageRepository.kt +++ b/app/src/main/java/com/puzzling/puzzlingaos/domain/repository/MyPageRepository.kt @@ -1,7 +1,7 @@ package com.puzzling.puzzlingaos.domain.repository -import com.puzzling.puzzlingaos.data.model.response.ResponseDetailRetroDto import com.puzzling.puzzlingaos.data.model.response.ResponseMyRetroListDto +import com.puzzling.puzzlingaos.domain.entity.DetailRetro interface MyPageRepository { @@ -15,5 +15,5 @@ interface MyPageRepository { projectId: Int, startDate: String, endDate: String, - ): ResponseDetailRetroDto + ): Result> } diff --git a/app/src/main/java/com/puzzling/puzzlingaos/presentation/detailRetrospect/DetailRetroAdapter.kt b/app/src/main/java/com/puzzling/puzzlingaos/presentation/detailRetrospect/DetailRetroAdapter.kt index 9f850c40..6a8f7d59 100644 --- a/app/src/main/java/com/puzzling/puzzlingaos/presentation/detailRetrospect/DetailRetroAdapter.kt +++ b/app/src/main/java/com/puzzling/puzzlingaos/presentation/detailRetrospect/DetailRetroAdapter.kt @@ -6,10 +6,11 @@ import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.RecyclerView import com.puzzling.puzzlingaos.data.model.response.ResponseDetailRetroDto import com.puzzling.puzzlingaos.databinding.ItemDetailRetroBinding +import com.puzzling.puzzlingaos.domain.entity.DetailRetro import com.puzzling.puzzlingaos.util.ItemDiffCallback class DetailRetroAdapter() : - ListAdapter( + ListAdapter( diffCallback, ) { @@ -25,7 +26,7 @@ class DetailRetroAdapter() : inner class DetailRetroViewHolder(private val binding: ItemDetailRetroBinding) : RecyclerView.ViewHolder(binding.root) { - fun onBind(item: ResponseDetailRetroDto.Data.DetailReviewData.Content) { + fun onBind(item: DetailRetro.Content) { binding.tvDetailRetroTitle.text = item.title binding.tvDetailRetroBody.text = item.content } @@ -33,7 +34,7 @@ class DetailRetroAdapter() : companion object { private val diffCallback = - ItemDiffCallback( + ItemDiffCallback( onContentsTheSame = { old, new -> old == new }, onItemsTheSame = { old, new -> old == new }, ) diff --git a/app/src/main/java/com/puzzling/puzzlingaos/presentation/detailRetrospect/DetailRetroFragment.kt b/app/src/main/java/com/puzzling/puzzlingaos/presentation/detailRetrospect/DetailRetroFragment.kt index 77d9a8f9..cc67a567 100644 --- a/app/src/main/java/com/puzzling/puzzlingaos/presentation/detailRetrospect/DetailRetroFragment.kt +++ b/app/src/main/java/com/puzzling/puzzlingaos/presentation/detailRetrospect/DetailRetroFragment.kt @@ -37,7 +37,7 @@ class DetailRetroFragment( for (data in dataList) { if (day == data.reviewDay) { binding.rcvDetailRetroMain.adapter = detailRetroAdapter - detailRetroAdapter.submitList(data.conte) + detailRetroAdapter.submitList(data.content) } } } diff --git a/app/src/main/java/com/puzzling/puzzlingaos/presentation/detailRetrospect/DetailRetroViewModel.kt b/app/src/main/java/com/puzzling/puzzlingaos/presentation/detailRetrospect/DetailRetroViewModel.kt index 4c785bcc..4d481bf3 100644 --- a/app/src/main/java/com/puzzling/puzzlingaos/presentation/detailRetrospect/DetailRetroViewModel.kt +++ b/app/src/main/java/com/puzzling/puzzlingaos/presentation/detailRetrospect/DetailRetroViewModel.kt @@ -5,7 +5,7 @@ import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.puzzling.puzzlingaos.data.model.response.ResponseDetailRetroDto +import com.puzzling.puzzlingaos.domain.entity.DetailRetro import com.puzzling.puzzlingaos.domain.repository.MyPageRepository import com.puzzling.puzzlingaos.util.UserInfo import dagger.hilt.android.lifecycle.HiltViewModel @@ -17,8 +17,8 @@ import javax.inject.Inject @HiltViewModel class DetailRetroViewModel @Inject constructor(private val repository: MyPageRepository) : ViewModel() { - private val _detailRetroList = MutableLiveData?>() - val detailRetroList: LiveData?> get() = _detailRetroList + private val _detailRetroList = MutableLiveData?>() + val detailRetroList: LiveData?> get() = _detailRetroList val week = listOf( "월", @@ -38,17 +38,13 @@ class DetailRetroViewModel @Inject constructor(private val repository: MyPageRep val projectName = MutableLiveData() fun getDetailRetro(projectId: Int) = viewModelScope.launch { - kotlin.runCatching { - Log.d("상세회고조회", "startOfWeek:: $startOfWeek") - Log.d("상세회고조회", "endOfWeek:: $endOfWeek") - repository.getMyDetailReview( - UserInfo.GET_MEMBER_ID, - projectId, - startOfWeek.toString(), - endOfWeek.toString(), - ) - }.onSuccess { response -> - _detailRetroList.value = response.data?.reviews + repository.getMyDetailReview( + UserInfo.GET_MEMBER_ID, + projectId, + startOfWeek.toString(), + endOfWeek.toString(), + ).onSuccess { response -> + _detailRetroList.value = response Log.d("상세회고조회", "response:: $response") }.onFailure { Log.d("상세회고조회", "fail:: $it")