Skip to content

Commit

Permalink
[REFACTOR/Team-Puzzling#68] 회고상세조회 뷰 Dto -> Entity 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
gaeun5744 committed Sep 3, 2023
1 parent b0e46ac commit 840c52d
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -12,7 +13,7 @@ data class ResponseDetailRetroDto(
@SerialName("message")
val message: String,
@SerialName("data")
val data: Data?,
val data: Data,
) {
@Serializable
data class Data(
Expand Down Expand Up @@ -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)
},

)
}
}
}
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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<List<DetailRetro>> = runCatching {
myPageDataSource.getMyDetailReview(
memberId,
projectId,
startDate,
endDate,
).data.toDetailRetro()
}
}
Original file line number Diff line number Diff line change
@@ -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<Content>?,
) {
data class Content(
val title: String,
val content: String,
)
}
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -15,5 +15,5 @@ interface MyPageRepository {
projectId: Int,
startDate: String,
endDate: String,
): ResponseDetailRetroDto
): Result<List<DetailRetro>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ResponseDetailRetroDto.Data.DetailReviewData.Content, DetailRetroAdapter.DetailRetroViewHolder>(
ListAdapter<DetailRetro.Content, DetailRetroAdapter.DetailRetroViewHolder>(
diffCallback,
) {

Expand All @@ -25,15 +26,15 @@ 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
}
}

companion object {
private val diffCallback =
ItemDiffCallback<ResponseDetailRetroDto.Data.DetailReviewData.Content>(
ItemDiffCallback<DetailRetro.Content>(
onContentsTheSame = { old, new -> old == new },
onItemsTheSame = { old, new -> old == new },
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,8 +17,8 @@ import javax.inject.Inject
@HiltViewModel
class DetailRetroViewModel @Inject constructor(private val repository: MyPageRepository) :
ViewModel() {
private val _detailRetroList = MutableLiveData<List<ResponseDetailRetroDto.Data.DetailReviewData>?>()
val detailRetroList: LiveData<List<ResponseDetailRetroDto.Data.DetailReviewData>?> get() = _detailRetroList
private val _detailRetroList = MutableLiveData<List<DetailRetro>?>()
val detailRetroList: LiveData<List<DetailRetro>?> get() = _detailRetroList

val week = listOf(
"",
Expand All @@ -38,17 +38,13 @@ class DetailRetroViewModel @Inject constructor(private val repository: MyPageRep
val projectName = MutableLiveData<String>()

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")
Expand Down

0 comments on commit 840c52d

Please sign in to comment.