|
@@ -28,6 +28,9 @@
|
|
| 28 |
<img [src]="b.imageUrl" alt="Cover" />
|
| 29 |
<footer>
|
| 30 |
<a routerLink="/books">Back to list</a>
|
|
|
|
|
|
|
|
|
|
| 31 |
</footer>
|
| 32 |
</article>
|
| 33 |
}
|
|
|
|
| 28 |
<img [src]="b.imageUrl" alt="Cover" />
|
| 29 |
<footer>
|
| 30 |
<a routerLink="/books">Back to list</a>
|
| 31 |
+
<button type="button" (click)="removeBook(b.isbn)">
|
| 32 |
+
Delete book
|
| 33 |
+
</button>
|
| 34 |
</footer>
|
| 35 |
</article>
|
| 36 |
}
|
|
@@ -1,6 +1,7 @@
|
|
| 1 |
-
import { Component,
|
| 2 |
-
import { RouterLink } from '@angular/router';
|
| 3 |
|
|
|
|
| 4 |
import { BookStore } from '../../shared/book-store';
|
| 5 |
|
| 6 |
@Component({
|
|
@@ -11,7 +12,24 @@ import { BookStore } from '../../shared/book-store';
|
|
| 11 |
})
|
| 12 |
export class BookDetailsPage {
|
| 13 |
#bookStore = inject(BookStore);
|
|
|
|
| 14 |
|
| 15 |
readonly isbn = input.required<string>();
|
| 16 |
-
protected book =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
}
|
|
|
|
| 1 |
+
import { Component, effect, inject, input, signal } from '@angular/core';
|
| 2 |
+
import { Router, RouterLink } from '@angular/router';
|
| 3 |
|
| 4 |
+
import { Book } from '../../shared/book';
|
| 5 |
import { BookStore } from '../../shared/book-store';
|
| 6 |
|
| 7 |
@Component({
|
|
|
|
| 12 |
})
|
| 13 |
export class BookDetailsPage {
|
| 14 |
#bookStore = inject(BookStore);
|
| 15 |
+
#router = inject(Router);
|
| 16 |
|
| 17 |
readonly isbn = input.required<string>();
|
| 18 |
+
protected book = signal<Book | undefined>(undefined);
|
| 19 |
+
|
| 20 |
+
constructor() {
|
| 21 |
+
effect(() => {
|
| 22 |
+
this.#bookStore.getSingle(this.isbn()).subscribe(book => {
|
| 23 |
+
this.book.set(book);
|
| 24 |
+
});
|
| 25 |
+
});
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
removeBook(isbn: string) {
|
| 29 |
+
if (window.confirm('Delete book?')) {
|
| 30 |
+
this.#bookStore.remove(isbn).subscribe(() => {
|
| 31 |
+
this.#router.navigateByUrl('/books');
|
| 32 |
+
});
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
}
|
|
@@ -28,7 +28,9 @@ export class BooksOverviewPage {
|
|
| 28 |
});
|
| 29 |
|
| 30 |
constructor() {
|
| 31 |
-
this
|
|
|
|
|
|
|
| 32 |
}
|
| 33 |
|
| 34 |
addLikedBook(newLikedBook: Book) {
|
|
|
|
| 28 |
});
|
| 29 |
|
| 30 |
constructor() {
|
| 31 |
+
this.#bookStore.getAll().subscribe(books => {
|
| 32 |
+
this.books.set(books);
|
| 33 |
+
});
|
| 34 |
}
|
| 35 |
|
| 36 |
addLikedBook(newLikedBook: Book) {
|
|
@@ -1,4 +1,6 @@
|
|
| 1 |
-
import { Injectable } from '@angular/core';
|
|
|
|
|
|
|
| 2 |
|
| 3 |
import { Book } from './book';
|
| 4 |
|
|
@@ -6,33 +8,18 @@ import { Book } from './book';
|
|
| 6 |
providedIn: 'root'
|
| 7 |
})
|
| 8 |
export class BookStore {
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
{
|
| 12 |
-
|
| 13 |
-
title: 'Tierisch gut kochen',
|
| 14 |
-
authors: ['Mrs Chimp', 'Mr Gorilla'],
|
| 15 |
-
subtitle: 'Rezepte von Affe bis Zebra',
|
| 16 |
-
imageUrl: 'https://cdn.ng-buch.de/kochen.png',
|
| 17 |
-
description: 'Immer lecker und gut',
|
| 18 |
-
createdAt: new Date().toISOString()
|
| 19 |
-
},
|
| 20 |
-
{
|
| 21 |
-
isbn: '67890',
|
| 22 |
-
title: 'Backen mit Affen',
|
| 23 |
-
subtitle: 'Bananenbrot und mehr',
|
| 24 |
-
authors: ['Orang Utan'],
|
| 25 |
-
imageUrl: 'https://cdn.ng-buch.de/backen.png',
|
| 26 |
-
description: 'Tolle Backtipps für Mensch und Tier',
|
| 27 |
-
createdAt: new Date().toISOString()
|
| 28 |
-
}
|
| 29 |
-
];
|
| 30 |
|
| 31 |
-
|
| 32 |
-
return this.#books;
|
| 33 |
}
|
| 34 |
|
| 35 |
-
|
| 36 |
-
return this.#
|
| 37 |
}
|
| 38 |
}
|
|
|
|
| 1 |
+
import { inject, Injectable } from '@angular/core';
|
| 2 |
+
import { HttpClient } from '@angular/common/http';
|
| 3 |
+
import { Observable } from 'rxjs';
|
| 4 |
|
| 5 |
import { Book } from './book';
|
| 6 |
|
|
|
|
| 8 |
providedIn: 'root'
|
| 9 |
})
|
| 10 |
export class BookStore {
|
| 11 |
+
#http = inject(HttpClient);
|
| 12 |
+
#apiUrl = 'https://api6.angular-buch.com';
|
| 13 |
|
| 14 |
+
getAll(): Observable<Book[]> {
|
| 15 |
+
return this.#http.get<Book[]>(`${this.#apiUrl}/books`);
|
| 16 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
getSingle(isbn: string): Observable<Book> {
|
| 19 |
+
return this.#http.get<Book>(`${this.#apiUrl}/books/${isbn}`);
|
| 20 |
}
|
| 21 |
|
| 22 |
+
remove(isbn: string): Observable<void> {
|
| 23 |
+
return this.#http.delete<void>(`${this.#apiUrl}/books/${isbn}`);
|
| 24 |
}
|
| 25 |
}
|