inline manga update

This commit is contained in:
Cuong-Tran 2024-11-21 01:09:11 +07:00
parent fd742d51e3
commit b8997ecbc8
No known key found for this signature in database
GPG Key ID: 733AA7624B9315C2

View File

@ -17,7 +17,13 @@ class NetworkToLocalManga(
} }
!localManga.favorite -> { !localManga.favorite -> {
// if the manga isn't a favorite, update new info from source to db // if the manga isn't a favorite, update new info from source to db
manga.updateManga(localManga.id) mangaRepository.update(
manga.toMangaUpdate()
.copy(
id = localManga.id,
thumbnailUrl = manga.thumbnailUrl?.takeIf { it.isNotBlank() },
),
)
manga.copy(id = localManga.id) manga.copy(id = localManga.id)
} }
else -> { else -> {
@ -33,14 +39,4 @@ class NetworkToLocalManga(
private suspend fun insertManga(manga: Manga): Long? { private suspend fun insertManga(manga: Manga): Long? {
return mangaRepository.insert(manga) return mangaRepository.insert(manga)
} }
private suspend fun Manga.updateManga(id: Long) {
mangaRepository.update(
toMangaUpdate()
.copy(
id = id,
thumbnailUrl = thumbnailUrl?.takeIf { it.isNotBlank() },
),
)
}
} }