@@ -1,5 +1,6 @@
|
|||||||
package org.booklore.controller;
|
package org.booklore.controller;
|
||||||
|
|
||||||
|
import org.booklore.exception.ApiError;
|
||||||
import org.booklore.model.dto.AuthorDetails;
|
import org.booklore.model.dto.AuthorDetails;
|
||||||
import org.booklore.model.dto.AuthorSearchResult;
|
import org.booklore.model.dto.AuthorSearchResult;
|
||||||
import org.booklore.model.dto.AuthorSummary;
|
import org.booklore.model.dto.AuthorSummary;
|
||||||
@@ -91,8 +92,15 @@ public class AuthorController {
|
|||||||
@GetMapping("/{authorId}/search-metadata")
|
@GetMapping("/{authorId}/search-metadata")
|
||||||
public ResponseEntity<List<AuthorSearchResult>> searchAuthorMetadata(
|
public ResponseEntity<List<AuthorSearchResult>> searchAuthorMetadata(
|
||||||
@Parameter(description = "ID of the author") @PathVariable long authorId,
|
@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) {
|
@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));
|
return ResponseEntity.ok(authorMetadataService.searchAuthorMetadata(query, region));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -85,6 +85,13 @@ public class AuthorMetadataService {
|
|||||||
.toList();
|
.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) {
|
public AuthorDetails matchAuthor(Long authorId, AuthorMatchRequest request) {
|
||||||
AuthorEntity author = authorRepository.findById(authorId)
|
AuthorEntity author = authorRepository.findById(authorId)
|
||||||
.orElseThrow(() -> ApiError.AUTHOR_NOT_FOUND.createException(authorId));
|
.orElseThrow(() -> ApiError.AUTHOR_NOT_FOUND.createException(authorId));
|
||||||
|
|||||||
+5
-1
@@ -6,6 +6,10 @@
|
|||||||
<label>{{ t('authorNameLabel') }}</label>
|
<label>{{ t('authorNameLabel') }}</label>
|
||||||
<input pInputText type="text" [(ngModel)]="searchQuery" [placeholder]="t('authorNamePlaceholder')" class="search-input"/>
|
<input pInputText type="text" [(ngModel)]="searchQuery" [placeholder]="t('authorNamePlaceholder')" class="search-input"/>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label>{{ t('asinLabel') }}</label>
|
||||||
|
<input pInputText type="text" [(ngModel)]="asinQuery" [placeholder]="t('asinPlaceholder')" class="search-input"/>
|
||||||
|
</div>
|
||||||
<div class="field region-field">
|
<div class="field region-field">
|
||||||
<label>{{ t('regionLabel') }}</label>
|
<label>{{ t('regionLabel') }}</label>
|
||||||
<p-select
|
<p-select
|
||||||
@@ -22,7 +26,7 @@
|
|||||||
icon="pi pi-search"
|
icon="pi pi-search"
|
||||||
(onClick)="search()"
|
(onClick)="search()"
|
||||||
[loading]="searching"
|
[loading]="searching"
|
||||||
[disabled]="!searchQuery.trim()">
|
[disabled]="!canSearch">
|
||||||
</p-button>
|
</p-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+9
-2
@@ -39,6 +39,7 @@ export class AuthorMatchComponent implements OnInit {
|
|||||||
private t = inject(TranslocoService);
|
private t = inject(TranslocoService);
|
||||||
|
|
||||||
searchQuery = '';
|
searchQuery = '';
|
||||||
|
asinQuery = '';
|
||||||
selectedRegion = 'us';
|
selectedRegion = 'us';
|
||||||
searching = false;
|
searching = false;
|
||||||
matching = false;
|
matching = false;
|
||||||
@@ -62,13 +63,19 @@ export class AuthorMatchComponent implements OnInit {
|
|||||||
this.searchQuery = this.authorName;
|
this.searchQuery = this.authorName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get canSearch(): boolean {
|
||||||
|
return !!this.searchQuery.trim() || !!this.asinQuery.trim();
|
||||||
|
}
|
||||||
|
|
||||||
search(): void {
|
search(): void {
|
||||||
if (!this.searchQuery.trim()) return;
|
const asin = this.asinQuery.trim();
|
||||||
|
const query = this.searchQuery.trim();
|
||||||
|
if (!query && !asin) return;
|
||||||
this.searching = true;
|
this.searching = true;
|
||||||
this.results = [];
|
this.results = [];
|
||||||
this.hasSearched = true;
|
this.hasSearched = true;
|
||||||
|
|
||||||
this.authorService.searchAuthorMetadata(this.authorId, this.searchQuery.trim(), this.selectedRegion)
|
this.authorService.searchAuthorMetadata(this.authorId, query, this.selectedRegion, asin || undefined)
|
||||||
.subscribe({
|
.subscribe({
|
||||||
next: (results) => {
|
next: (results) => {
|
||||||
this.results = results;
|
this.results = results;
|
||||||
|
|||||||
@@ -35,10 +35,14 @@ export class AuthorService {
|
|||||||
return this.http.get<AuthorDetails>(`${this.baseUrl}/by-name`, {params: {name}});
|
return this.http.get<AuthorDetails>(`${this.baseUrl}/by-name`, {params: {name}});
|
||||||
}
|
}
|
||||||
|
|
||||||
searchAuthorMetadata(authorId: number, query: string, region: string): Observable<AuthorSearchResult[]> {
|
searchAuthorMetadata(authorId: number, query: string, region: string, asin?: string): Observable<AuthorSearchResult[]> {
|
||||||
return this.http.get<AuthorSearchResult[]>(`${this.baseUrl}/${authorId}/search-metadata`, {
|
const params: Record<string, string> = {region};
|
||||||
params: {q: query, region}
|
if (asin) {
|
||||||
});
|
params['asin'] = asin;
|
||||||
|
} else {
|
||||||
|
params['q'] = query;
|
||||||
|
}
|
||||||
|
return this.http.get<AuthorSearchResult[]>(`${this.baseUrl}/${authorId}/search-metadata`, {params});
|
||||||
}
|
}
|
||||||
|
|
||||||
matchAuthor(authorId: number, request: AuthorMatchRequest): Observable<AuthorDetails> {
|
matchAuthor(authorId: number, request: AuthorMatchRequest): Observable<AuthorDetails> {
|
||||||
|
|||||||
@@ -119,13 +119,15 @@
|
|||||||
"match": {
|
"match": {
|
||||||
"authorNameLabel": "Author Name",
|
"authorNameLabel": "Author Name",
|
||||||
"authorNamePlaceholder": "Enter author name to search",
|
"authorNamePlaceholder": "Enter author name to search",
|
||||||
|
"asinLabel": "ASIN",
|
||||||
|
"asinPlaceholder": "Enter ASIN to look up directly",
|
||||||
"regionLabel": "Region",
|
"regionLabel": "Region",
|
||||||
"searchBtn": "Search",
|
"searchBtn": "Search",
|
||||||
"searching": "Searching...",
|
"searching": "Searching...",
|
||||||
"noResults": "No Results Found",
|
"noResults": "No Results Found",
|
||||||
"noResultsHint": "Try adjusting your search term or selecting a different region",
|
"noResultsHint": "Try adjusting your search term, entering an ASIN, or selecting a different region",
|
||||||
"readyToSearch": "Ready to Search",
|
"readyToSearch": "Ready to Search",
|
||||||
"readyToSearchHint": "Enter the author name and click Search to find metadata",
|
"readyToSearchHint": "Search by author name or enter an ASIN to look up directly",
|
||||||
"resultsFound": "{{ count }} results found",
|
"resultsFound": "{{ count }} results found",
|
||||||
"matchBtn": "Match",
|
"matchBtn": "Match",
|
||||||
"toast": {
|
"toast": {
|
||||||
|
|||||||
@@ -119,13 +119,15 @@
|
|||||||
"match": {
|
"match": {
|
||||||
"authorNameLabel": "Nombre del autor",
|
"authorNameLabel": "Nombre del autor",
|
||||||
"authorNamePlaceholder": "Ingrese el nombre del autor para buscar",
|
"authorNamePlaceholder": "Ingrese el nombre del autor para buscar",
|
||||||
|
"asinLabel": "ASIN",
|
||||||
|
"asinPlaceholder": "Ingrese el ASIN para buscar directamente",
|
||||||
"regionLabel": "Región",
|
"regionLabel": "Región",
|
||||||
"searchBtn": "Buscar",
|
"searchBtn": "Buscar",
|
||||||
"searching": "Buscando...",
|
"searching": "Buscando...",
|
||||||
"noResults": "Sin resultados",
|
"noResults": "Sin resultados",
|
||||||
"noResultsHint": "Intente ajustar el término de búsqueda o seleccionar una región diferente",
|
"noResultsHint": "Intente ajustar el término de búsqueda, ingresar un ASIN o seleccionar una región diferente",
|
||||||
"readyToSearch": "Listo para buscar",
|
"readyToSearch": "Listo para buscar",
|
||||||
"readyToSearchHint": "Ingrese el nombre del autor y haga clic en Buscar para encontrar metadatos",
|
"readyToSearchHint": "Busque por nombre de autor o ingrese un ASIN para buscar directamente",
|
||||||
"resultsFound": "{{ count }} resultados encontrados",
|
"resultsFound": "{{ count }} resultados encontrados",
|
||||||
"matchBtn": "Coincidir",
|
"matchBtn": "Coincidir",
|
||||||
"toast": {
|
"toast": {
|
||||||
|
|||||||
Reference in New Issue
Block a user