- Use mapstruct instead of manual transformer
- Rename Entities and DTOs - Implement refresh metadata - Delete old unused metadata dialog
This commit is contained in:
-45
@@ -1,45 +0,0 @@
|
||||
<div *ngIf="!isLoading && bookMetadataList.length > 0" class="search-container">
|
||||
<div class="input-group">
|
||||
<input type="text" [(ngModel)]="searchText" placeholder="Enter book title"/>
|
||||
<p-button
|
||||
severity="success"
|
||||
[disabled]="isButtonDisabled"
|
||||
(click)="populateTitle()">Search</p-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div *ngIf="isLoading" class="loading">
|
||||
Loading metadata...
|
||||
</div>
|
||||
|
||||
<div *ngIf="errorMessage" class="error">
|
||||
{{ errorMessage }}
|
||||
</div>
|
||||
|
||||
<div *ngIf="!isLoading && bookMetadataList.length > 0" class="metadata-list">
|
||||
<div *ngFor="let metadata of bookMetadataList" class="book-metadata">
|
||||
<div class="metadata-header">
|
||||
<div class="book-image-container">
|
||||
<!--<img class="book-image" [src]="metadata.thumbnail || 'assets/book-cover-metadata.png'" alt="Book Cover"/>-->
|
||||
<p-button class="select-button" (click)="selectMetadata(metadata)">Select</p-button>
|
||||
</div>
|
||||
<div>
|
||||
<h3>{{ metadata.title }}<span *ngIf="metadata.subtitle">: {{ metadata.subtitle }}</span></h3>
|
||||
<p><strong>Authors:</strong> {{ metadata.authors.join(', ') || 'No authors available' }}</p>
|
||||
<p><strong>Publisher:</strong> {{ metadata.publisher }}</p>
|
||||
<p><strong>Published Date:</strong> {{ metadata.publishedDate }}</p>
|
||||
<p><strong>ISBN:</strong> {{ metadata.isbn10 }}</p>
|
||||
<p><strong>Description:</strong> {{ truncateDescription(metadata.description!) }}</p>
|
||||
<p><strong>Page Count:</strong> {{ metadata.pageCount }}</p>
|
||||
<p *ngIf="metadata.googleBookId">
|
||||
<strong>Google Book Id: </strong>
|
||||
<a [href]="'https://books.google.com/books?id=' + metadata.googleBookId" target="_blank">{{ metadata.googleBookId }}</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div *ngIf="!isLoading && bookMetadataList.length === 0" class="no-metadata">
|
||||
No metadata found for this book.
|
||||
</div>
|
||||
-105
@@ -1,105 +0,0 @@
|
||||
.search-container {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.input-group {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
input[type="text"] {
|
||||
padding: 10px;
|
||||
font-size: 1rem;
|
||||
width: 90%;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
button {
|
||||
background-color: #007bff;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 10px 15px;
|
||||
font-size: 1rem;
|
||||
cursor: pointer;
|
||||
border-radius: 5px;
|
||||
transition: background-color 0.3s ease;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background-color: #0056b3;
|
||||
}
|
||||
|
||||
button:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.metadata-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.metadata-header {
|
||||
display: flex;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.book-image {
|
||||
width: 100px;
|
||||
height: 150px;
|
||||
object-fit: cover;
|
||||
border-radius: 5px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.select-button {
|
||||
width: auto;
|
||||
padding: 8px 15px;
|
||||
margin-top: 10px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.book-metadata {
|
||||
background-color: var(--surface-50);
|
||||
padding: 15px;
|
||||
margin-bottom: 15px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size: 1.5rem;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 5px 0;
|
||||
color: var(--text-color-secondary);
|
||||
font-size: 1.0rem;
|
||||
}
|
||||
|
||||
strong {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
button {
|
||||
background-color: #007bff;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 10px 15px;
|
||||
font-size: 0.9rem;
|
||||
cursor: pointer;
|
||||
border-radius: 5px;
|
||||
transition: background-color 0.3s ease;
|
||||
|
||||
&:hover {
|
||||
background-color: #0056b3;
|
||||
}
|
||||
|
||||
&:focus {
|
||||
outline: none;
|
||||
}
|
||||
}
|
||||
-91
@@ -1,91 +0,0 @@
|
||||
import {Component, OnInit} from '@angular/core';
|
||||
import {BookMetadata} from '../../model/book.model';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {Router} from '@angular/router';
|
||||
import {BookService} from '../../service/book.service';
|
||||
import {Button} from 'primeng/button';
|
||||
import {NgForOf, NgIf} from '@angular/common';
|
||||
|
||||
@Component({
|
||||
selector: 'app-book-metadata-dialog',
|
||||
templateUrl: './book-metadata-dialog.component.html',
|
||||
styleUrls: ['./book-metadata-dialog.component.scss'],
|
||||
imports: [
|
||||
FormsModule,
|
||||
Button,
|
||||
NgIf,
|
||||
NgForOf
|
||||
]
|
||||
})
|
||||
export class BookMetadataDialogComponent implements OnInit {
|
||||
bookMetadataList: BookMetadata[] = [];
|
||||
isLoading = true;
|
||||
errorMessage: string | null = null;
|
||||
searchText: string = '';
|
||||
isButtonDisabled = false;
|
||||
bookId: number = 0;
|
||||
libraryId: number = 0;
|
||||
|
||||
constructor(private bookService: BookService, public dynamicDialogConfig: DynamicDialogConfig, private dynamicDialogRef: DynamicDialogRef, private router: Router) {
|
||||
this.searchText = dynamicDialogConfig.data.bookTitle;
|
||||
this.bookId = this.dynamicDialogConfig.data.bookId;
|
||||
this.libraryId = this.dynamicDialogConfig.data.libraryId;
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.bookService.fetchBookMetadataByBookId(this.bookId).subscribe({
|
||||
next: (metadataList) => {
|
||||
this.bookMetadataList = metadataList;
|
||||
this.isLoading = false;
|
||||
},
|
||||
error: (error) => {
|
||||
this.errorMessage = 'Failed to load metadata';
|
||||
this.isLoading = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
selectMetadata(metadata: BookMetadata): void {
|
||||
this.bookService.setBookMetadata(metadata.googleBookId, this.bookId).subscribe({
|
||||
next: () => {
|
||||
this.dynamicDialogRef.close();
|
||||
this.router.navigate(['/library', this.libraryId, 'book', this.bookId, 'info']);
|
||||
},
|
||||
error: (error) => {
|
||||
this.errorMessage = 'Failed to save book metadata';
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
truncateDescription(description: string): string {
|
||||
const maxLength = 1500;
|
||||
return description && description.length > maxLength ? description.substring(0, maxLength) + '...' : description;
|
||||
}
|
||||
|
||||
populateTitle() {
|
||||
this.isButtonDisabled = true;
|
||||
|
||||
setTimeout(() => {
|
||||
if (this.isButtonDisabled) {
|
||||
this.isButtonDisabled = false;
|
||||
this.errorMessage = 'Request timed out. Please try again.';
|
||||
}
|
||||
}, 5000);
|
||||
|
||||
this.bookService.fetchBookMetadataByTerm(this.searchText).subscribe({
|
||||
next: (metadataList) => {
|
||||
this.bookMetadataList = metadataList;
|
||||
this.isLoading = false;
|
||||
this.isButtonDisabled = false;
|
||||
},
|
||||
error: (error) => {
|
||||
this.errorMessage = 'Failed to load metadata';
|
||||
this.isLoading = false;
|
||||
this.isButtonDisabled = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import {BookMetadataBI} from '../model/book-metadata-for-book-info.model';
|
||||
})
|
||||
export class BookService {
|
||||
private readonly url = 'http://localhost:8080/v1/book';
|
||||
private readonly metadataUrl = 'http://localhost:8080/v1/metadata';
|
||||
|
||||
private bookStateSubject = new BehaviorSubject<BookState>({
|
||||
books: null,
|
||||
@@ -144,14 +145,6 @@ export class BookService {
|
||||
return `${this.url}/${bookId}/cover`;
|
||||
}
|
||||
|
||||
fetchBookMetadataByBookId(bookId: number): Observable<BookMetadata[]> {
|
||||
return this.http.get<BookMetadata[]>(`${this.url}/${bookId}/fetch-metadata`);
|
||||
}
|
||||
|
||||
fetchBookMetadataByTerm(term: string): Observable<BookMetadata[]> {
|
||||
return this.http.get<BookMetadata[]>(`${this.url}/fetch-metadata?term=${term}`);
|
||||
}
|
||||
|
||||
setBookMetadata(googleBookId: string, bookId: number): Observable<Book> {
|
||||
const requestBody = {googleBookId};
|
||||
return this.http.put<Book>(`${this.url}/${bookId}/set-metadata`, requestBody).pipe(
|
||||
@@ -198,11 +191,10 @@ export class BookService {
|
||||
}
|
||||
|
||||
fetchMetadata(bookId: number, request: FetchMetadataRequest): Observable<FetchedMetadata[]> {
|
||||
return this.http.post<FetchedMetadata[]>(`${this.url}/${bookId}/metadata`, request);
|
||||
return this.http.post<FetchedMetadata[]>(`${this.metadataUrl}/${bookId}`, request);
|
||||
}
|
||||
|
||||
updateMetadata(bookId: number, bookMetadata: BookMetadataBI): Observable<BookMetadata> {
|
||||
return this.http.put<BookMetadata>(`${this.url}/${bookId}/metadata`, bookMetadata);
|
||||
return this.http.put<BookMetadata>(`${this.metadataUrl}/${bookId}`, bookMetadata);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user