WIP: Metadata

This commit is contained in:
aditya.chandel
2025-01-03 23:43:16 -07:00
parent f976c70bed
commit c7724e6837
17 changed files with 295 additions and 324 deletions
-2
View File
@@ -1,6 +1,5 @@
import {NgModule} from '@angular/core'; import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser'; import {BrowserModule} from '@angular/platform-browser';
import {AppRoutingModule} from './app-routing.module'; import {AppRoutingModule} from './app-routing.module';
import {AppComponent} from './app.component'; import {AppComponent} from './app.component';
import {AppLayoutModule} from './book/component/layout/app.layout.module'; import {AppLayoutModule} from './book/component/layout/app.layout.module';
@@ -41,7 +40,6 @@ import {ProgressSpinnerModule} from 'primeng/progressspinner';
import {provideAnimationsAsync} from '@angular/platform-browser/animations/async'; import {provideAnimationsAsync} from '@angular/platform-browser/animations/async';
import {providePrimeNG} from 'primeng/config'; import {providePrimeNG} from 'primeng/config';
import Aura from '@primeng/themes/aura'; import Aura from '@primeng/themes/aura';
import { MetadataSearcherComponent } from './book-info-tabs/metadata-searcher/metadata-searcher.component';
import {IftaLabel} from 'primeng/iftalabel'; import {IftaLabel} from 'primeng/iftalabel';
import {LoadingOverlayComponent} from './loading-overlay/loading-overlay.component'; import {LoadingOverlayComponent} from './loading-overlay/loading-overlay.component';
@@ -1,88 +1,76 @@
<div class="container pt-4 flex flex-col h-full"> <div *ngIf="bookMetadata$ | async as bookMetadata" class="container pt-4 flex flex-col h-full">
<div class="space-y-4 overflow-y-auto flex-1"> <form [formGroup]="bookMetadataForm" (ngSubmit)="onSave()" class="space-y-4 overflow-y-auto flex-1">
<div class="flex w-full gap-x-4"> <div class="flex w-full gap-x-4">
<div class="flex flex-col gap-1 w-2/3"> <div class="flex flex-col gap-1 w-2/3">
<label for="title">Title</label> <label for="title">Title</label>
<input pInputText id="title" class="w-full" [(ngModel)]="bookForm.title"/> <input pInputText id="title" class="w-full" formControlName="title"/>
</div> </div>
<div class="flex flex-col gap-1 w-1/3"> <div class="flex flex-col gap-1 w-1/3">
<label for="subtitle">Subtitle</label> <label for="subtitle">Subtitle</label>
<input pInputText id="subtitle" class="w-full" [(ngModel)]="bookForm.subtitle"/> <input pInputText id="subtitle" class="w-full" formControlName="subtitle"/>
</div> </div>
</div> </div>
<div class="flex w-full gap-x-4"> <div class="flex w-full gap-x-4">
<div class="flex flex-col gap-1 w-3/4"> <div class="flex flex-col gap-1 w-3/4">
<label for="authors">Authors</label> <label for="authors">Authors</label>
<input pInputText <input pInputText id="authors" class="w-full" formControlName="authors" placeholder="Enter authors separated by commas"/>
id="authors"
class="w-full"
[(ngModel)]="authorsInput"
(ngModelChange)="onAuthorsInputChange()"
placeholder="Enter authors separated by commas"/>
</div> </div>
<div class="flex flex-col gap-1 w-1/4"> <div class="flex flex-col gap-1 w-1/4">
<label for="publish">Publish Date</label> <label for="publish">Publish Date</label>
<input pInputText id="publish" class="w-full" [(ngModel)]="bookForm.publishedDate"/> <input pInputText id="publish" class="w-full" formControlName="publishedDate"/>
</div> </div>
</div> </div>
<div class="flex flex-col gap-1 w-full"> <div class="flex flex-col gap-1 w-full">
<label for="description">Description</label> <label for="description">Description</label>
<textarea id="description" rows="5" cols="30" pTextarea [(ngModel)]="bookForm.description"></textarea> <textarea id="description" rows="5" cols="30" pTextarea formControlName="description"></textarea>
</div> </div>
<div class="flex flex-grow w-full justify-between gap-4"> <div class="flex flex-grow w-full justify-between gap-4">
<div class="w-1/3 flex justify-center items-center pt-4 pr-4 pb-4"> <div class="w-1/3 flex justify-center items-center pt-4 pr-4 pb-4">
<p-image [src]="coverImageSrc(bookId)" alt="Image" width="250"/> <p-image [src]="coverImageSrc(bookMetadata.bookId)" alt="Image" width="250"></p-image>
</div> </div>
<div class="w-2/3 space-y-2"> <div class="w-2/3 space-y-2">
<div class="flex flex-col gap-1 w-full"> <div class="flex flex-col gap-1 w-full">
<label for="categories">Categories</label> <label for="categories">Categories</label>
<input <input pInputText id="categories" class="w-full" formControlName="categories"/>
pInputText
id="categories"
class="w-full"
[(ngModel)]="categoriesInput"
(input)="onCategoriesInputChange()"
/>
</div> </div>
<div class="flex w-full gap-x-4"> <div class="flex w-full gap-x-4">
<div class="flex flex-col gap-1 w-1/2"> <div class="flex flex-col gap-1 w-1/2">
<label for="publisher">Publisher</label> <label for="publisher">Publisher</label>
<input pInputText id="publisher" class="w-full" [(ngModel)]="bookForm.publisher"/> <input pInputText id="publisher" class="w-full" formControlName="publisher"/>
</div> </div>
<div class="flex flex-col w-1/2"> <div class="flex flex-col w-1/2">
<label for="language">Language</label> <label for="language">Language</label>
<input pInputText id="language" class="w-full" [(ngModel)]="bookForm.language"/> <input pInputText id="language" class="w-full" formControlName="language"/>
</div> </div>
</div> </div>
<div class="flex w-full gap-x-4"> <div class="flex w-full gap-x-4">
<div class="flex flex-col gap-1 w-1/2"> <div class="flex flex-col gap-1 w-1/2">
<label for="isbn10">ISBN10</label> <label for="isbn10">ISBN10</label>
<input pInputText id="isbn10" class="w-full" [(ngModel)]="bookForm.isbn10"/> <input pInputText id="isbn10" class="w-full" formControlName="isbn10"/>
</div> </div>
<div class="flex flex-col w-1/2"> <div class="flex flex-col w-1/2">
<label for="isbn13">ISBN13</label> <label for="isbn13">ISBN13</label>
<input pInputText id="isbn13" class="w-full" [(ngModel)]="bookForm.isbn13"/> <input pInputText id="isbn13" class="w-full" formControlName="isbn13"/>
</div> </div>
</div> </div>
<div class="flex w-full gap-x-4"> <div class="flex w-full gap-x-4">
<div class="flex flex-col w-1/2"> <div class="flex flex-col w-1/2">
<label for="aisn">AISN</label> <label for="aisn">AISN</label>
<input pInputText id="aisn" class="w-full" [(ngModel)]="bookForm.asin"/> <input pInputText id="aisn" class="w-full" formControlName="asin"/>
</div> </div>
<div class="flex flex-col w-1/2"> <div class="flex flex-col w-1/2">
<label for="page-count">Page Count</label> <label for="page-count">Page Count</label>
<input pInputText id="page-count" class="w-full" [(ngModel)]="bookForm.pageCount"/> <input pInputText id="page-count" class="w-full" formControlName="pageCount"/>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </form>
<div class="flex flex-col gap-x-4 mt-auto"> <div class="flex flex-col gap-x-4 mt-auto">
<p-divider></p-divider> <p-divider></p-divider>
<div class="flex gap-x-4 justify-end"> <div class="flex gap-x-4 justify-end">
<p-button label="Cancel" icon="pi pi-times" severity="secondary" (onClick)="closeDialog.emit()"/> <p-button label="Cancel" icon="pi pi-times" severity="secondary"></p-button>
<p-button label="Save" icon="pi pi-check" (onClick)="onSave()"/> <p-button label="Save" icon="pi pi-check" type="submit"></p-button>
</div> </div>
</div> </div>
</div> </div>
@@ -1,12 +1,16 @@
import {Component, EventEmitter, Input, OnChanges, Output, SimpleChanges} from '@angular/core'; import {Component, OnInit} from '@angular/core';
import {InputText} from 'primeng/inputtext'; import {InputText} from 'primeng/inputtext';
import {Textarea} from 'primeng/textarea'; import {Textarea} from 'primeng/textarea';
import {Image} from 'primeng/image'; import {Image} from 'primeng/image';
import {Button} from 'primeng/button'; import {Button} from 'primeng/button';
import {Divider} from 'primeng/divider'; import {Divider} from 'primeng/divider';
import {FormsModule} from '@angular/forms'; import {FormControl, FormGroup, FormsModule, ReactiveFormsModule} from '@angular/forms';
import {BookMetadataForm} from '../../book/model/book-metadata-form'; import {Observable} from 'rxjs';
import {BookInfoService} from '../book-info.service';
import {AsyncPipe, NgIf} from '@angular/common';
import {BookService} from '../../book/service/book.service'; import {BookService} from '../../book/service/book.service';
import {BookMetadataBI} from '../../book/model/book-metadata-for-book-info.model';
import {MessageService} from 'primeng/api';
@Component({ @Component({
selector: 'app-book-details', selector: 'app-book-details',
@@ -19,55 +23,86 @@ import {BookService} from '../../book/service/book.service';
Image, Image,
Button, Button,
Divider, Divider,
FormsModule FormsModule,
AsyncPipe,
NgIf,
ReactiveFormsModule
] ]
}) })
export class BookDetailsComponent implements OnChanges { export class BookDetailsComponent implements OnInit {
@Input() bookForm!: BookMetadataForm; bookMetadata$: Observable<BookMetadataBI | null>;
@Input() bookId!: number; bookMetadataForm: FormGroup;
@Output() save = new EventEmitter<BookMetadataForm>(); currentBookId!: number;
@Output() closeDialog = new EventEmitter<unknown>();
authorsInput: string = ''; constructor(private bookInfoService: BookInfoService, private bookService: BookService, private messageService: MessageService) {
categoriesInput: string = ''; this.bookMetadata$ = this.bookInfoService.bookMetadata$;
this.bookMetadataForm = new FormGroup({
title: new FormControl(''),
constructor(private bookService: BookService) { subtitle: new FormControl(''),
authors: new FormControl(''),
categories: new FormControl(''),
publisher: new FormControl(''),
publishedDate: new FormControl(''),
isbn10: new FormControl(''),
isbn13: new FormControl(''),
asin: new FormControl(''),
description: new FormControl(''),
pageCount: new FormControl(''),
language: new FormControl(''),
});
} }
ngOnChanges(changes: SimpleChanges): void { ngOnInit(): void {
if (this.bookForm.authors) { this.bookMetadata$.subscribe((bookMetadata) => {
this.authorsInput = this.bookForm.authors.join(', '); if (bookMetadata) {
} this.currentBookId = bookMetadata.bookId;
if (this.bookForm.categories) { this.bookMetadataForm.setValue({
this.categoriesInput = this.bookForm.categories.join(', '); title: bookMetadata.title,
subtitle: bookMetadata.subtitle,
authors: bookMetadata.authors.join(', '),
categories: bookMetadata.categories.join(', '),
publisher: bookMetadata.publisher,
publishedDate: bookMetadata.publishedDate,
isbn10: bookMetadata.isbn10,
isbn13: bookMetadata.isbn13,
asin: bookMetadata.asin ? bookMetadata.asin : '',
description: bookMetadata.description,
pageCount: bookMetadata.pageCount,
language: bookMetadata.language
});
} }
});
} }
onSave(): void { onSave(): void {
if (this.authorsInput) { const updatedBookMetadata: BookMetadataBI = {
this.bookForm.authors = this.authorsInput.split(',').map(author => author.trim()); bookId: this.currentBookId,
title: this.bookMetadataForm.get('title')?.value,
subtitle: this.bookMetadataForm.get('subtitle')?.value,
authors: this.bookMetadataForm.get('authors')?.value.split(',').map((author: string) => author.trim()),
categories: this.bookMetadataForm.get('categories')?.value.split(',').map((category: string) => category.trim()),
publisher: this.bookMetadataForm.get('publisher')?.value,
publishedDate: this.bookMetadataForm.get('publishedDate')?.value,
isbn10: this.bookMetadataForm.get('isbn10')?.value,
isbn13: this.bookMetadataForm.get('isbn13')?.value,
asin: this.bookMetadataForm.get('asin')?.value,
description: this.bookMetadataForm.get('description')?.value,
pageCount: this.bookMetadataForm.get('pageCount')?.value,
language: this.bookMetadataForm.get('language')?.value
};
this.bookService.updateMetadata(updatedBookMetadata.bookId, updatedBookMetadata).subscribe({
next: () => {
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Book metadata updated'});
this.bookInfoService.emit(updatedBookMetadata);
},
error: (error) => {
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to update book metadata'});
} }
if (this.categoriesInput) { })
this.bookForm.categories = this.categoriesInput.split(',').map(category => category.trim());
}
this.save.emit(this.bookForm);
} }
onAuthorsInputChange(): void { coverImageSrc(bookId: number): string {
if (this.authorsInput) {
this.bookForm.authors = this.authorsInput.split(',').map(author => author.trim());
}
}
onCategoriesInputChange(): void {
if (this.categoriesInput) {
this.bookForm.categories = this.categoriesInput.split(',').map(category => category.trim());
}
}
coverImageSrc(bookId: number) {
return this.bookService.getBookCoverUrl(bookId); return this.bookService.getBookCoverUrl(bookId);
} }
} }
@@ -6,10 +6,10 @@
</p-tablist> </p-tablist>
<p-tabpanels style="height: 100%; overflow: hidden; padding-bottom: 0"> <p-tabpanels style="height: 100%; overflow: hidden; padding-bottom: 0">
<p-tabpanel value="0" style="height: 100%; overflow: hidden;"> <p-tabpanel value="0" style="height: 100%; overflow: hidden;">
<app-book-details [bookId]="book.id" [bookForm]="metadataForm" (save)="saveBook($event)" (closeDialog)="closeDialog($event)"></app-book-details> <app-book-details></app-book-details>
</p-tabpanel> </p-tabpanel>
<p-tabpanel value="1" style="height: 100%; overflow: hidden;"> <p-tabpanel value="1" style="height: 100%; overflow: hidden;">
<app-book-match [book]="book" (closeDialog)="closeDialog($event)"></app-book-match> <app-book-match></app-book-match>
</p-tabpanel> </p-tabpanel>
<p-tabpanel value="2" style="height: 100%; overflow: hidden;"> <p-tabpanel value="2" style="height: 100%; overflow: hidden;">
<p>I too work!!</p> <p>I too work!!</p>
@@ -3,10 +3,11 @@ import {Tab, TabList, TabPanel, TabPanels, Tabs} from 'primeng/tabs';
import {BookDetailsComponent} from './book-details/book-details.component'; import {BookDetailsComponent} from './book-details/book-details.component';
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog'; import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
import {BookService} from '../book/service/book.service'; import {BookService} from '../book/service/book.service';
import {Book} from '../book/model/book.model';
import {BookMetadataForm} from '../book/model/book-metadata-form';
import {MessageService} from 'primeng/api'; import {MessageService} from 'primeng/api';
import {BookMatchComponent} from './book-match/book-match.component'; import {BookMatchComponent} from './book-match/book-match.component';
import {BookInfoService} from './book-info.service';
import {Book} from '../book/model/book.model';
import {BookMetadataBI} from '../book/model/book-metadata-for-book-info.model';
@Component({ @Component({
selector: 'book-info-tabs', selector: 'book-info-tabs',
@@ -19,42 +20,39 @@ import {BookMatchComponent} from './book-match/book-match.component';
Tab, Tab,
TabPanels, TabPanels,
BookDetailsComponent, BookDetailsComponent,
TabPanel,
BookMatchComponent, BookMatchComponent,
TabPanel ],
]
}) })
export class BookInfoTabsComponent { export class BookInfoTabsComponent implements OnInit {
book: Book;
metadataForm: BookMetadataForm = {} as BookMetadataForm;
constructor(private bookService: BookService, private dynamicDialogConfig: DynamicDialogConfig, constructor(private dynamicDialogConfig: DynamicDialogConfig, private dynamicDialogRef: DynamicDialogRef, private bookInfoService: BookInfoService) {
private messageService: MessageService, private dynamicDialogRef: DynamicDialogRef) {
this.book = this.dynamicDialogConfig.data.book;
this.initializeBookForm();
} }
private initializeBookForm(): void { ngOnInit(): void {
if (this.book?.metadata) { const initialBook = this.dynamicDialogConfig.data.book;
this.metadataForm = { if (initialBook?.metadata) {
...this.book.metadata, this.bookInfoService.emit(this.convertToBookMetadataBI(initialBook));
authors: this.book.metadata.authors?.map(a => a.name) || [], }
categories: this.book.metadata.categories?.map(c => c.name) || [] }
private convertToBookMetadataBI(book: Book): BookMetadataBI {
const metadata = book.metadata;
return {
bookId: book.id,
title: metadata?.title || '',
subtitle: metadata?.subtitle,
authors: metadata?.authors?.map((author) => author.name) || [],
categories: metadata?.categories?.map((category) => category.name) || [],
publisher: metadata?.publisher || '',
publishedDate: metadata?.publishedDate || '',
isbn10: metadata?.isbn10 || '',
isbn13: metadata?.isbn13 || '',
asin: metadata?.asin || '',
description: metadata?.description,
pageCount: metadata?.pageCount || 0,
language: metadata?.language || '',
googleBookId: metadata?.googleBookId || '',
}; };
} }
} }
saveBook(bookMetadataForm: BookMetadataForm) {
this.bookService.updateMetadataV2(this.book?.id!, bookMetadataForm).subscribe({
next: () => {
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Book metadata updated'});
},
error: (error) => {
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to update book metadata'});
}
});
}
closeDialog($event: any) {
this.dynamicDialogRef.close();
}
}
@@ -0,0 +1,16 @@
import {Injectable} from '@angular/core';
import {BehaviorSubject} from 'rxjs';
import {BookMetadataBI} from '../book/model/book-metadata-for-book-info.model';
@Injectable({
providedIn: 'root'
})
export class BookInfoService {
private subject = new BehaviorSubject<BookMetadataBI | null>(null);
bookMetadata$ = this.subject.asObservable();
emit(bookMetadata: BookMetadataBI) {
this.subject.next(bookMetadata);
}
}
@@ -1,14 +1,8 @@
<form *ngIf="!selectedMetadata" class="flex flex-col w-full h-full pt-4" [formGroup]="form" (ngSubmit)="onSubmit()"> <form *ngIf="!selectedFetchedMetadata" class="flex flex-col w-full h-full pt-4" [formGroup]="form" (ngSubmit)="onSubmit()">
<div class="flex w-full gap-x-4 items-end"> <div class="flex w-full gap-x-4 items-end">
<div class="flex flex-col gap-1 w-1/6"> <div class="flex flex-col gap-1 w-1/6">
<label for="provider">Provider</label> <label for="provider">Provider</label>
<p-select <p-select id="provider" class="w-full" [options]="providers" formControlName="provider" placeholder="Select Provider.."></p-select>
id="provider"
class="w-full"
[options]="providers"
formControlName="provider"
placeholder="Select Provider.."
></p-select>
</div> </div>
<div class="flex flex-col gap-1 w-1/6"> <div class="flex flex-col gap-1 w-1/6">
@@ -36,7 +30,7 @@
</div> </div>
<div *ngIf="!loading" class="mt-8 flex-1 overflow-y-auto"> <div *ngIf="!loading" class="mt-8 flex-1 overflow-y-auto">
<div *ngFor="let book of fetchedMetadata" class="book-item flex flex-col w-full"> <div *ngFor="let book of allFetchedMetadata" class="book-item flex flex-col w-full">
<div class="flex w-full flex-row book-item-content" (click)="onBookClick(book)"> <div class="flex w-full flex-row book-item-content" (click)="onBookClick(book)">
<img [src]="book.thumbnailUrl" alt="Image" class="img-fixed-dimensions pr-2"/> <img [src]="book.thumbnailUrl" alt="Image" class="img-fixed-dimensions pr-2"/>
<div class=" flex flex-col w-full m-2"> <div class=" flex flex-col w-full m-2">
@@ -59,6 +53,6 @@
</div> </div>
</form> </form>
<div *ngIf="selectedMetadata" class="h-full flex-auto"> <div *ngIf="selectedFetchedMetadata" class="h-full flex-auto">
<app-metadata-searcher [book]="book!" [fetchedMetadata]="selectedMetadata" (closeDialog)="closeTheDialog($event)"></app-metadata-searcher> <app-metadata-searcher [fetchedMetadata]="selectedFetchedMetadata" (goBack)="onGoBack($event)"></app-metadata-searcher>
</div> </div>
@@ -8,9 +8,10 @@ import {NgForOf, NgIf} from '@angular/common';
import {Provider} from '../../book/model/provider.model'; import {Provider} from '../../book/model/provider.model';
import {BookService} from '../../book/service/book.service'; import {BookService} from '../../book/service/book.service';
import {FetchMetadataRequest} from '../../book/model/fetch-metadata-request.model'; import {FetchMetadataRequest} from '../../book/model/fetch-metadata-request.model';
import {Book, FetchedMetadata} from '../../book/model/book.model'; import {FetchedMetadata} from '../../book/model/book.model';
import {ProgressSpinner} from 'primeng/progressspinner'; import {ProgressSpinner} from 'primeng/progressspinner';
import {MetadataSearcherComponent} from '../metadata-searcher/metadata-searcher.component'; import {MetadataSearcherComponent} from '../metadata-searcher/metadata-searcher.component';
import {BookInfoService} from '../book-info.service';
@Component({ @Component({
selector: 'app-book-match', selector: 'app-book-match',
@@ -31,18 +32,16 @@ import {MetadataSearcherComponent} from '../metadata-searcher/metadata-searcher.
}) })
export class BookMatchComponent implements OnInit { export class BookMatchComponent implements OnInit {
@Input() book!: Book;
@Output() closeDialog = new EventEmitter<unknown>();
form: FormGroup; form: FormGroup;
providers = Object.values(Provider); providers = Object.values(Provider);
fetchedMetadata: FetchedMetadata[] = []; allFetchedMetadata: FetchedMetadata[] = [];
selectedMetadata!: FetchedMetadata; selectedFetchedMetadata!: FetchedMetadata | null;
bookId!: number;
loading: boolean = false; loading: boolean = false;
constructor(private fb: FormBuilder, private bookService: BookService) { constructor(private fb: FormBuilder, private bookService: BookService, private bookInfoService: BookInfoService) {
this.form = this.fb.group({ this.form = this.fb.group({
provider: [null], provider: null,
isbn: [''], isbn: [''],
title: [''], title: [''],
author: [''], author: [''],
@@ -50,12 +49,17 @@ export class BookMatchComponent implements OnInit {
} }
ngOnInit() { ngOnInit() {
const firstAuthor = this.book!.metadata?.authors && this.book!.metadata?.authors.length > 0 ? this.book!.metadata?.authors[0].name : ''; this.bookInfoService.bookMetadata$.subscribe((bookMetadata => {
this.form.patchValue({ if (bookMetadata) {
isbn: this.book!.metadata?.isbn10 || '', this.bookId = bookMetadata.bookId;
title: this.book!.metadata?.title || '', this.form.setValue(({
author: firstAuthor, provider: null,
}); isbn: bookMetadata.isbn10,
title: bookMetadata.title,
author: bookMetadata.authors.length > 0 ? bookMetadata.authors[0] : ''
}))
}
}))
} }
get isSearchEnabled(): boolean { get isSearchEnabled(): boolean {
@@ -74,27 +78,24 @@ export class BookMatchComponent implements OnInit {
return; return;
} }
const fetchRequest: FetchMetadataRequest = { const fetchRequest: FetchMetadataRequest = {
bookId: 1, bookId: this.bookId,
provider: providerKey, provider: providerKey,
title: this.form.get('title')?.value, title: this.form.get('title')?.value,
isbn: this.form.get('isbn')?.value, isbn: this.form.get('isbn')?.value,
author: this.form.get('author')?.value author: this.form.get('author')?.value
}; };
this.loading = true; this.loading = true;
this.bookService.fetchMetadataFromSource(fetchRequest.bookId, fetchRequest) this.bookService.fetchMetadata(fetchRequest.bookId, fetchRequest)
.subscribe({ .subscribe({
next: (fetchedMetadata) => { next: (fetchedMetadata) => {
console.log('Metadata fetched successfully', fetchedMetadata);
this.loading = false; this.loading = false;
this.fetchedMetadata = fetchedMetadata.map((book) => ({ this.allFetchedMetadata = fetchedMetadata.map((book) => ({
...book, ...book,
thumbnailUrl: book.thumbnailUrl thumbnailUrl: book.thumbnailUrl
})); }));
}, },
error: (err) => { error: (err) => {
this.loading = false; this.loading = false;
console.error('Error fetching metadata', err);
} }
}); });
} else { } else {
@@ -107,11 +108,11 @@ export class BookMatchComponent implements OnInit {
return safeText.length > length ? safeText.substring(0, length) + '...' : safeText; return safeText.length > length ? safeText.substring(0, length) + '...' : safeText;
} }
onBookClick(book: FetchedMetadata) { onBookClick(fetchedMetadata: FetchedMetadata) {
this.selectedMetadata = book; this.selectedFetchedMetadata = fetchedMetadata;
} }
closeTheDialog($event: unknown) { onGoBack($event: boolean) {
this.closeDialog.emit() this.selectedFetchedMetadata = null;
} }
} }
@@ -1,91 +1,90 @@
<div class="h-full flex pt-4 flex-col"> <form [formGroup]="bookMetadataForm" (ngSubmit)="onSave()" class="h-full flex pt-4 flex-col">
<div class="overflow-y-scroll flex-1"> <div class="overflow-y-scroll flex-1">
<div class="form-row"> <div class="form-row">
<label for="title" class="label">Title</label> <label for="title" class="label">Title</label>
<div class="input-container"> <div class="input-container">
<input pInputText id="title" [(ngModel)]="toUpdateMetadata.title" class="input"/> <input pInputText id="title" formControlName="title" class="input"/>
<p-button icon="pi pi-arrow-left" [outlined]="true" class="arrow-button" (click)="copyFetchedToCurrent('title')"/> <p-button icon="pi pi-arrow-left" [outlined]="true" class="arrow-button" (click)="copyFetchedToCurrent('title')"/>
<input pInputText id="titleFetched" [(ngModel)]="fetchedMetadata.title" class="input"/> <input pInputText [value]="fetchedMetadata.title" class="input"/>
</div> </div>
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="authors" class="label">Authors</label> <label for="authors" class="label">Authors</label>
<div class="input-container"> <div class="input-container">
<input pInputText id="authors" [(ngModel)]="currentAuthorsString" class="input"/> <input pInputText id="authors" formControlName="authors" class="input"/>
<p-button icon="pi pi-arrow-left" [outlined]="true" class="arrow-button" (click)="copyFetchedToCurrent('authors')"/> <p-button icon="pi pi-arrow-left" [outlined]="true" class="arrow-button" (click)="copyFetchedToCurrent('authors')"/>
<input pInputText id="authorsFetched" [(ngModel)]="fetchedAuthorsString" class="input"/> <input pInputText [value]="fetchedAuthorsString()" class="input"/>
</div> </div>
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="categories" class="label">Categories</label> <label for="categories" class="label">Categories</label>
<div class="input-container"> <div class="input-container">
<input pInputText id="categories" [(ngModel)]="currentCategoriesString" class="input"/> <input pInputText id="categories" formControlName="categories" class="input"/>
<p-button icon="pi pi-arrow-left" [outlined]="true" class="arrow-button" (click)="copyFetchedToCurrent('categories')"/> <p-button icon="pi pi-arrow-left" [outlined]="true" class="arrow-button" (click)="copyFetchedToCurrent('categories')"/>
<input pInputText id="categoriesFetched" [(ngModel)]="fetchedCategoriesString" class="input"/> <input pInputText [value]="fetchedCategoriesString()" class="input"/>
</div> </div>
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="publisher" class="label">Publisher</label> <label for="publisher" class="label">Publisher</label>
<div class="input-container"> <div class="input-container">
<input pInputText id="publisher" [(ngModel)]="toUpdateMetadata.publisher" class="input"/> <input pInputText id="publisher" formControlName="publisher" class="input"/>
<p-button icon="pi pi-arrow-left" [outlined]="true" class="arrow-button" (click)="copyFetchedToCurrent('publisher')"/> <p-button icon="pi pi-arrow-left" [outlined]="true" class="arrow-button" (click)="copyFetchedToCurrent('publisher')"/>
<input pInputText id="publisherFetched" [(ngModel)]="fetchedMetadata.publisher" class="input"/> <input pInputText [value]="fetchedMetadata.publisher" class="input"/>
</div> </div>
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="publishedDate" class="label">Published</label> <label for="publishedDate" class="label">Published</label>
<div class="input-container"> <div class="input-container">
<input pInputText id="publishedDate" [(ngModel)]="toUpdateMetadata.publishedDate" class="input"/> <input pInputText id="publishedDate" formControlName="publishedDate" class="input"/>
<p-button icon="pi pi-arrow-left" [outlined]="true" class="arrow-button" (click)="copyFetchedToCurrent('publishedDate')"/> <p-button icon="pi pi-arrow-left" [outlined]="true" class="arrow-button" (click)="copyFetchedToCurrent('publishedDate')"/>
<input pInputText id="publishedDateFetched" [(ngModel)]="fetchedMetadata.publishedDate" class="input"/> <input pInputText [value]="fetchedMetadata.publishedDate" class="input"/>
</div> </div>
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="isbn10" class="label">ISBN-10</label> <label for="isbn10" class="label">ISBN-10</label>
<div class="input-container"> <div class="input-container">
<input pInputText id="isbn10" [(ngModel)]="toUpdateMetadata.isbn10" class="input"/> <input pInputText id="isbn10" formControlName="isbn10" class="input"/>
<p-button icon="pi pi-arrow-left" [outlined]="true" class="arrow-button" (click)="copyFetchedToCurrent('isbn10')"/> <p-button icon="pi pi-arrow-left" [outlined]="true" class="arrow-button" (click)="copyFetchedToCurrent('isbn10')"/>
<input pInputText id="isbn10Fetched" [(ngModel)]="fetchedMetadata.isbn10" class="input"/> <input pInputText [value]="fetchedMetadata.isbn10" class="input"/>
</div> </div>
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="language" class="label">Language</label> <label for="language" class="label">Language</label>
<div class="input-container"> <div class="input-container">
<input pInputText id="language" [(ngModel)]="toUpdateMetadata.language" class="input"/> <input pInputText id="language" formControlName="language" class="input"/>
<p-button icon="pi pi-arrow-left" [outlined]="true" class="arrow-button" (click)="copyFetchedToCurrent('language')"/> <p-button icon="pi pi-arrow-left" [outlined]="true" class="arrow-button" (click)="copyFetchedToCurrent('language')"/>
<input pInputText id="languageFetched" [(ngModel)]="fetchedMetadata.language" class="input"/> <input pInputText [value]="fetchedMetadata.language" class="input"/>
</div> </div>
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="language" class="label">Pages</label> <label for="pageCount" class="label">Pages</label>
<div class="input-container"> <div class="input-container">
<input pInputText id="pageCount" [(ngModel)]="toUpdateMetadata.pageCount" class="input"/> <input pInputText id="pageCount" formControlName="pageCount" class="input"/>
<p-button icon="pi pi-arrow-left" [outlined]="true" class="arrow-button" (click)="copyFetchedToCurrent('pageCount')"/> <p-button icon="pi pi-arrow-left" [outlined]="true" class="arrow-button" (click)="copyFetchedToCurrent('pageCount')"/>
<input pInputText id="pageCountFetched" [(ngModel)]="fetchedMetadata.pageCount" class="input"/> <input pInputText [value]="fetchedMetadata.pageCount" class="input"/>
</div> </div>
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="description" class="label">Description</label> <label for="description" class="label">Description</label>
<div class="input-container"> <div class="input-container">
<textarea id="description" [(ngModel)]="toUpdateMetadata.description" class="input"></textarea> <textarea id="description" formControlName="description" class="input"></textarea>
<p-button icon="pi pi-arrow-left" [outlined]="true" class="arrow-button" (click)="copyFetchedToCurrent('description')"/> <p-button icon="pi pi-arrow-left" [outlined]="true" class="arrow-button" (click)="copyFetchedToCurrent('description')"/>
<textarea id="descriptionFetched" [(ngModel)]="fetchedMetadata.description" class="input"></textarea> <textarea [value]="fetchedMetadata.description" class="input"></textarea>
</div> </div>
</div> </div>
<div class="form-row"> <div class="form-row">
<label class="label"></label> <label class="label"></label>
<div class="input-container"> <div class="input-container">
<img *ngIf="!updateThumbnail" [src]="coverImageSrc(book)" alt="Book Thumbnail" class="thumbnail"/> <img *ngIf="!updateThumbnailUrl" [src]="coverImageSrc(currentBookId)" alt="Book Thumbnail" class="thumbnail"/>
<img *ngIf="updateThumbnail" [src]="fetchedMetadata.thumbnailUrl" alt="Fetched Thumbnail" class="thumbnail"/> <img *ngIf="updateThumbnailUrl" [src]="fetchedMetadata.thumbnailUrl" alt="Fetched Thumbnail" class="thumbnail"/>
<p-button icon="pi pi-arrow-left" [outlined]="true" class="arrow-button" (click)="shouldUpdateThumbnail()"/> <p-button icon="pi pi-arrow-left" [outlined]="true" class="arrow-button" (click)="shouldUpdateThumbnail()"/>
<img [src]="fetchedMetadata.thumbnailUrl" alt="Fetched Thumbnail" class="thumbnail"/> <img [src]="fetchedMetadata.thumbnailUrl" alt="Fetched Thumbnail" class="thumbnail"/>
</div> </div>
@@ -94,10 +93,14 @@
<div class="flex flex-col gap-x-4 mt-auto"> <div class="flex flex-col gap-x-4 mt-auto">
<p-divider></p-divider> <p-divider></p-divider>
<div class="flex justify-between">
<p-button label="Back" icon="pi pi-arrow-left" severity="warn" (onClick)="goBackClick()"></p-button>
<div class="flex gap-x-4 justify-end"> <div class="flex gap-x-4 justify-end">
<p-button label="Cancel" icon="pi pi-times" severity="secondary" (onClick)="closeDialog.emit()"></p-button> <p-button label="Cancel" icon="pi pi-times" severity="secondary"></p-button>
<p-button label="Save" icon="pi pi-check" severity="primary" [disabled]="loading" (onClick)="saveMetadata()"></p-button> <p-button label="Save" icon="pi pi-check" severity="primary" type="submit" [disabled]="loading"></p-button>
</div>
</div> </div>
</div> </div>
</div> </form>
@@ -1,12 +1,15 @@
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
import {Book, BookMetadata, FetchedMetadata} from '../../book/model/book.model'; import {FetchedMetadata} from '../../book/model/book.model';
import {BookService} from '../../book/service/book.service'; import {BookService} from '../../book/service/book.service';
import {MessageService} from 'primeng/api'; import {MessageService} from 'primeng/api';
import {Button} from 'primeng/button'; import {Button} from 'primeng/button';
import {FormsModule} from '@angular/forms'; import {FormControl, FormGroup, FormsModule, ReactiveFormsModule} from '@angular/forms';
import {InputText} from 'primeng/inputtext'; import {InputText} from 'primeng/inputtext';
import {NgIf} from '@angular/common'; import {NgIf} from '@angular/common';
import {Divider} from 'primeng/divider'; import {Divider} from 'primeng/divider';
import {BookInfoService} from '../book-info.service';
import {Observable} from 'rxjs';
import {BookMetadataBI} from '../../book/model/book-metadata-for-book-info.model';
@Component({ @Component({
selector: 'app-metadata-searcher', selector: 'app-metadata-searcher',
@@ -18,76 +21,95 @@ import {Divider} from 'primeng/divider';
FormsModule, FormsModule,
InputText, InputText,
NgIf, NgIf,
Divider Divider,
ReactiveFormsModule
] ]
}) })
export class MetadataSearcherComponent implements OnInit { export class MetadataSearcherComponent implements OnInit {
@Input() fetchedMetadata!: FetchedMetadata; @Input() fetchedMetadata!: FetchedMetadata;
@Input() book!: Book; @Output() goBack = new EventEmitter<boolean>();
@Output() closeDialog = new EventEmitter<unknown>();
toUpdateMetadata!: FetchedMetadata; bookMetadataForm: FormGroup;
bookMetadata$: Observable<BookMetadataBI | null>;
currentBookId!: number;
loading: boolean = false; loading: boolean = false;
updateThumbnail: boolean = false; updateThumbnailUrl: boolean = false;
constructor(private bookService: BookService, private messageService: MessageService) {
constructor(private bookService: BookService, private bookInfoService: BookInfoService, private messageService: MessageService) {
this.bookMetadata$ = this.bookInfoService.bookMetadata$;
this.bookMetadataForm = new FormGroup({
title: new FormControl(''),
subtitle: new FormControl(''),
authors: new FormControl(''),
categories: new FormControl(''),
publisher: new FormControl(''),
publishedDate: new FormControl(''),
isbn10: new FormControl(''),
isbn13: new FormControl(''),
asin: new FormControl(''),
description: new FormControl(''),
pageCount: new FormControl(''),
language: new FormControl(''),
});
} }
ngOnInit() { ngOnInit(): void {
console.log(this.book) this.bookMetadata$.subscribe((bookMetadata) => {
this.toUpdateMetadata = this.convertBookMetadataToFetchedMetadata(this.book!.metadata!); if (bookMetadata) {
this.currentBookId = bookMetadata.bookId;
this.bookMetadataForm.setValue({
title: bookMetadata.title,
subtitle: bookMetadata.subtitle,
authors: bookMetadata.authors.join(', '),
categories: bookMetadata.categories.join(', '),
publisher: bookMetadata.publisher,
publishedDate: bookMetadata.publishedDate,
isbn10: bookMetadata.isbn10,
isbn13: bookMetadata.isbn13,
asin: bookMetadata.asin,
description: bookMetadata.description,
pageCount: bookMetadata.pageCount == 0 ? null : bookMetadata.pageCount,
language: bookMetadata.language
});
}
});
} }
copyFetchedToCurrent(field: keyof FetchedMetadata) { fetchedAuthorsString(): string {
if (this.fetchedMetadata && this.toUpdateMetadata) {
this.toUpdateMetadata[field] = this.fetchedMetadata[field];
}
}
get currentAuthorsString(): string {
return this.toUpdateMetadata.authors ? this.toUpdateMetadata.authors.map(author => author).join(', ') : '';
}
set currentAuthorsString(value: string) {
this.toUpdateMetadata.authors = value.split(',');
}
get fetchedAuthorsString(): string {
return this.fetchedMetadata.authors ? this.fetchedMetadata.authors.map(author => author).join(', ') : ''; return this.fetchedMetadata.authors ? this.fetchedMetadata.authors.map(author => author).join(', ') : '';
} }
set fetchedAuthorsString(value: string) { fetchedCategoriesString(): string {
this.fetchedMetadata.authors = value.split(',');
}
get currentCategoriesString(): string {
return this.toUpdateMetadata.categories ? this.toUpdateMetadata.categories.map(category => category).join(', ') : '';
}
set currentCategoriesString(value: string) {
this.toUpdateMetadata.categories = value.split(',');
}
get fetchedCategoriesString(): string {
return this.fetchedMetadata.categories ? this.fetchedMetadata.categories.map(category => category).join(', ') : ''; return this.fetchedMetadata.categories ? this.fetchedMetadata.categories.map(category => category).join(', ') : '';
} }
set fetchedCategoriesString(value: string) { coverImageSrc(bookId: number): string {
this.fetchedMetadata.categories = value.split(','); return this.bookService.getBookCoverUrl(bookId);
} }
coverImageSrc(book: Book): string { onSave(): void {
return this.bookService.getBookCoverUrl(book.id); const updatedBookMetadata: BookMetadataBI = {
} bookId: this.currentBookId,
title: this.bookMetadataForm.get('title')?.value || this.fetchedMetadata.title,
subtitle: this.bookMetadataForm.get('subtitle')?.value || this.fetchedMetadata.subtitle,
authors: this.bookMetadataForm.get('authors')?.value ? this.bookMetadataForm.get('authors')?.value.split(',').map((author: string) => author.trim()) : this.fetchedMetadata.authors,
categories: this.bookMetadataForm.get('categories')?.value ? this.bookMetadataForm.get('categories')?.value.split(',').map((category: string) => category.trim()) : this.fetchedMetadata.categories,
publisher: this.bookMetadataForm.get('publisher')?.value || this.fetchedMetadata.publisher,
publishedDate: this.bookMetadataForm.get('publishedDate')?.value || this.fetchedMetadata.publishedDate,
isbn10: this.bookMetadataForm.get('isbn10')?.value || this.fetchedMetadata.isbn10,
isbn13: this.bookMetadataForm.get('isbn13')?.value || this.fetchedMetadata.isbn13,
asin: this.bookMetadataForm.get('asin')?.value || this.fetchedMetadata.asin,
description: this.bookMetadataForm.get('description')?.value || this.fetchedMetadata.description,
pageCount: this.bookMetadataForm.get('pageCount')?.value || this.fetchedMetadata.pageCount,
language: this.bookMetadataForm.get('language')?.value || this.fetchedMetadata.language,
thumbnailUrl: this.updateThumbnailUrl ? this.fetchedMetadata.thumbnailUrl : undefined
};
saveMetadata() { this.bookService.updateMetadata(updatedBookMetadata.bookId, updatedBookMetadata).subscribe({
this.loading = true;
this.updateFields();
this.bookService.updateMetadata(this.book.id, this.toUpdateMetadata).subscribe({
next: () => { next: () => {
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Book metadata updated'}); this.messageService.add({severity: 'info', summary: 'Success', detail: 'Book metadata updated'});
this.bookInfoService.emit(updatedBookMetadata);
this.loading = false; this.loading = false;
}, },
error: (error) => { error: (error) => {
@@ -97,75 +119,18 @@ export class MetadataSearcherComponent implements OnInit {
}); });
} }
updateFields() {
if (!this.toUpdateMetadata.title && this.fetchedMetadata.title) {
this.toUpdateMetadata.title = this.fetchedMetadata.title;
}
if (!this.toUpdateMetadata.subtitle && this.fetchedMetadata.subtitle) {
this.toUpdateMetadata.subtitle = this.fetchedMetadata.subtitle;
}
if (!this.toUpdateMetadata.publisher && this.fetchedMetadata.publisher) {
this.toUpdateMetadata.publisher = this.fetchedMetadata.publisher;
}
if (!this.toUpdateMetadata.publishedDate && this.fetchedMetadata.publishedDate) {
this.toUpdateMetadata.publishedDate = this.fetchedMetadata.publishedDate;
}
if (!this.toUpdateMetadata.description && this.fetchedMetadata.description) {
this.toUpdateMetadata.description = this.fetchedMetadata.description;
}
if (!this.toUpdateMetadata.isbn10 && this.fetchedMetadata.isbn10) {
this.toUpdateMetadata.isbn10 = this.fetchedMetadata.isbn10;
}
if (!this.toUpdateMetadata.language && this.fetchedMetadata.language) {
this.toUpdateMetadata.language = this.fetchedMetadata.language;
}
if (!this.toUpdateMetadata.pageCount && this.fetchedMetadata.pageCount) {
this.toUpdateMetadata.pageCount = this.fetchedMetadata.pageCount;
}
if (!this.toUpdateMetadata.authors || this.toUpdateMetadata.authors.length === 0) {
this.toUpdateMetadata.authors = this.fetchedMetadata.authors;
}
if (!this.toUpdateMetadata.categories || this.toUpdateMetadata.categories.length === 0) {
this.toUpdateMetadata.categories = this.fetchedMetadata.categories;
}
if (this.updateThumbnail) {
this.toUpdateMetadata.thumbnailUrl = this.fetchedMetadata.thumbnailUrl;
}
}
shouldUpdateThumbnail() { shouldUpdateThumbnail() {
this.updateThumbnail = true; this.updateThumbnailUrl = true;
} }
convertBookMetadataToFetchedMetadata(bookMetadata: BookMetadata): FetchedMetadata { copyFetchedToCurrent(field: string): void {
return { const value = this.fetchedMetadata[field];
bookId: null, if (value) {
googleBookId: bookMetadata.googleBookId || null, this.bookMetadataForm.get(field)?.setValue(value);
amazonBookId: '', }
title: bookMetadata.title || null, }
subtitle: bookMetadata.subtitle || null,
publisher: bookMetadata.publisher || null, goBackClick() {
publishedDate: bookMetadata.publishedDate || null, this.goBack.emit(true);
description: bookMetadata.description || null,
isbn13: '',
isbn10: bookMetadata.isbn10 || null,
pageCount: bookMetadata.pageCount || null,
thumbnailUrl: '',
language: bookMetadata.language || null,
rating: null,
reviewCount: null,
authors: bookMetadata.authors.map(author => author.name),
categories: bookMetadata.categories.map(category => category.name),
};
} }
} }
@@ -85,7 +85,6 @@ export class BookCardComponent implements OnInit {
openBookDetailsDialog(bookId: number): void { openBookDetailsDialog(bookId: number): void {
this.bookService.getBookByIdFromAPI(bookId, true).subscribe(({ this.bookService.getBookByIdFromAPI(bookId, true).subscribe(({
next: (book) => { next: (book) => {
console.log(book)
this.dialogService.open(BookInfoTabsComponent, { this.dialogService.open(BookInfoTabsComponent, {
header: 'Open book details', header: 'Open book details',
modal: true, modal: true,
@@ -36,14 +36,6 @@
</div> </div>
</li> </li>
<p-divider layout="vertical" /> <p-divider layout="vertical" />
<li>
<a class="topbar-item">
<i class="pi pi-book text-surface-700 dark:text-surface-100" (click)="openBookDetailsDialog()"
pTooltip="Book Details" tooltipPosition="top"></i>
</a>
</li>
<li> <li>
<a class="topbar-item"> <a class="topbar-item">
<i class="pi pi-plus-circle text-surface-700 dark:text-surface-100" (click)="openLibraryCreatorDialog()" <i class="pi pi-plus-circle text-surface-700 dark:text-surface-100" (click)="openLibraryCreatorDialog()"
@@ -77,22 +77,6 @@ export class AppTopBarComponent implements OnDestroy {
this.showEvents = !this.showEvents; this.showEvents = !this.showEvents;
} }
openBookDetailsDialog(): void {
this.ref = this.dialogService.open(BookInfoTabsComponent, {
header: 'Open book details',
modal: true,
closable: true,
width: '1200px',
height: '835px',
showHeader: false,
closeOnEscape: true,
data: {
bookId: 1
}
});
}
openLibraryCreatorDialog(): void { openLibraryCreatorDialog(): void {
this.ref = this.dialogService.open(LibraryCreatorComponent, { this.ref = this.dialogService.open(LibraryCreatorComponent, {
header: 'Create New Library', header: 'Create New Library',
@@ -1,4 +1,5 @@
export interface BookMetadataForm { export interface BookMetadataBI {
bookId: number;
title: string; title: string;
subtitle?: string; subtitle?: string;
authors: Array<string>; authors: Array<string>;
@@ -7,9 +8,10 @@ export interface BookMetadataForm {
publishedDate: string; publishedDate: string;
isbn10: string; isbn10: string;
isbn13: string; isbn13: string;
asin: string; asin?: string;
description?: string; description?: string;
pageCount: number; pageCount?: number | null;
language: string; language: string;
googleBookId: string; googleBookId?: string;
thumbnailUrl?: string;
} }
@@ -45,6 +45,7 @@ export interface FetchedMetadata {
reviewCount: number | null; reviewCount: number | null;
authors: string[]; authors: string[];
categories: string[]; categories: string[];
asin: string | null;
[key: string]: any; [key: string]: any;
} }
@@ -4,8 +4,8 @@ import {HttpClient} from '@angular/common/http';
import {catchError, map, switchMap, tap} from 'rxjs/operators'; import {catchError, map, switchMap, tap} from 'rxjs/operators';
import {Book, BookMetadata, BookSetting, FetchedMetadata} from '../model/book.model'; import {Book, BookMetadata, BookSetting, FetchedMetadata} from '../model/book.model';
import {BookState} from '../model/state/book-state.model'; import {BookState} from '../model/state/book-state.model';
import {BookMetadataForm} from '../model/book-metadata-form';
import {FetchMetadataRequest} from '../model/fetch-metadata-request.model'; import {FetchMetadataRequest} from '../model/fetch-metadata-request.model';
import {BookMetadataBI} from '../model/book-metadata-for-book-info.model';
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
@@ -197,16 +197,12 @@ export class BookService {
}); });
} }
fetchMetadataFromSource(bookId: number, request: FetchMetadataRequest): Observable<FetchedMetadata[]> { fetchMetadata(bookId: number, request: FetchMetadataRequest): Observable<FetchedMetadata[]> {
return this.http.post<FetchedMetadata[]>(`${this.url}/${bookId}/metadata`, request); return this.http.post<FetchedMetadata[]>(`${this.url}/${bookId}/metadata`, request);
} }
updateMetadata(bookId: number, updateMedata: FetchedMetadata): Observable<BookMetadata> { updateMetadata(bookId: number, bookMetadata: BookMetadataBI): Observable<BookMetadata> {
return this.http.put<BookMetadata>(`${this.url}/${bookId}/source/AMAZON/metadata`, updateMedata); return this.http.put<BookMetadata>(`${this.url}/${bookId}/metadata`, bookMetadata);
}
updateMetadataV2(bookId: number, bookMetadataForm: BookMetadataForm): Observable<BookMetadata> {
return this.http.put<BookMetadata>(`${this.url}/${bookId}/metadata`, bookMetadataForm);
} }
} }
-1
View File
@@ -1,4 +1,3 @@
// loading.service.ts
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs'; import { BehaviorSubject } from 'rxjs';