Rename method name

This commit is contained in:
aditya.chandel
2024-12-21 22:36:33 -07:00
parent 853d4c7ca0
commit e343e7e7f3
2 changed files with 20 additions and 22 deletions
@@ -48,11 +48,11 @@ export class BooksBrowserComponent implements OnInit {
if (libraryId) {
this.entityType.set('library');
this.currentEntityId.set(libraryId);
this.libraryBookService.loadBooksSignal(libraryId);
this.libraryBookService.loadLibraryBooks(libraryId);
} else if (shelfId) {
this.entityType.set('shelf');
this.currentEntityId.set(shelfId);
this.libraryBookService.loadBooksSignal(shelfId);
this.libraryBookService.loadLibraryBooks(shelfId);
}
});
@@ -121,6 +121,24 @@ export class LibraryAndBookService {
);
}
loadLibraryBooks(libraryId: number) {
if (!this.loadedLibraries.has(libraryId)) {
this.http.get<Book[]>(`${this.libraryUrl}/${libraryId}/book`).pipe(
map(response => response),
catchError(error => {
console.error(`Error loading books for library ${libraryId}:`, error);
return of([]);
})
).subscribe((books) => {
const updatedMap = new Map(this.libraryBooksMap());
updatedMap.set(libraryId, books);
this.libraryBooksMap.set(updatedMap);
this.loadedLibraries.add(libraryId);
console.log(`Loaded books for library ${libraryId}`);
});
}
}
deleteLibrary(libraryId: number | null): Observable<void> {
return this.http.delete<void>(`${this.libraryUrl}/${libraryId}`).pipe(
tap(() => {
@@ -182,24 +200,6 @@ export class LibraryAndBookService {
});
}
loadBooksSignal(libraryId: number) {
if (!this.loadedLibraries.has(libraryId)) {
this.http.get<Book[]>(`${this.libraryUrl}/${libraryId}/book`).pipe(
map(response => response),
catchError(error => {
console.error(`Error loading books for library ${libraryId}:`, error);
return of([]);
})
).subscribe((books) => {
const updatedMap = new Map(this.libraryBooksMap());
updatedMap.set(libraryId, books);
this.libraryBooksMap.set(updatedMap);
this.loadedLibraries.add(libraryId);
console.log(`Loaded books for library ${libraryId}`);
});
}
}
handleNewBook(book: Book) {
const newBook: Book = this.convertBookDTOToBook(book);
const updatedMap = new Map(this.libraryBooksMap());
@@ -310,6 +310,4 @@ export class LibraryAndBookService {
const requestBody = {googleBookId: googleBookId};
return this.http.put<void>(`${this.bookUrl}/${bookId}/set-metadata`, requestBody);
}
}