fix(api): cannot delete duplicate page match if it is unknown

This commit is contained in:
Gauthier Roebroeck 2022-02-08 16:44:43 +08:00
parent db990baea6
commit a6dece2b81

View file

@ -127,8 +127,7 @@ class PageHashController(
@RequestParam("media_type") mediaType: String,
@RequestParam("file_size") size: Long,
) {
val hash = pageHashRepository.findKnown(PageHash(pageHash, mediaType, size))
?: throw ResponseStatusException(HttpStatus.NOT_FOUND)
val hash = PageHash(pageHash, mediaType, size)
val toRemove = pageHashRepository.findMatchesByHash(hash, null, Pageable.unpaged())
.groupBy(
@ -155,17 +154,14 @@ class PageHashController(
@RequestParam("file_size") size: Long,
@RequestBody matchDto: PageHashMatchDto,
) {
val hash = pageHashRepository.findKnown(PageHash(pageHash, mediaType, size))
?: throw ResponseStatusException(HttpStatus.NOT_FOUND)
val toRemove = Pair(
matchDto.bookId,
listOf(
BookPageNumbered(
fileName = matchDto.fileName,
mediaType = hash.mediaType,
fileHash = hash.hash,
fileSize = hash.size,
mediaType = mediaType,
fileHash = pageHash,
fileSize = size,
pageNumber = matchDto.pageNumber,
),
),