-
Notifications
You must be signed in to change notification settings - Fork 1
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
[FIX] 서버 통신에 성공한 경우에만 스크랩 갱신시키도록 변경 #320
Changes from all commits
555fee1
65413b0
5344fa1
781d10f
ffda301
ebb56b8
62e239c
4455231
26ca341
9a1fa3b
3a1bb9e
254bf78
c0d4150
1545b38
da67bfb
b8852f2
c7b1f90
b3b728b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,55 @@ | ||
package com.runnect.runnect.data.dto.response | ||
|
||
|
||
import com.runnect.runnect.domain.entity.MyScrapCourse | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ResponseGetMyScrapCourse( | ||
@SerialName("data") | ||
val data: Data, | ||
@SerialName("message") | ||
val message: String, | ||
@SerialName("status") | ||
val status: Int, | ||
@SerialName("success") | ||
val success: Boolean, | ||
@SerialName("user") | ||
val user: User, | ||
@SerialName("scraps") | ||
val scraps: List<Scrap>, | ||
) { | ||
@Serializable | ||
data class Data( | ||
@SerialName("Scraps") | ||
val scraps: List<Scrap>, | ||
@SerialName("user") | ||
val user: User, | ||
data class User( | ||
@SerialName("userId") | ||
val id: Int, | ||
) | ||
|
||
@Serializable | ||
data class Scrap( | ||
@SerialName("courseId") | ||
val courseId: Int, | ||
@SerialName("departure") | ||
val departure: Departure, | ||
@SerialName("id") | ||
val id: Int, | ||
@SerialName("image") | ||
val image: String, | ||
@SerialName("publicCourseId") | ||
val publicCourseId: Int, | ||
@SerialName("title") | ||
val title: String, | ||
) { | ||
@Serializable | ||
data class Scrap( | ||
@SerialName("courseId") | ||
val courseId: Int, | ||
@SerialName("departure") | ||
val departure: Departure, | ||
@SerialName("id") | ||
val id: Int, | ||
@SerialName("image") | ||
val image: String, | ||
@SerialName("publicCourseId") | ||
val publicCourseId: Int, | ||
@SerialName("title") | ||
val title: String, | ||
) { | ||
@Serializable | ||
data class Departure( | ||
@SerialName("city") | ||
val city: String, | ||
@SerialName("region") | ||
val region: String, | ||
) | ||
} | ||
data class Departure( | ||
@SerialName("city") | ||
val city: String, | ||
@SerialName("region") | ||
val region: String, | ||
) | ||
} | ||
|
||
@Serializable | ||
data class User( | ||
@SerialName("id") | ||
val id: Int, | ||
fun toMyScrapCourses(): List<MyScrapCourse> = scraps.map { course -> | ||
MyScrapCourse( | ||
courseId = course.courseId, | ||
id = course.id, | ||
publicCourseId = course.publicCourseId, | ||
image = course.image, | ||
city = course.departure.city, | ||
region = course.departure.region, | ||
title = course.title | ||
) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -367,8 +367,7 @@ class CourseDetailActivity : | |
return@setOnClickListener | ||
} | ||
|
||
it.isSelected = !it.isSelected | ||
viewModel.postCourseScrap(publicCourseId, it.isSelected) | ||
viewModel.postCourseScrap(publicCourseId, !it.isSelected) | ||
} | ||
} | ||
|
||
|
@@ -589,8 +588,18 @@ class CourseDetailActivity : | |
|
||
private fun setupCourseScrapStateObserver() { | ||
viewModel.courseScrapState.observe(this) { state -> | ||
if (state is UiStateV2.Failure) { | ||
showSnackbar(binding.root, state.msg) | ||
when (state) { | ||
is UiStateV2.Success -> { | ||
val response = state.data ?: return@observe | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기 null 처리 setupMyScrapCourseGetStateObserver()처럼 뷰모델에서 하는 건 어떨까요? 통일이 되면 좋을 것 같습니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 응답값이 널일 때 어떻게 처리할 것인지에 대한 논의가 미리 진행되지 않아서, 이런 식으로 그냥 리턴을 해버리는 코드도 상당히 많은 거 같아요..! 이런 코드들도 우남님이 말하신 것처럼 뷰모델에서 널체크 하고 UiState Failure 처리하는 것으로 수정이 필요할 거 같습니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CourseDetailViewModel에서 대부분의 서버통신 코드가 널처리를 따로 하지 않고 그냥 nullable한 응답값을 프래그먼트로 보내는 방식이어서, 코드의 수정사항이 많을 것으로 예상됩니다. 배포 후에 별도 브랜치에서 리팩토링 진행할게요! |
||
binding.tvCourseDetailScrapCount.text = response.scrapCount.toString() | ||
binding.ivCourseDetailScrap.isSelected = response.scrapTF | ||
} | ||
|
||
is UiStateV2.Failure -> { | ||
showSnackbar(binding.root, state.msg) | ||
} | ||
|
||
else -> {} | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이제 보니 id가 3개나 되니까 각각이 뭔지 잘 모르겠고 너무 헷갈리는군여
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저도 처음에는 헷갈렸는데 어느정도 패턴이 있어서 적응이 되더라구요 😅