Update metadata
This commit is contained in:
+6
-4
@@ -2,15 +2,12 @@ package com.adityachandel.booklore.controller;
|
|||||||
|
|
||||||
import com.adityachandel.booklore.mapper.BookMetadataMapper;
|
import com.adityachandel.booklore.mapper.BookMetadataMapper;
|
||||||
import com.adityachandel.booklore.model.dto.BookMetadata;
|
import com.adityachandel.booklore.model.dto.BookMetadata;
|
||||||
import com.adityachandel.booklore.model.dto.request.BooksMetadataRefreshRequest;
|
|
||||||
import com.adityachandel.booklore.model.dto.request.LibraryMetadataRefreshRequest;
|
|
||||||
import com.adityachandel.booklore.model.dto.request.MetadataRefreshRequest;
|
import com.adityachandel.booklore.model.dto.request.MetadataRefreshRequest;
|
||||||
import com.adityachandel.booklore.quartz.JobSchedulerService;
|
import com.adityachandel.booklore.quartz.JobSchedulerService;
|
||||||
import com.adityachandel.booklore.service.metadata.BookMetadataService;
|
import com.adityachandel.booklore.service.metadata.BookMetadataService;
|
||||||
import com.adityachandel.booklore.service.metadata.BookMetadataUpdater;
|
import com.adityachandel.booklore.service.metadata.BookMetadataUpdater;
|
||||||
import com.adityachandel.booklore.service.metadata.model.FetchMetadataRequest;
|
import com.adityachandel.booklore.service.metadata.model.FetchMetadataRequest;
|
||||||
import com.adityachandel.booklore.service.metadata.model.FetchedBookMetadata;
|
import com.adityachandel.booklore.service.metadata.model.FetchedBookMetadata;
|
||||||
import com.adityachandel.booklore.service.metadata.model.MetadataProvider;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
@@ -34,11 +31,16 @@ public class MetadataController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/{bookId}")
|
@PutMapping("/{bookId}")
|
||||||
public ResponseEntity<BookMetadata> updateMetadata(@RequestBody FetchedBookMetadata setMetadataRequest, @PathVariable long bookId) {
|
public ResponseEntity<BookMetadata> updateMetadataFromFetch(@RequestBody FetchedBookMetadata setMetadataRequest, @PathVariable long bookId) {
|
||||||
BookMetadata bookMetadata = bookMetadataMapper.toBookMetadata(bookMetadataUpdater.setBookMetadata(bookId, setMetadataRequest, true), true);
|
BookMetadata bookMetadata = bookMetadataMapper.toBookMetadata(bookMetadataUpdater.setBookMetadata(bookId, setMetadataRequest, true), true);
|
||||||
return ResponseEntity.ok(bookMetadata);
|
return ResponseEntity.ok(bookMetadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PutMapping("/update/{bookId}")
|
||||||
|
public ResponseEntity<BookMetadata> updateMetadata(@PathVariable long bookId, @RequestBody BookMetadata bookMetadata) {
|
||||||
|
return ResponseEntity.ok(bookMetadataUpdater.updateMetadata(bookId, bookMetadata));
|
||||||
|
}
|
||||||
|
|
||||||
@PutMapping(path = "/refreshV2")
|
@PutMapping(path = "/refreshV2")
|
||||||
public ResponseEntity<String> scheduleRefreshV2(@Validated @RequestBody MetadataRefreshRequest request) {
|
public ResponseEntity<String> scheduleRefreshV2(@Validated @RequestBody MetadataRefreshRequest request) {
|
||||||
jobSchedulerService.scheduleMetadataRefreshV2(request);
|
jobSchedulerService.scheduleMetadataRefreshV2(request);
|
||||||
|
|||||||
@@ -10,4 +10,7 @@ import java.util.List;
|
|||||||
public interface AuthorMapper {
|
public interface AuthorMapper {
|
||||||
Author toAuthor(AuthorEntity authorEntity);
|
Author toAuthor(AuthorEntity authorEntity);
|
||||||
List<Author> toAuthorList(List<AuthorEntity> authorEntities);
|
List<Author> toAuthorList(List<AuthorEntity> authorEntities);
|
||||||
|
|
||||||
|
AuthorEntity toAuthorEntity(Author author);
|
||||||
|
List<AuthorEntity> toAuthorEntityList(List<Author> authors);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,4 +13,7 @@ public interface CategoryMapper {
|
|||||||
|
|
||||||
List<Category> toCategoryList(List<CategoryEntity> entities);
|
List<Category> toCategoryList(List<CategoryEntity> entities);
|
||||||
|
|
||||||
|
CategoryEntity toCategoryEntity(Category category);
|
||||||
|
|
||||||
|
List<CategoryEntity> toCategoryEntities(List<Category> categories);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ public class BookMetadata {
|
|||||||
private String isbn10;
|
private String isbn10;
|
||||||
private Integer pageCount;
|
private Integer pageCount;
|
||||||
private String language;
|
private String language;
|
||||||
private Float rating;
|
private Double rating;
|
||||||
private Integer reviewCount;
|
private Integer reviewCount;
|
||||||
private Instant coverUpdatedOn;
|
private Instant coverUpdatedOn;
|
||||||
private List<Author> authors;
|
private List<Author> authors;
|
||||||
|
|||||||
+56
@@ -1,7 +1,10 @@
|
|||||||
package com.adityachandel.booklore.service.metadata;
|
package com.adityachandel.booklore.service.metadata;
|
||||||
|
|
||||||
import com.adityachandel.booklore.exception.ApiError;
|
import com.adityachandel.booklore.exception.ApiError;
|
||||||
|
import com.adityachandel.booklore.mapper.AuthorMapper;
|
||||||
import com.adityachandel.booklore.mapper.BookMetadataMapper;
|
import com.adityachandel.booklore.mapper.BookMetadataMapper;
|
||||||
|
import com.adityachandel.booklore.mapper.CategoryMapper;
|
||||||
|
import com.adityachandel.booklore.model.dto.BookMetadata;
|
||||||
import com.adityachandel.booklore.model.entity.AuthorEntity;
|
import com.adityachandel.booklore.model.entity.AuthorEntity;
|
||||||
import com.adityachandel.booklore.model.entity.BookEntity;
|
import com.adityachandel.booklore.model.entity.BookEntity;
|
||||||
import com.adityachandel.booklore.model.entity.BookMetadataEntity;
|
import com.adityachandel.booklore.model.entity.BookMetadataEntity;
|
||||||
@@ -32,6 +35,9 @@ public class BookMetadataUpdater {
|
|||||||
private BookMetadataRepository bookMetadataRepository;
|
private BookMetadataRepository bookMetadataRepository;
|
||||||
private CategoryRepository categoryRepository;
|
private CategoryRepository categoryRepository;
|
||||||
private FileService fileService;
|
private FileService fileService;
|
||||||
|
private BookMetadataMapper bookMetadataMapper;
|
||||||
|
private AuthorMapper authorMapper;
|
||||||
|
private CategoryMapper categoryMapper;
|
||||||
|
|
||||||
|
|
||||||
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||||
@@ -87,4 +93,54 @@ public class BookMetadataUpdater {
|
|||||||
return metadata;
|
return metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BookMetadata updateMetadata(long bookId, BookMetadata updatedMetadata) {
|
||||||
|
BookEntity bookEntity = bookRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||||
|
BookMetadataEntity metadata = bookEntity.getMetadata();
|
||||||
|
|
||||||
|
if (updatedMetadata.getTitle() != null) {
|
||||||
|
metadata.setTitle(updatedMetadata.getTitle());
|
||||||
|
}
|
||||||
|
if (updatedMetadata.getSubtitle() != null) {
|
||||||
|
metadata.setSubtitle(updatedMetadata.getSubtitle());
|
||||||
|
}
|
||||||
|
if (updatedMetadata.getPublisher() != null) {
|
||||||
|
metadata.setPublisher(updatedMetadata.getPublisher());
|
||||||
|
}
|
||||||
|
if (updatedMetadata.getPublishedDate() != null) {
|
||||||
|
metadata.setPublishedDate(updatedMetadata.getPublishedDate());
|
||||||
|
}
|
||||||
|
if (updatedMetadata.getDescription() != null) {
|
||||||
|
metadata.setDescription(updatedMetadata.getDescription());
|
||||||
|
}
|
||||||
|
if (updatedMetadata.getIsbn13() != null) {
|
||||||
|
metadata.setIsbn13(updatedMetadata.getIsbn13());
|
||||||
|
}
|
||||||
|
if (updatedMetadata.getIsbn10() != null) {
|
||||||
|
metadata.setIsbn10(updatedMetadata.getIsbn10());
|
||||||
|
}
|
||||||
|
if (updatedMetadata.getPageCount() != null) {
|
||||||
|
metadata.setPageCount(updatedMetadata.getPageCount());
|
||||||
|
}
|
||||||
|
if (updatedMetadata.getLanguage() != null) {
|
||||||
|
metadata.setLanguage(updatedMetadata.getLanguage());
|
||||||
|
}
|
||||||
|
if (updatedMetadata.getRating() != null) {
|
||||||
|
metadata.setRating(updatedMetadata.getRating());
|
||||||
|
}
|
||||||
|
if (updatedMetadata.getReviewCount() != null) {
|
||||||
|
metadata.setReviewCount(updatedMetadata.getReviewCount());
|
||||||
|
}
|
||||||
|
if (updatedMetadata.getCoverUpdatedOn() != null) {
|
||||||
|
metadata.setCoverUpdatedOn(updatedMetadata.getCoverUpdatedOn());
|
||||||
|
}
|
||||||
|
if (updatedMetadata.getAuthors() != null) {
|
||||||
|
metadata.setAuthors(authorMapper.toAuthorEntityList(updatedMetadata.getAuthors()));
|
||||||
|
}
|
||||||
|
if (updatedMetadata.getCategories() != null) {
|
||||||
|
metadata.setCategories(categoryMapper.toCategoryEntities(updatedMetadata.getCategories()));
|
||||||
|
}
|
||||||
|
bookRepository.save(bookEntity);
|
||||||
|
return bookMetadataMapper.toBookMetadata(metadata, false);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
package com.adityachandel.booklore.service.metadata;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class SimpleMetadataUpdaterService {
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@ VALUES
|
|||||||
INSERT INTO app_settings (category, name, val)
|
INSERT INTO app_settings (category, name, val)
|
||||||
VALUES
|
VALUES
|
||||||
('epub', 'theme', 'white'),
|
('epub', 'theme', 'white'),
|
||||||
('epub', 'fontSize', '120'),
|
('epub', 'fontSize', '150'),
|
||||||
('epub', 'font', 'serif');
|
('epub', 'font', 'serif');
|
||||||
|
|
||||||
INSERT INTO app_settings (category, name, val)
|
INSERT INTO app_settings (category, name, val)
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ export class BookBrowserComponent implements OnInit {
|
|||||||
EntityType = EntityType;
|
EntityType = EntityType;
|
||||||
|
|
||||||
stateOptions: any[] = [{label: 'Grid', value: 'grid'}, {label: 'Table', value: 'table'}];
|
stateOptions: any[] = [{label: 'Grid', value: 'grid'}, {label: 'Table', value: 'table'}];
|
||||||
value: string = 'grid';
|
value: string = 'table';
|
||||||
|
|
||||||
@ViewChild(BookTableComponent) bookTableComponent!: BookTableComponent;
|
@ViewChild(BookTableComponent) bookTableComponent!: BookTableComponent;
|
||||||
|
|
||||||
|
|||||||
+77
-14
@@ -10,13 +10,16 @@
|
|||||||
[(selection)]="selectedBooks"
|
[(selection)]="selectedBooks"
|
||||||
(onHeaderCheckboxToggle)="onHeaderCheckboxToggle($event)"
|
(onHeaderCheckboxToggle)="onHeaderCheckboxToggle($event)"
|
||||||
(onRowSelect)="onRowSelect($event)"
|
(onRowSelect)="onRowSelect($event)"
|
||||||
(onRowUnselect)="onRowUnselect($event)">
|
(onRowUnselect)="onRowUnselect($event)"
|
||||||
|
(onEditComplete)="onEditComplete($event)">
|
||||||
<ng-template #header>
|
<ng-template #header>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="max-w-16">Cover</th>
|
<th class="max-w-16">Cover</th>
|
||||||
<th pResizableColumn>Title</th>
|
<th pResizableColumn>Title</th>
|
||||||
|
<th pResizableColumn>Authors</th>
|
||||||
<th pResizableColumn>Publisher</th>
|
<th pResizableColumn>Publisher</th>
|
||||||
<th>Published</th>
|
<th>Published</th>
|
||||||
|
<th>Genres</th>
|
||||||
<th>ISBN</th>
|
<th>ISBN</th>
|
||||||
<th>Language</th>
|
<th>Language</th>
|
||||||
<th>Rating</th>
|
<th>Rating</th>
|
||||||
@@ -28,25 +31,85 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
<ng-template #body let-book>
|
<ng-template #body let-book>
|
||||||
<tr style="height:46px">
|
<tr *ngIf="book.metadata as metadata" style="height:46px">
|
||||||
<td (click)="openMetadataCenter(book.id)"><img [src]="urlHelper.getCoverUrl(book.id, book.metadata?.coverUpdatedOn)" alt="Book Cover" class="size-7"/></td>
|
<td (click)="openMetadataCenter(book.id)">
|
||||||
<td (click)="openMetadataCenter(book.id)" class="w-1/2 max-w-96 overflow-hidden truncate" [title]="book.metadata?.id">{{ book.metadata?.title }}</td>
|
<img [src]="urlHelper.getCoverUrl(book.id, metadata.coverUpdatedOn)" alt="Book Cover" class="size-7"/>
|
||||||
<td class="w-1/6 max-w-40 overflow-hidden truncate">{{ book.metadata?.publisher }}</td>
|
</td>
|
||||||
<td class="w-1/12 max-w-30 overflow-hidden truncate">{{ book.metadata?.publishedDate }}</td>
|
|
||||||
<td class="w-1/12 max-w-32 overflow-hidden truncate">{{ book.metadata?.isbn10 }}</td>
|
<td [pEditableColumn]="metadata.title"
|
||||||
<td class="w-1/12 max-w-28 overflow-hidden truncate">{{ book.metadata?.language }}</td>
|
pEditableColumnField="metadata.title"
|
||||||
<td class="w-1/12 max-w-30 overflow-hidden truncate">
|
class="min-w-[25rem] max-w-[35rem] overflow-hidden truncate"
|
||||||
<ng-container *ngIf="book.metadata">
|
[pEditableColumnRowIndex]="book.id"
|
||||||
|
[title]="book.metadata?.id">
|
||||||
|
<p-cellEditor>
|
||||||
|
<ng-template #input>
|
||||||
|
<input pInputText class="w-full max-w-full" type="text" [(ngModel)]="metadata.title"/>
|
||||||
|
</ng-template>
|
||||||
|
<ng-template #output>
|
||||||
|
{{ metadata.title }}
|
||||||
|
</ng-template>
|
||||||
|
</p-cellEditor>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td class="min-w-[10rem] max-w-[15rem] overflow-hidden truncate">{{ getAuthorNames(metadata.authors) }}</td>
|
||||||
|
|
||||||
|
<td [pEditableColumn]="metadata.publisher"
|
||||||
|
pEditableColumnField="metadata.publisher"
|
||||||
|
class="min-w-[6rem] max-w-[10rem] overflow-hidden truncate"
|
||||||
|
[pEditableColumnRowIndex]="book.id">
|
||||||
|
<p-cellEditor>
|
||||||
|
<ng-template #input>
|
||||||
|
<input pInputText class="w-full max-w-full" type="text" [(ngModel)]="metadata.publisher"/>
|
||||||
|
</ng-template>
|
||||||
|
<ng-template #output>
|
||||||
|
{{ metadata.publisher }}
|
||||||
|
</ng-template>
|
||||||
|
</p-cellEditor>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td [pEditableColumn]="metadata.publishedDate"
|
||||||
|
pEditableColumnField="metadata.publishedDate"
|
||||||
|
class="min-w-[9.5rem] max-w-[9.5rem] overflow-hidden truncate"
|
||||||
|
[pEditableColumnRowIndex]="book.id">
|
||||||
|
<p-cellEditor>
|
||||||
|
<ng-template #input>
|
||||||
|
<input pInputText class="w-full max-w-full" type="text" [(ngModel)]="metadata.publishedDate"/>
|
||||||
|
</ng-template>
|
||||||
|
<ng-template #output>
|
||||||
|
{{ metadata.publishedDate }}
|
||||||
|
</ng-template>
|
||||||
|
</p-cellEditor>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td class="min-w-[8rem] max-w-[10rem] overflow-hidden truncate">{{ getGenres(metadata.categories) }}</td>
|
||||||
|
|
||||||
|
<td [pEditableColumn]="metadata.isbn10"
|
||||||
|
pEditableColumnField="metadata.isbn10"
|
||||||
|
class="overflow-hidden truncate max-w-15"
|
||||||
|
[pEditableColumnRowIndex]="book.id">
|
||||||
|
<p-cellEditor>
|
||||||
|
<ng-template #input>
|
||||||
|
<input pInputText type="text" [(ngModel)]="metadata.isbn10" class="w-full"/>
|
||||||
|
</ng-template>
|
||||||
|
<ng-template #output>
|
||||||
|
{{ metadata.isbn10 }}
|
||||||
|
</ng-template>
|
||||||
|
</p-cellEditor>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td class="max-w-28 overflow-hidden truncate">{{ metadata.language }}</td>
|
||||||
|
<td class="max-w-30 overflow-hidden truncate">
|
||||||
|
<ng-container>
|
||||||
<p-rating
|
<p-rating
|
||||||
[(ngModel)]="book.metadata.rating"
|
[(ngModel)]="metadata.rating"
|
||||||
readonly
|
readonly
|
||||||
stars="5"
|
stars="5"
|
||||||
[style.--p-rating-icon-active-color]="getStarColor(book.metadata.rating)">
|
[style.--p-rating-icon-active-color]="getStarColor(metadata.rating)">
|
||||||
</p-rating>
|
</p-rating>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
</td>
|
</td>
|
||||||
<td class="w-1/12 max-w-32 overflow-hidden truncate">{{ book.metadata?.pageCount }}</td>
|
<td class="max-w-32 overflow-hidden truncate">{{ metadata.pageCount }}</td>
|
||||||
<td class="w-1/12 max-w-32 overflow-hidden truncate">{{ book.metadata?.reviewCount }}</td>
|
<td class="max-w-32 overflow-hidden truncate">{{ metadata.reviewCount }}</td>
|
||||||
<td class="max-w-16">
|
<td class="max-w-16">
|
||||||
<p-tableCheckbox [value]="book"></p-tableCheckbox>
|
<p-tableCheckbox [value]="book"></p-tableCheckbox>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
+28
-9
@@ -1,13 +1,14 @@
|
|||||||
import {Component, EventEmitter, inject, Input, OnChanges, Output} from '@angular/core';
|
import {Component, EventEmitter, inject, Input, OnChanges, Output} from '@angular/core';
|
||||||
import {TableModule} from 'primeng/table';
|
import {TableEditCompleteEvent, TableModule} from 'primeng/table';
|
||||||
import {NgIf} from '@angular/common';
|
import {NgIf} from '@angular/common';
|
||||||
import {BookService} from '../../../service/book.service';
|
|
||||||
import {Rating} from 'primeng/rating';
|
import {Rating} from 'primeng/rating';
|
||||||
import {FormsModule} from '@angular/forms';
|
import {FormsModule} from '@angular/forms';
|
||||||
import {Book} from '../../../model/book.model';
|
import {Author, Book, Category} from '../../../model/book.model';
|
||||||
import {SortOption} from '../../../model/sort.model';
|
import {SortOption} from '../../../model/sort.model';
|
||||||
import {MetadataDialogService} from '../../../../metadata/service/metadata-dialog.service';
|
import {MetadataDialogService} from '../../../../metadata/service/metadata-dialog.service';
|
||||||
import {UrlHelperService} from '../../../../utilities/service/url-helper.service';
|
import {UrlHelperService} from '../../../../utilities/service/url-helper.service';
|
||||||
|
import {InputText} from 'primeng/inputtext';
|
||||||
|
import {MetadataService} from '../../../../metadata/service/metadata.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-book-table',
|
selector: 'app-book-table',
|
||||||
@@ -17,7 +18,8 @@ import {UrlHelperService} from '../../../../utilities/service/url-helper.service
|
|||||||
TableModule,
|
TableModule,
|
||||||
NgIf,
|
NgIf,
|
||||||
Rating,
|
Rating,
|
||||||
FormsModule
|
FormsModule,
|
||||||
|
InputText
|
||||||
],
|
],
|
||||||
styleUrl: './book-table.component.scss'
|
styleUrl: './book-table.component.scss'
|
||||||
})
|
})
|
||||||
@@ -29,9 +31,9 @@ export class BookTableComponent implements OnChanges {
|
|||||||
@Input() books: Book[] = [];
|
@Input() books: Book[] = [];
|
||||||
@Input() sortOption: SortOption | null = null;
|
@Input() sortOption: SortOption | null = null;
|
||||||
|
|
||||||
private bookService = inject(BookService);
|
|
||||||
protected urlHelper = inject(UrlHelperService);
|
protected urlHelper = inject(UrlHelperService);
|
||||||
private metadataDialogService = inject(MetadataDialogService);
|
private metadataDialogService = inject(MetadataDialogService);
|
||||||
|
private metadataService = inject(MetadataService)
|
||||||
|
|
||||||
// Hack to set virtual-scroller height
|
// Hack to set virtual-scroller height
|
||||||
ngOnChanges() {
|
ngOnChanges() {
|
||||||
@@ -67,10 +69,6 @@ export class BookTableComponent implements OnChanges {
|
|||||||
this.selectedBooksChange.emit(this.selectedBookIds);
|
this.selectedBooksChange.emit(this.selectedBookIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
getBookCoverUrl(bookId: number): string {
|
|
||||||
return this.bookService.getBookCoverUrl(bookId);
|
|
||||||
}
|
|
||||||
|
|
||||||
openMetadataCenter(id: number): void {
|
openMetadataCenter(id: number): void {
|
||||||
this.metadataDialogService.openBookMetadataCenterDialog(id, 'view');
|
this.metadataDialogService.openBookMetadataCenterDialog(id, 'view');
|
||||||
}
|
}
|
||||||
@@ -88,4 +86,25 @@ export class BookTableComponent implements OnChanges {
|
|||||||
return 'rgb(239, 68, 68)';
|
return 'rgb(239, 68, 68)';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onEditComplete($event: TableEditCompleteEvent) {
|
||||||
|
const field = $event.field?.replace(/^metadata\./, '');
|
||||||
|
this.metadataService.updateMetadataField($event.index, field, $event.data).subscribe();
|
||||||
|
}
|
||||||
|
|
||||||
|
removeAuthor(authorToRemove: { name: string }) {
|
||||||
|
/*const authors = this.books[0].metadata.authors; // Adjust this to get the correct book metadata
|
||||||
|
const index = authors.findIndex(author => author.name === authorToRemove.name);
|
||||||
|
if (index !== -1) {
|
||||||
|
authors.splice(index, 1); // Remove the author from the array
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
|
||||||
|
getAuthorNames(authors: Author[]): string {
|
||||||
|
return authors?.map(author => author.name).join(', ') || 'No authors available';
|
||||||
|
}
|
||||||
|
|
||||||
|
getGenres(genres: Category[]) {
|
||||||
|
return genres?.map(g => g.name).join(', ') || 'No genres available';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -200,4 +200,31 @@ export class BookService {
|
|||||||
});
|
});
|
||||||
this.bookStateSubject.next({...currentState, books: updatedBooks})
|
this.bookStateSubject.next({...currentState, books: updatedBooks})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getBookMetadata(bookId: number): BookMetadata | null {
|
||||||
|
const book = this.bookStateSubject.value.books?.find(book => book.id === bookId);
|
||||||
|
return book?.metadata ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateBookMetadata(bookId: number | undefined, metadataField: string | undefined, value: any) {
|
||||||
|
if (!bookId || !metadataField) {
|
||||||
|
console.error("Invalid bookId or metadataField.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const currentState = this.bookStateSubject.value;
|
||||||
|
const updatedBooks = (currentState.books || []).map(book => {
|
||||||
|
if (book.id === bookId) {
|
||||||
|
const updatedBook = {
|
||||||
|
...book,
|
||||||
|
metadata: {
|
||||||
|
...book.metadata,
|
||||||
|
[metadataField]: value
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return updatedBook as Book;
|
||||||
|
}
|
||||||
|
return book;
|
||||||
|
});
|
||||||
|
this.bookStateSubject.next({...currentState, books: updatedBooks});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,33 @@ export class MetadataService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateBookMetadataNew(bookId: number, bookMetadata: BookMetadata): Observable<BookMetadata> {
|
||||||
|
return this.http.put<BookMetadata>(`${this.url}/update/${bookId}`, bookMetadata).pipe(
|
||||||
|
map(updatedMetadata => {
|
||||||
|
this.bookService.handleBookMetadataUpdate(bookId, updatedMetadata);
|
||||||
|
return updatedMetadata;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateMetadataField(bookId: number | undefined, field: string | undefined, value: any): Observable<BookMetadata> {
|
||||||
|
if (!bookId || !field) {
|
||||||
|
throw new Error('Invalid bookId or field');
|
||||||
|
}
|
||||||
|
const currentMetadata = this.bookService.getBookMetadata(bookId);
|
||||||
|
if (!currentMetadata) {
|
||||||
|
throw new Error('Metadata not found');
|
||||||
|
}
|
||||||
|
const updatedMetadata: BookMetadata = {
|
||||||
|
...currentMetadata,
|
||||||
|
[field]: value
|
||||||
|
};
|
||||||
|
if (!updatedMetadata.bookId) {
|
||||||
|
throw new Error('Invalid bookId in metadata');
|
||||||
|
}
|
||||||
|
return this.updateBookMetadataNew(bookId, updatedMetadata);
|
||||||
|
}
|
||||||
|
|
||||||
autoRefreshMetadata(metadataRefreshRequest: MetadataRefreshRequest): Observable<any> {
|
autoRefreshMetadata(metadataRefreshRequest: MetadataRefreshRequest): Observable<any> {
|
||||||
return this.http.put<void>(`${this.url}/refreshV2`, metadataRefreshRequest).pipe(
|
return this.http.put<void>(`${this.url}/refreshV2`, metadataRefreshRequest).pipe(
|
||||||
map(() => {
|
map(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user