popular manga api done

This commit is contained in:
Aria Moradi 2020-12-25 19:29:48 +03:30
parent f20c51c558
commit c9c96e7d60
2 changed files with 24 additions and 5 deletions

View File

@ -15,7 +15,8 @@ class Main {
val app = Javalin.create().start(4567)
app.before() { ctx ->
ctx.header("Access-Control-Allow-Origin", "*") // allow the client which is running on another port
// allow the client which is running on another port
ctx.header("Access-Control-Allow-Origin", "*")
}
app.get("/api/v1/extension/list") { ctx ->
@ -36,7 +37,7 @@ class Main {
app.get("/api/v1/source/:source_id/popular") { ctx ->
val sourceId = ctx.pathParam("source_id")
// ctx.json(getPopularManga(sourceId))
ctx.json(getPopularManga(sourceId))
}
}
}

View File

@ -2,7 +2,25 @@ 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> {
// SourceEntity.findById(sourceId.toLong())
//}
fun getPopularManga(sourceId: String): List<MangaDataClass> {
val manguasPage = getHttpSource(sourceId.toLong()).fetchPopularManga(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,
it.genre,
MangaStatus.values().first { that -> it.status == that.status }.name,
)
}
}