zaimanhua: update MangaDto and PageItemDto to handle nullable fields (#10111)

Co-authored-by: stevenyomi <95685115+stevenyomi@users.noreply.github.com>
This commit is contained in:
zhongfly 2025-08-14 22:37:55 +08:00 committed by Draff
parent 3a62d41476
commit 1e8fec699c
Signed by: Draff
GPG Key ID: E8A89F3211677653

View File

@ -11,25 +11,25 @@ import kotlinx.serialization.json.JsonNames
class MangaDto( class MangaDto(
private val id: Int, private val id: Int,
private val title: String, private val title: String,
private val cover: String, private val cover: String?,
private val description: String? = null, private val description: String?,
private val types: List<TagDto>, private val types: List<TagDto>?,
private val status: List<TagDto>, private val status: List<TagDto>?,
private val authors: List<TagDto>? = null, private val authors: List<TagDto>?,
@SerialName("chapters") @SerialName("chapters")
private val chapterGroups: List<ChapterGroupDto>, private val chapterGroups: List<ChapterGroupDto>,
@SerialName("last_update_chapter_id") @SerialName("last_update_chapter_id")
private val lastUpdateChapterId: Int = 0, private val lastUpdateChapterId: Int,
@SerialName("last_updatetime") @SerialName("last_updatetime")
private val lastUpdateTime: Long = 0, private val lastUpdateTime: Long,
) { ) {
fun toSManga() = SManga.create().apply { fun toSManga() = SManga.create().apply {
url = id.toString() url = id.toString()
title = this@MangaDto.title title = this@MangaDto.title
author = authors?.joinToString { it.name } author = authors?.joinToString { it.name }
description = this@MangaDto.description description = this@MangaDto.description
genre = types.joinToString { it.name } genre = types?.joinToString { it.name }
status = parseStatus(this@MangaDto.status[0].name) status = parseStatus(this@MangaDto.status?.firstOrNull()?.name.orEmpty())
thumbnail_url = cover thumbnail_url = cover
initialized = true initialized = true
} }
@ -80,12 +80,12 @@ class ChapterDto(
@SerialName("chapter_title") @SerialName("chapter_title")
private val name: String, private val name: String,
@SerialName("updatetime") @SerialName("updatetime")
private val updateTime: Long = 0, private val updateTime: Long?,
) { ) {
fun toSChapterInternal() = SChapter.create().apply { fun toSChapterInternal() = SChapter.create().apply {
url = id.toString() url = id.toString()
name = this@ChapterDto.name.formatChapterName() name = this@ChapterDto.name.formatChapterName()
date_upload = updateTime * 1000 date_upload = updateTime?.times(1000) ?: 0L
} }
} }
@ -112,25 +112,21 @@ class PageDto(
@Serializable @Serializable
class PageItemDto( class PageItemDto(
private val id: Int = 0, private val id: Int?,
@SerialName("comic_id") @SerialName("comic_id")
private val comicId: Int = 0, private val comicId: Int,
private val title: String, private val title: String,
private val authors: String = "", private val authors: String?,
private val status: String, private val status: String?,
private val cover: String, private val cover: String?,
private val types: String, private val types: String?,
) { ) {
fun toSManga() = SManga.create().apply { fun toSManga() = SManga.create().apply {
url = if (this@PageItemDto.id != 0) { url = (this@PageItemDto.id?.takeIf { it != 0 } ?: this@PageItemDto.comicId).toString()
this@PageItemDto.id.toString()
} else {
this@PageItemDto.comicId.toString()
}
title = this@PageItemDto.title title = this@PageItemDto.title
author = authors.formatList() author = authors?.formatList()
genre = types.formatList() genre = types?.formatList()
status = parseStatus(this@PageItemDto.status) status = parseStatus(this@PageItemDto.status ?: "")
thumbnail_url = cover thumbnail_url = cover
} }
} }
@ -159,12 +155,12 @@ class DataWrapperDto<T>(
@Serializable @Serializable
class SimpleResponseDto( class SimpleResponseDto(
val errno: Int = 0, val errno: Int? = 0,
) )
@Serializable @Serializable
class ResponseDto<T>( class ResponseDto<T>(
val errno: Int = 0, val errno: Int? = 0,
val errmsg: String = "", val errmsg: String = "",
val data: T, val data: T,
) )