Skip to content

Commit

Permalink
fix: failure to get series if no items (#749)
Browse files Browse the repository at this point in the history
If there was no items in a series list (such as anime), then the call to retrieve the series would
fail. Instead make it return an empty list but still a successful request. This fixes the issue of
if a user has only anime in their library, or only manga.

fix #746
  • Loading branch information
Chesire authored Apr 9, 2022
1 parent 4e7e295 commit 7dd0fc5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
3 changes: 0 additions & 3 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,7 @@ class KitsuLibrary @Inject constructor(

val body = response.body()
if (response.isSuccessful && body != null) {
val series = body.data.mapNotNull {
map.toSeriesDomain(AddResponseDto(it, body.included))
}
models.addAll(series)
models.addAll(buildSeries(body))
retries = 0

if (body.links.next.isNotEmpty()) {
Expand All @@ -167,6 +164,16 @@ class KitsuLibrary @Inject constructor(
}
}

private fun buildSeries(body: RetrieveResponseDto): List<SeriesDomain> {
return body.data.mapNotNull {
if (body.included == null) {
null
} else {
map.toSeriesDomain(AddResponseDto(it, body.included))
}
}
}

private fun parseResponse(response: Response<AddResponseDto>): Resource<SeriesDomain> {
return if (response.isSuccessful) {
response.body()?.let { entity ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ data class RetrieveResponseDto(
@Json(name = "data")
val data: List<DataDto>,
@Json(name = "included")
val included: List<IncludedDto>,
val included: List<IncludedDto>?,
@Json(name = "links")
val links: Links
)

0 comments on commit 7dd0fc5

Please sign in to comment.