Add ASIN lookup to author search (#3162) (#3228)

This commit is contained in:
ACX
2026-03-07 14:51:28 -07:00
committed by GitHub
parent bdb838d2e4
commit dcf54d6cad
7 changed files with 46 additions and 12 deletions
@@ -1,5 +1,6 @@
package org.booklore.controller;
import org.booklore.exception.ApiError;
import org.booklore.model.dto.AuthorDetails;
import org.booklore.model.dto.AuthorSearchResult;
import org.booklore.model.dto.AuthorSummary;
@@ -91,8 +92,15 @@ public class AuthorController {
@GetMapping("/{authorId}/search-metadata")
public ResponseEntity<List<AuthorSearchResult>> searchAuthorMetadata(
@Parameter(description = "ID of the author") @PathVariable long authorId,
@Parameter(description = "Author name to search") @RequestParam("q") String query,
@Parameter(description = "Author name to search") @RequestParam(value = "q", required = false) String query,
@Parameter(description = "Author ASIN to look up") @RequestParam(required = false) String asin,
@Parameter(description = "Region for provider lookup") @RequestParam(defaultValue = "us") String region) {
if (asin != null && !asin.isBlank()) {
return ResponseEntity.ok(authorMetadataService.lookupAuthorByAsin(asin.trim(), region));
}
if (query == null || query.isBlank()) {
throw ApiError.GENERIC_BAD_REQUEST.createException("Either 'q' or 'asin' parameter is required");
}
return ResponseEntity.ok(authorMetadataService.searchAuthorMetadata(query, region));
}
@@ -85,6 +85,13 @@ public class AuthorMetadataService {
.toList();
}
public List<AuthorSearchResult> lookupAuthorByAsin(String asin, String region) {
return authorParserMap.values().stream()
.map(provider -> provider.getAuthorByAsin(asin, region))
.filter(java.util.Objects::nonNull)
.toList();
}
public AuthorDetails matchAuthor(Long authorId, AuthorMatchRequest request) {
AuthorEntity author = authorRepository.findById(authorId)
.orElseThrow(() -> ApiError.AUTHOR_NOT_FOUND.createException(authorId));