mirror of
https://github.com/gotson/komga.git
synced 2025-01-09 04:08:00 +08:00
feat(api): mark read progress for series with Tachiyomi format
This commit is contained in:
parent
94720b49c1
commit
82af4b3bbf
@ -35,6 +35,7 @@ import org.gotson.komga.interfaces.rest.dto.BookDto
|
||||
import org.gotson.komga.interfaces.rest.dto.CollectionDto
|
||||
import org.gotson.komga.interfaces.rest.dto.SeriesDto
|
||||
import org.gotson.komga.interfaces.rest.dto.SeriesMetadataUpdateDto
|
||||
import org.gotson.komga.interfaces.rest.dto.TachiyomiReadProgressUpdateDto
|
||||
import org.gotson.komga.interfaces.rest.dto.restrictUrl
|
||||
import org.gotson.komga.interfaces.rest.dto.toDto
|
||||
import org.gotson.komga.interfaces.rest.persistence.BookDtoRepository
|
||||
@ -363,6 +364,29 @@ class SeriesController(
|
||||
}
|
||||
}
|
||||
|
||||
@PatchMapping("{seriesId}/read-progress/tachiyomi")
|
||||
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||
fun markReadProgress(
|
||||
@PathVariable seriesId: String,
|
||||
@Valid @RequestBody readProgress: TachiyomiReadProgressUpdateDto,
|
||||
@AuthenticationPrincipal principal: KomgaPrincipal
|
||||
) {
|
||||
seriesRepository.getLibraryId(seriesId)?.let {
|
||||
if (!principal.user.canAccessLibrary(it)) throw ResponseStatusException(HttpStatus.FORBIDDEN)
|
||||
} ?: throw ResponseStatusException(HttpStatus.NOT_FOUND)
|
||||
|
||||
bookDtoRepository.findAll(
|
||||
BookSearchWithReadProgress(seriesIds = listOf(seriesId)),
|
||||
principal.user.id,
|
||||
UnpagedSorted(Sort.by(Sort.Order.asc("metadata.numberSort"))),
|
||||
).forEachIndexed { index, book ->
|
||||
if (index < readProgress.lastBookRead)
|
||||
bookLifecycle.markReadProgressCompleted(book.id, principal.user)
|
||||
else
|
||||
bookLifecycle.deleteReadProgress(book.id, principal.user)
|
||||
}
|
||||
}
|
||||
|
||||
@DeleteMapping("{seriesId}/read-progress")
|
||||
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||
fun markAsUnread(
|
||||
|
@ -3,6 +3,7 @@ package org.gotson.komga.interfaces.rest.dto
|
||||
import com.fasterxml.jackson.annotation.JsonFormat
|
||||
import java.time.LocalDate
|
||||
import java.time.LocalDateTime
|
||||
import javax.validation.constraints.PositiveOrZero
|
||||
|
||||
data class SeriesDto(
|
||||
val id: String,
|
||||
@ -66,3 +67,7 @@ data class BookMetadataAggregationDto(
|
||||
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
|
||||
val lastModified: LocalDateTime
|
||||
)
|
||||
|
||||
data class TachiyomiReadProgressUpdateDto(
|
||||
@get:PositiveOrZero val lastBookRead: Int,
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user