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