|
@@ -1,7 +1,8 @@
|
|
| 1 |
-
import { Component, signal } from '@angular/core';
|
| 2 |
|
| 3 |
import { Book } from '../../shared/book';
|
| 4 |
import { BookCard } from '../book-card/book-card';
|
|
|
|
| 5 |
|
| 6 |
@Component({
|
| 7 |
selector: 'app-books-overview-page',
|
|
@@ -10,30 +11,13 @@ import { BookCard } from '../book-card/book-card';
|
|
| 10 |
styleUrl: './books-overview-page.scss',
|
| 11 |
})
|
| 12 |
export class BooksOverviewPage {
|
|
|
|
|
|
|
| 13 |
protected books = signal<Book[]>([]);
|
| 14 |
protected likedBooks = signal<Book[]>([]);
|
| 15 |
|
| 16 |
constructor() {
|
| 17 |
-
this.books.set(
|
| 18 |
-
{
|
| 19 |
-
isbn: '12345',
|
| 20 |
-
title: 'Tierisch gut kochen',
|
| 21 |
-
authors: ['Mrs Chimp', 'Mr Gorilla'],
|
| 22 |
-
subtitle: 'Rezepte von Affe bis Zebra',
|
| 23 |
-
imageUrl: 'https://cdn.ng-buch.de/kochen.png',
|
| 24 |
-
description: 'Immer lecker und gut',
|
| 25 |
-
createdAt: new Date().toISOString(),
|
| 26 |
-
},
|
| 27 |
-
{
|
| 28 |
-
isbn: '67890',
|
| 29 |
-
title: 'Backen mit Affen',
|
| 30 |
-
subtitle: 'Bananenbrot und mehr',
|
| 31 |
-
authors: ['Orang Utan'],
|
| 32 |
-
imageUrl: 'https://cdn.ng-buch.de/backen.png',
|
| 33 |
-
description: 'Tolle Backtipps für Mensch und Tier',
|
| 34 |
-
createdAt: new Date().toISOString(),
|
| 35 |
-
},
|
| 36 |
-
]);
|
| 37 |
}
|
| 38 |
|
| 39 |
addLikedBook(newLikedBook: Book) {
|
|
|
|
| 1 |
+
import { Component, inject, signal } from '@angular/core';
|
| 2 |
|
| 3 |
import { Book } from '../../shared/book';
|
| 4 |
import { BookCard } from '../book-card/book-card';
|
| 5 |
+
import { BookStore } from '../../shared/book-store';
|
| 6 |
|
| 7 |
@Component({
|
| 8 |
selector: 'app-books-overview-page',
|
|
|
|
| 11 |
styleUrl: './books-overview-page.scss',
|
| 12 |
})
|
| 13 |
export class BooksOverviewPage {
|
| 14 |
+
#bookStore = inject(BookStore);
|
| 15 |
+
|
| 16 |
protected books = signal<Book[]>([]);
|
| 17 |
protected likedBooks = signal<Book[]>([]);
|
| 18 |
|
| 19 |
constructor() {
|
| 20 |
+
this.books.set(this.#bookStore.getAll());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
}
|
| 22 |
|
| 23 |
addLikedBook(newLikedBook: Book) {
|
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { BookStore } from './book-store';
|
| 2 |
+
import { Book } from './book';
|
| 3 |
+
|
| 4 |
+
describe('BookStore', () => {
|
| 5 |
+
let service: BookStore;
|
| 6 |
+
|
| 7 |
+
beforeEach(() => {
|
| 8 |
+
service = new BookStore();
|
| 9 |
+
});
|
| 10 |
+
|
| 11 |
+
it('should be created', () => {
|
| 12 |
+
expect(service).toBeTruthy();
|
| 13 |
+
});
|
| 14 |
+
|
| 15 |
+
it('should return a list of books', () => {
|
| 16 |
+
const books = service.getAll();
|
| 17 |
+
|
| 18 |
+
// Optional: Wir können die Bücher auch noch intensiver prüfen
|
| 19 |
+
// Zum Beispiel:
|
| 20 |
+
// expect(books[0].isbn).toBe('12345');
|
| 21 |
+
// expect(books[1].title).toBe('Backen mit Affen');
|
| 22 |
+
expect(books.length).toBeGreaterThan(0);
|
| 23 |
+
});
|
| 24 |
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { TestBed } from '@angular/core/testing';
|
| 2 |
+
import { BookStore } from './book-store';
|
| 3 |
+
|
| 4 |
+
describe('BookStore', () => {
|
| 5 |
+
let service: BookStore;
|
| 6 |
+
|
| 7 |
+
beforeEach(() => {
|
| 8 |
+
TestBed.configureTestingModule({
|
| 9 |
+
providers: [BookStore]
|
| 10 |
+
});
|
| 11 |
+
service = TestBed.inject(BookStore);
|
| 12 |
+
});
|
| 13 |
+
|
| 14 |
+
it('should be created', () => {
|
| 15 |
+
expect(service).toBeTruthy();
|
| 16 |
+
});
|
| 17 |
+
|
| 18 |
+
it('should return a list of books', () => {
|
| 19 |
+
const books = service.getAll();
|
| 20 |
+
expect(books.length).toBeGreaterThan(0);
|
| 21 |
+
|
| 22 |
+
// Optional: Wir können die Bücher auch noch intensiver prüfen
|
| 23 |
+
// Zum Beispiel:
|
| 24 |
+
// expect(books[0].isbn).toBe('12345');
|
| 25 |
+
// expect(books[1].title).toBe('Backen mit Affen');
|
| 26 |
+
});
|
| 27 |
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Injectable } from '@angular/core';
|
| 2 |
+
|
| 3 |
+
import { Book } from './book';
|
| 4 |
+
|
| 5 |
+
@Injectable({
|
| 6 |
+
providedIn: 'root'
|
| 7 |
+
})
|
| 8 |
+
export class BookStore {
|
| 9 |
+
|
| 10 |
+
#books: Book[] = [
|
| 11 |
+
{
|
| 12 |
+
isbn: '12345',
|
| 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 |
+
getAll(): Book[] {
|
| 32 |
+
return this.#books;
|
| 33 |
+
}
|
| 34 |
+
}
|