chapter new parameters get endpoint

This commit is contained in:
Aria Moradi 2021-05-11 15:15:31 +04:30
parent e3d3ec6895
commit 8abb132ad6
3 changed files with 56 additions and 29 deletions

View File

@ -69,9 +69,17 @@ object Chapter {
val dbChapterCount = transaction { ChapterTable.selectAll().count() }
if (dbChapterCount > chapterCount) { // we got some clean up due
// TODO: delete orphan chapters
val dbChapterList = transaction { ChapterTable.selectAll().orderBy() }
}
val dbChapters = transaction { ChapterTable.selectAll() }
.associateBy({ it[ChapterTable.url] }, { it })
chapterList.mapIndexed { index, it ->
val dbChapter = dbChapters.getValue(it.url)
ChapterDataClass(
it.url,
it.name,
@ -79,6 +87,11 @@ object Chapter {
it.chapter_number,
it.scanlator,
mangaId,
dbChapter[ChapterTable.isRead],
dbChapter[ChapterTable.isBookmarked],
dbChapter[ChapterTable.lastPageRead],
chapterCount - index,
)
}
@ -125,6 +138,7 @@ object Chapter {
}
}
return ChapterDataClass(
chapterEntry[ChapterTable.url],
chapterEntry[ChapterTable.name],
@ -132,6 +146,10 @@ object Chapter {
chapterEntry[ChapterTable.chapter_number],
chapterEntry[ChapterTable.scanlator],
mangaId,
chapterEntry[ChapterTable.isRead],
chapterEntry[ChapterTable.isBookmarked],
chapterEntry[ChapterTable.lastPageRead],
chapterEntry[ChapterTable.chapterIndex],
chapterCount.toInt(),
pageList.count()

View File

@ -80,11 +80,11 @@ object LegacyBackupImport : LegacyBackupBase() {
return validationResult
}
private fun restoreCategories(jsonCategories: JsonElement) { // TODO
private fun restoreCategories(jsonCategories: JsonElement) {
val backupCategories = parser.fromJson<List<CategoryImpl>>(jsonCategories)
val dbCategories = getCategoryList()
// Iterate over them
// Iterate over them and create missing categories
backupCategories.forEach { category ->
if (dbCategories.none { it.name == category.name }) {
createCategory(category.name)

View File

@ -10,12 +10,21 @@ package ir.armor.tachidesk.model.dataclass
data class ChapterDataClass(
val url: String,
val name: String,
val date_upload: Long,
val chapter_number: Float,
val uploadDate: Long,
val chapterNumber: Float,
val scanlator: String?,
val mangaId: Int,
/** this chapter's index */
/** chapter is read */
val read: Boolean,
/** chapter is bookmarked */
val bookmarked: Boolean,
/** last read page, zero means not read/no data */
val lastPageRead: Int,
/** this chapter's index, starts with 1 */
val chapterIndex: Int? = null,
/** total chapter count, used to calculate if there's a next and prev chapter */