From fade116a0225e1d705a68d08887a821dff60acdf Mon Sep 17 00:00:00 2001 From: Aria Moradi Date: Tue, 19 Jan 2021 14:47:25 +0330 Subject: [PATCH] add latest manga --- .../main/kotlin/ir/armor/tachidesk/Main.kt | 4 ++++ .../ir/armor/tachidesk/util/MangaList.kt | 22 ++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/server/src/main/kotlin/ir/armor/tachidesk/Main.kt b/server/src/main/kotlin/ir/armor/tachidesk/Main.kt index a57e56a..95d002c 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/Main.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/Main.kt @@ -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)) + } } diff --git a/server/src/main/kotlin/ir/armor/tachidesk/util/MangaList.kt b/server/src/main/kotlin/ir/armor/tachidesk/util/MangaList.kt index 2e82960..37e485c 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/util/MangaList.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/util/MangaList.kt @@ -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 { @@ -16,6 +15,27 @@ fun getPopularManga(sourceId: String): List { it.initialized, + it.artist, + it.author, + it.description, + it.genre, + MangaStatus.values().first { that -> it.status == that.status }.name, + ) + } +} + +fun getLatestManga(sourceId: String): List { + 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,