mirror of
https://github.com/gotson/komga.git
synced 2026-01-19 14:41:30 +01:00
refactor: move DTOs to their own package
This commit is contained in:
parent
05a6818c2b
commit
f19d03903c
6 changed files with 52 additions and 38 deletions
|
|
@ -13,6 +13,9 @@ import org.gotson.komga.domain.service.AsyncOrchestrator
|
|||
import org.gotson.komga.domain.service.BookLifecycle
|
||||
import org.gotson.komga.infrastructure.image.ImageType
|
||||
import org.gotson.komga.infrastructure.security.KomgaPrincipal
|
||||
import org.gotson.komga.interfaces.rest.dto.BookDto
|
||||
import org.gotson.komga.interfaces.rest.dto.PageDto
|
||||
import org.gotson.komga.interfaces.rest.dto.toDto
|
||||
import org.springframework.data.domain.Page
|
||||
import org.springframework.data.domain.PageRequest
|
||||
import org.springframework.data.domain.Pageable
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@ import org.gotson.komga.domain.persistence.LibraryRepository
|
|||
import org.gotson.komga.domain.persistence.SeriesRepository
|
||||
import org.gotson.komga.domain.service.AsyncOrchestrator
|
||||
import org.gotson.komga.infrastructure.security.KomgaPrincipal
|
||||
import org.gotson.komga.interfaces.rest.dto.BookDto
|
||||
import org.gotson.komga.interfaces.rest.dto.SeriesDto
|
||||
import org.gotson.komga.interfaces.rest.dto.toDto
|
||||
import org.springframework.data.domain.Page
|
||||
import org.springframework.data.domain.PageRequest
|
||||
import org.springframework.data.domain.Pageable
|
||||
|
|
|
|||
|
|
@ -1,37 +1,9 @@
|
|||
package org.gotson.komga.interfaces.rest
|
||||
package org.gotson.komga.interfaces.rest.dto
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat
|
||||
import org.apache.commons.io.FilenameUtils
|
||||
import org.gotson.komga.domain.model.Book
|
||||
import org.gotson.komga.domain.model.Series
|
||||
import java.time.LocalDateTime
|
||||
import java.time.ZoneId
|
||||
import java.time.ZoneOffset
|
||||
|
||||
data class SeriesDto(
|
||||
val id: Long,
|
||||
val libraryId: Long,
|
||||
val name: String,
|
||||
val url: String,
|
||||
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
|
||||
val created: LocalDateTime?,
|
||||
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
|
||||
val lastModified: LocalDateTime?,
|
||||
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
|
||||
val fileLastModified: LocalDateTime,
|
||||
val booksCount: Int
|
||||
)
|
||||
|
||||
fun Series.toDto(includeUrl: Boolean) = SeriesDto(
|
||||
id = id,
|
||||
libraryId = library.id,
|
||||
name = name,
|
||||
url = if (includeUrl) url.toURI().path else "",
|
||||
created = createdDate?.toUTC(),
|
||||
lastModified = lastModifiedDate?.toUTC(),
|
||||
fileLastModified = fileLastModified.toUTC(),
|
||||
booksCount = books.size
|
||||
)
|
||||
|
||||
data class BookDto(
|
||||
val id: Long,
|
||||
|
|
@ -76,12 +48,3 @@ fun Book.toDto(includeFullUrl: Boolean) =
|
|||
comment = media.comment ?: ""
|
||||
)
|
||||
)
|
||||
|
||||
data class PageDto(
|
||||
val number: Int,
|
||||
val fileName: String,
|
||||
val mediaType: String
|
||||
)
|
||||
|
||||
fun LocalDateTime.toUTC(): LocalDateTime =
|
||||
atZone(ZoneId.systemDefault()).withZoneSameInstant(ZoneOffset.UTC).toLocalDateTime()
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package org.gotson.komga.interfaces.rest.dto
|
||||
|
||||
data class PageDto(
|
||||
val number: Int,
|
||||
val fileName: String,
|
||||
val mediaType: String
|
||||
)
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package org.gotson.komga.interfaces.rest.dto
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat
|
||||
import org.gotson.komga.domain.model.Series
|
||||
import java.time.LocalDateTime
|
||||
|
||||
data class SeriesDto(
|
||||
val id: Long,
|
||||
val libraryId: Long,
|
||||
val name: String,
|
||||
val url: String,
|
||||
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
|
||||
val created: LocalDateTime?,
|
||||
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
|
||||
val lastModified: LocalDateTime?,
|
||||
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
|
||||
val fileLastModified: LocalDateTime,
|
||||
val booksCount: Int
|
||||
)
|
||||
|
||||
fun Series.toDto(includeUrl: Boolean) = SeriesDto(
|
||||
id = id,
|
||||
libraryId = library.id,
|
||||
name = name,
|
||||
url = if (includeUrl) url.toURI().path else "",
|
||||
created = createdDate?.toUTC(),
|
||||
lastModified = lastModifiedDate?.toUTC(),
|
||||
fileLastModified = fileLastModified.toUTC(),
|
||||
booksCount = books.size
|
||||
)
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package org.gotson.komga.interfaces.rest.dto
|
||||
|
||||
import java.time.LocalDateTime
|
||||
import java.time.ZoneId
|
||||
import java.time.ZoneOffset
|
||||
|
||||
fun LocalDateTime.toUTC(): LocalDateTime =
|
||||
atZone(ZoneId.systemDefault()).withZoneSameInstant(ZoneOffset.UTC).toLocalDateTime()
|
||||
Loading…
Reference in a new issue