add latest manga

This commit is contained in:
Aria Moradi 2021-01-19 14:47:25 +03:30
parent f085f26d10
commit fade116a02
2 changed files with 25 additions and 1 deletions

View File

@ -66,6 +66,10 @@ class Main {
val sourceId = ctx.pathParam("source_id")
ctx.json(getPopularManga(sourceId))
}
app.get("/api/v1/source/:source_id/latest") { ctx ->
val sourceId = ctx.pathParam("source_id")
ctx.json(getLatestManga(sourceId))
}
}

View File

@ -1,7 +1,6 @@
package ir.armor.tachidesk.util
import ir.armor.tachidesk.database.dataclass.MangaDataClass
import ir.armor.tachidesk.database.entity.SourceEntity
import ir.armor.tachidesk.database.table.MangaStatus
fun getPopularManga(sourceId: String): List<MangaDataClass> {
@ -16,6 +15,27 @@ fun getPopularManga(sourceId: String): List<MangaDataClass> {
it.initialized,
it.artist,
it.author,
it.description,
it.genre,
MangaStatus.values().first { that -> it.status == that.status }.name,
)
}
}
fun getLatestManga(sourceId: String): List<MangaDataClass> {
val manguasPage = getHttpSource(sourceId.toLong()).fetchLatestUpdates(1).toBlocking().first()
return manguasPage.mangas.map {
MangaDataClass(
sourceId.toLong(),
it.url,
it.title,
it.thumbnail_url,
it.initialized,
it.artist,
it.author,
it.description,