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

[AN/USER] fix: 상세 화면 축제 목록 요청 로직 변경 및 Throwable 예외 처리 제거(#986) #987

Merged
merged 9 commits into from
May 20, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,5 @@ private fun <T> handleBadRequestException(response: Response<T>) {
throw BookmarkLimitExceededException()
}
}
throw Throwable("400 Bad Request")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ class ArtistDetailViewModel @Inject constructor(
runCatching {
val deferredArtistDetail =
async { artistRepository.loadArtistDetail(id, delayTimeMillis) }
val deferredFestivals = async { artistRepository.loadArtistFestivals(id, 10) }
val deferredFestivals = async {
artistRepository.loadArtistFestivals(id = id, size = FESTIVAL_PAGE_SIZE)
}

val artist = deferredArtistDetail.await().getOrThrow()
val festivalPage = deferredFestivals.await().getOrThrow()

Expand Down Expand Up @@ -89,18 +92,19 @@ class ArtistDetailViewModel @Inject constructor(

viewModelScope.launch {
val currentFestivals = successUiState.festivals
val lastItem = successUiState.festivals.lastOrNull()
val isPast = when {
lastItem == null -> true
lastItem.endDate < LocalDate.now() -> true
successUiState.isLast -> true
else -> false
}
val lastItem = currentFestivals.lastOrNull()
val isPast =
lastItem?.endDate?.isBefore(LocalDate.now()) ?: true || successUiState.isLast

val lastFestivalId = if (successUiState.isLast) null else lastItem?.id
val lastStartDate = if (successUiState.isLast) null else lastItem?.startDate

artistRepository.loadArtistFestivals(
id = artistId,
lastFestivalId = currentFestivals.lastOrNull()?.id,
lastStartDate = currentFestivals.lastOrNull()?.startDate,
lastFestivalId = lastFestivalId,
lastStartDate = lastStartDate,
isPast = isPast,
size = FESTIVAL_PAGE_SIZE,
).onSuccess { festivalsPage ->
_uiState.value = successUiState.copy(
festivals = currentFestivals + festivalsPage.toUiState(),
Expand Down Expand Up @@ -189,6 +193,7 @@ class ArtistDetailViewModel @Inject constructor(
}

companion object {
private const val FESTIVAL_PAGE_SIZE = 20
private const val KEY_LOAD_ARTIST_DETAIL = "KEY_LOAD_ARTIST_DETAIL"
private const val KEY_LOAD_MORE_ARTIST_FESTIVAL = "KEY_LOAD_MORE_ARTIST_FESTIVAL"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ class SchoolDetailViewModel @Inject constructor(
viewModelScope.launch {
val deferredSchoolInfo =
async { schoolRepository.loadSchoolInfo(schoolId, delayTimeMillis) }
val deferredFestivalPage = async { schoolRepository.loadSchoolFestivals(schoolId) }
val deferredFestivalPage = async {
schoolRepository.loadSchoolFestivals(schoolId = schoolId, size = FESTIVAL_PAGE_SIZE)
}

runCatching {
val schoolInfo = deferredSchoolInfo.await().getOrThrow()
Expand Down Expand Up @@ -87,18 +89,17 @@ class SchoolDetailViewModel @Inject constructor(

viewModelScope.launch {
val currentFestivals = successUiState.festivals
val lastItem = successUiState.festivals.lastOrNull()
val isPast = when {
lastItem == null -> true
lastItem.endDate > LocalDate.now() -> true
successUiState.isLast -> true
else -> false
}
val lastItem = currentFestivals.lastOrNull()
val isPast =
lastItem?.endDate?.isBefore(LocalDate.now()) ?: true || successUiState.isLast
val lastFestivalId = if (successUiState.isLast) null else lastItem?.id
val lastStartDate = if (successUiState.isLast) null else lastItem?.startDate
schoolRepository.loadSchoolFestivals(
schoolId = schoolId,
lastFestivalId = currentFestivals.lastOrNull()?.id?.toInt(),
lastStartDate = currentFestivals.lastOrNull()?.startDate,
lastFestivalId = lastFestivalId?.toInt(),
lastStartDate = lastStartDate,
isPast = isPast,
size = FESTIVAL_PAGE_SIZE,
).onSuccess { festivalsPage ->
_uiState.value = successUiState.copy(
festivals = currentFestivals + festivalsPage.festivals.map { it.toUiState() },
Expand Down Expand Up @@ -185,6 +186,7 @@ class SchoolDetailViewModel @Inject constructor(
)

companion object {
private const val FESTIVAL_PAGE_SIZE = 20
private const val KEY_LOAD_SCHOOL_DETAIL = "KEY_LOAD_SCHOOL_DETAIL"
private const val KEY_LOAD_MORE_SCHOOL_FESTIVALS = "KEY_LOAD_MORE_SCHOOL_FESTIVALS"
}
Expand Down
Loading