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

View File

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

View File

@@ -10,12 +10,21 @@ package ir.armor.tachidesk.model.dataclass
data class ChapterDataClass( data class ChapterDataClass(
val url: String, val url: String,
val name: String, val name: String,
val date_upload: Long, val uploadDate: Long,
val chapter_number: Float, val chapterNumber: Float,
val scanlator: String?, val scanlator: String?,
val mangaId: Int, 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, val chapterIndex: Int? = null,
/** total chapter count, used to calculate if there's a next and prev chapter */ /** total chapter count, used to calculate if there's a next and prev chapter */