diff --git a/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/BookController.kt b/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/BookController.kt index 43753a4c3..74260eae5 100644 --- a/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/BookController.kt +++ b/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/BookController.kt @@ -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 diff --git a/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/SeriesController.kt b/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/SeriesController.kt index d49f63bb9..04bd86a6d 100644 --- a/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/SeriesController.kt +++ b/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/SeriesController.kt @@ -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 diff --git a/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/Dto.kt b/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/dto/BookDto.kt similarity index 55% rename from komga/src/main/kotlin/org/gotson/komga/interfaces/rest/Dto.kt rename to komga/src/main/kotlin/org/gotson/komga/interfaces/rest/dto/BookDto.kt index 9c9bdcfff..2f91d9f59 100644 --- a/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/Dto.kt +++ b/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/dto/BookDto.kt @@ -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() diff --git a/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/dto/PageDto.kt b/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/dto/PageDto.kt new file mode 100644 index 000000000..942d38ab6 --- /dev/null +++ b/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/dto/PageDto.kt @@ -0,0 +1,7 @@ +package org.gotson.komga.interfaces.rest.dto + +data class PageDto( + val number: Int, + val fileName: String, + val mediaType: String +) diff --git a/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/dto/SeriesDto.kt b/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/dto/SeriesDto.kt new file mode 100644 index 000000000..b9cae2147 --- /dev/null +++ b/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/dto/SeriesDto.kt @@ -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 +) diff --git a/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/dto/Utils.kt b/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/dto/Utils.kt new file mode 100644 index 000000000..c8a506676 --- /dev/null +++ b/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/dto/Utils.kt @@ -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()