Skip to content

Commit

Permalink
[REFACTOR/Team-Puzzling#68] 프로젝트 회고조회 api Dto -> Entity
Browse files Browse the repository at this point in the history
  • Loading branch information
gaeun5744 committed Sep 4, 2023
1 parent fc99262 commit 783ebae
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 37 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.ProjectReview
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

Expand All @@ -12,7 +13,7 @@ data class ResponseMyRetroListDto(
@SerialName("message")
val message: String,
@SerialName("data")
val data: List<ReviewData>?,
val data: List<ReviewData>,
) {
@Serializable
data class ReviewData(
Expand All @@ -23,5 +24,12 @@ data class ResponseMyRetroListDto(
@SerialName("contents")
val contents: String,
)
}

fun toProjectReview() = data.map { reviewData ->
ProjectReview(
reviewData.reviewId,
reviewData.reviewDate,
reviewData.contents,
)
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package com.puzzling.puzzlingaos.data.repository

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.entity.ProjectReview
import com.puzzling.puzzlingaos.domain.repository.MyPageRepository
import javax.inject.Inject

class MyPageRepositoryImpl @Inject constructor(private val myPageDataSource: MyPageDataSource) :
MyPageRepository {
override suspend fun getMyProjectReview(memberId: Int, projectId: Int): ResponseMyRetroListDto {
return myPageDataSource.getMyProjectReview(memberId, projectId)
}
override suspend fun getMyProjectReview(
memberId: Int,
projectId: Int,
): Result<List<ProjectReview>> =
runCatching {
myPageDataSource.getMyProjectReview(memberId, projectId).toProjectReview()
}

override suspend fun getMyDetailReview(
memberId: Int,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.puzzling.puzzlingaos.domain.entity

data class ProjectReview(
val reviewId: Int,
val reviewDate: String,
val contents: String,
)
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.puzzling.puzzlingaos.domain.repository

import com.puzzling.puzzlingaos.data.model.response.ResponseMyRetroListDto
import com.puzzling.puzzlingaos.domain.entity.DetailRetro
import com.puzzling.puzzlingaos.domain.entity.ProjectReview

interface MyPageRepository {

suspend fun getMyProjectReview(
memberId: Int,
projectId: Int,
): ResponseMyRetroListDto
): Result<List<ProjectReview>>

suspend fun getMyDetailReview(
memberId: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import androidx.recyclerview.widget.ConcatAdapter
import androidx.recyclerview.widget.LinearLayoutManager
import com.puzzling.puzzlingaos.R
import com.puzzling.puzzlingaos.base.BaseFragment
import com.puzzling.puzzlingaos.data.model.response.ResponseMyRetroListDto
import com.puzzling.puzzlingaos.databinding.FragmentMyRetrospectBinding
import com.puzzling.puzzlingaos.domain.entity.ProjectReview
import com.puzzling.puzzlingaos.presentation.detailRetrospect.DetailRetroActivity
import com.puzzling.puzzlingaos.presentation.mypage.adapter.MyRetroContentAdapter
import com.puzzling.puzzlingaos.presentation.mypage.adapter.MyRetroTitleAdapter
Expand All @@ -24,25 +24,12 @@ class MyRetrospectFragment :
private lateinit var viewModel: MyRetrospectViewModel
private var currentTitle = "piikle"

private val dummyItemList = mutableListOf(
ResponseMyRetroListDto.ReviewData(23, "2023-07-12", "여기는 20글자 정도 노출되고,,"),
ResponseMyRetroListDto.ReviewData(
12,
"2023-07-24",
"유저가 회고 템플릿에서 가장 첫 번째 인풋창에 입력한 값 노출.. ",
),
ResponseMyRetroListDto.ReviewData(5, "2023-07-27", "여기는18글자정도노출되고나머지부분..."),
ResponseMyRetroListDto.ReviewData(7, "2023-07-5", "여기는18글자정도노출되고나머지부분..."),
ResponseMyRetroListDto.ReviewData(8, "2023-08-02", "여기는18글자정도노출되고나머지부분..."),
ResponseMyRetroListDto.ReviewData(10, "2023-06-22", "여기는18글자정도노출되고나머지부분..."),
)

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

viewModel = ViewModelProvider(requireActivity())[MyRetrospectViewModel::class.java]
viewModel.currentProject.observe(this) {
Log.d("myPage 회고 뷰", "${it}")
Log.d("myPage 회고 뷰", "$it")
viewModel.getMyProjectReview(it.projectId)
}
initToolbar()
Expand Down Expand Up @@ -84,7 +71,7 @@ class MyRetrospectFragment :

myRetroContentAdapter.setOnItemClickListener(object :
MyRetroContentAdapter.OnItemClickListener {
override fun onItemClick(v: View, item: ResponseMyRetroListDto.ReviewData, pos: Int) {
override fun onItemClick(v: View, item: ProjectReview, pos: Int) {
val intent = Intent(activity, DetailRetroActivity::class.java)
intent.putExtra("Title", viewModel.currentProject.value?.projectName)
intent.putExtra("homeProjectId", viewModel.currentProject.value?.projectId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.puzzling.puzzlingaos.data.model.response.ResponseMyRetroListDto
import com.puzzling.puzzlingaos.data.model.response.ResponseProjectRetroWeekDto
import com.puzzling.puzzlingaos.domain.entity.Project
import com.puzzling.puzzlingaos.domain.entity.ProjectReview
import com.puzzling.puzzlingaos.domain.repository.MyBoardRepository
import com.puzzling.puzzlingaos.domain.repository.MyPageRepository
import com.puzzling.puzzlingaos.domain.repository.ProjectRepository
Expand All @@ -23,8 +23,8 @@ class MyRetrospectViewModel @Inject constructor(
) :
ViewModel() {

private val _responseReview = MutableLiveData<List<ResponseMyRetroListDto.ReviewData>?>()
val responseReveiew: LiveData<List<ResponseMyRetroListDto.ReviewData>?> get() = _responseReview
private val _responseReview = MutableLiveData<List<ProjectReview>?>()
val responseReveiew: LiveData<List<ProjectReview>?> get() = _responseReview

private var _responseProjectList: MutableLiveData<List<Project>> = MutableLiveData()
val responseProjectList: LiveData<List<Project>>
Expand All @@ -37,10 +37,8 @@ class MyRetrospectViewModel @Inject constructor(
val retroWeek: LiveData<ResponseProjectRetroWeekDto.ProjectCycle?> get() = _retroWeek

fun getMyProjectReview(selectedProjectId: Int) = viewModelScope.launch {
kotlin.runCatching {
myPageRepository.getMyProjectReview(1, selectedProjectId)
}.onSuccess { response ->
_responseReview.value = response.data
myPageRepository.getMyProjectReview(1, selectedProjectId).onSuccess { response ->
_responseReview.value = response
Log.d("MyProjectRetro", "$response")
}.onFailure {
Log.d("MyProjectRetro", "$it")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.puzzling.puzzlingaos.data.model.response.ResponseMyRetroListDto
import com.puzzling.puzzlingaos.databinding.ItemMyretroRetroBinding
import com.puzzling.puzzlingaos.domain.entity.ProjectReview
import com.puzzling.puzzlingaos.util.ItemDiffCallback

class MyRetroContentAdapter() :
ListAdapter<ResponseMyRetroListDto.ReviewData, MyRetroContentAdapter.MyRetroContenViewHolder>(
ListAdapter<ProjectReview, MyRetroContentAdapter.MyRetroContenViewHolder>(
diffCallback,
) {

Expand All @@ -28,7 +28,7 @@ class MyRetroContentAdapter() :

inner class MyRetroContenViewHolder(private val binding: ItemMyretroRetroBinding) :
RecyclerView.ViewHolder(binding.root) {
fun onBind(item: ResponseMyRetroListDto.ReviewData) {
fun onBind(item: ProjectReview) {
binding.tvMyretroDate.text = item.reviewDate

if (item.contents.length < 17) {
Expand All @@ -40,14 +40,14 @@ class MyRetroContentAdapter() :

if (bindingAdapterPosition != RecyclerView.NO_POSITION) {
binding.clMyRetroContainer.setOnClickListener {
listener?.onItemClick(itemView,item, bindingAdapterPosition)
listener?.onItemClick(itemView, item, bindingAdapterPosition)
}
}
}
}

interface OnItemClickListener {
fun onItemClick(v: View, item:ResponseMyRetroListDto.ReviewData, pos: Int)
fun onItemClick(v: View, item: ProjectReview, pos: Int)
}

fun setOnItemClickListener(listener: OnItemClickListener) {
Expand All @@ -56,7 +56,7 @@ class MyRetroContentAdapter() :

companion object {
private val diffCallback =
ItemDiffCallback<ResponseMyRetroListDto.ReviewData>(
ItemDiffCallback<ProjectReview>(
onContentsTheSame = { old, new -> old == new },
onItemsTheSame = { old, new -> old == new },
)
Expand Down

0 comments on commit 783ebae

Please sign in to comment.