mirror of
https://github.com/gotson/komga.git
synced 2025-12-22 00:13:30 +01:00
parent
5ff0bfb50d
commit
9218e6bb26
3 changed files with 66 additions and 7 deletions
|
|
@ -364,11 +364,13 @@ class BookController(
|
|||
book.metadata.releaseDate = newMetadata.releaseDate
|
||||
}
|
||||
releaseDateLock?.let { book.metadata.releaseDateLock = it }
|
||||
if (authors != null) {
|
||||
book.metadata.authors = authors!!.map {
|
||||
Author(it.name ?: "", it.role ?: "")
|
||||
}.toMutableList()
|
||||
} else book.metadata.authors = mutableListOf()
|
||||
if (isSet("authors")) {
|
||||
if (authors != null) {
|
||||
book.metadata.authors = authors!!.map {
|
||||
Author(it.name ?: "", it.role ?: "")
|
||||
}.toMutableList()
|
||||
} else book.metadata.authors = mutableListOf()
|
||||
}
|
||||
authorsLock?.let { book.metadata.authorsLock = it }
|
||||
}
|
||||
bookRepository.save(book).toDto(includeFullUrl = true)
|
||||
|
|
|
|||
|
|
@ -56,8 +56,11 @@ class BookMetadataUpdateDto {
|
|||
|
||||
var releaseDateLock: Boolean? = null
|
||||
|
||||
@Valid
|
||||
var authors: List<AuthorUpdateDto>? = null
|
||||
@get:Valid
|
||||
var authors: List<AuthorUpdateDto>?
|
||||
by Delegates.observable<List<AuthorUpdateDto>?>(null) { prop, _, _ ->
|
||||
isSet[prop.name] = true
|
||||
}
|
||||
|
||||
var authorsLock: Boolean? = null
|
||||
}
|
||||
|
|
|
|||
|
|
@ -524,4 +524,58 @@ class BookControllerTest(
|
|||
assertThat(releaseDate).isNull()
|
||||
}
|
||||
}
|
||||
|
||||
//Not part of the above @Nested class because @Transactional fails
|
||||
@Test
|
||||
@Transactional
|
||||
@WithMockCustomUser(roles = [UserRoles.ADMIN])
|
||||
fun `given json without fields when updating metadata then existing fields are untouched`() {
|
||||
val testDate = LocalDate.of(2020, 1, 1)
|
||||
val series = makeSeries(
|
||||
name = "series",
|
||||
books = listOf(makeBook("1.cbr").also {
|
||||
with(it.metadata)
|
||||
{
|
||||
ageRating = 12
|
||||
readingDirection = BookMetadata.ReadingDirection.LEFT_TO_RIGHT
|
||||
authors.add(Author("Author", "role"))
|
||||
releaseDate = testDate
|
||||
summary = "summary"
|
||||
number = "number"
|
||||
numberLock = true
|
||||
numberSort = 2F
|
||||
numberSortLock = true
|
||||
publisher = "publisher"
|
||||
title = "title"
|
||||
}
|
||||
})
|
||||
).also { it.library = library }
|
||||
seriesRepository.save(series)
|
||||
val bookId = series.books.first().id
|
||||
|
||||
val jsonString = """
|
||||
{
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
mockMvc.patch("/api/v1/books/${bookId}/metadata") {
|
||||
contentType = MediaType.APPLICATION_JSON
|
||||
content = jsonString
|
||||
}.andExpect {
|
||||
status { isOk }
|
||||
}
|
||||
|
||||
val updatedBook = bookRepository.findByIdOrNull(bookId)
|
||||
with(updatedBook!!.metadata) {
|
||||
assertThat(readingDirection).isEqualTo(BookMetadata.ReadingDirection.LEFT_TO_RIGHT)
|
||||
assertThat(ageRating).isEqualTo(12)
|
||||
assertThat(authors).hasSize(1)
|
||||
assertThat(releaseDate).isEqualTo(testDate)
|
||||
assertThat(summary).isEqualTo("summary")
|
||||
assertThat(number).isEqualTo("number")
|
||||
assertThat(numberSort).isEqualTo(2F)
|
||||
assertThat(publisher).isEqualTo("publisher")
|
||||
assertThat(title).isEqualTo("title")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue