Permalink
Browse files

Auto-generated commit -- Introduce interface BookRaw for HTTP response

- create book-raw.ts in shared folder with BookRaw interface
- change signature of book factory method to accept any or BookRaw
- use BookRaw for the generic type param of http.get() in BookStoreService

Signed-off-by: Johannes Hoppe <johannes.hoppe@haushoppe-its.de>

Triggered by commit: angular-buch/book-monkey2@ab72c19
Travis build: https://travis-ci.org/angular-buch/book-monkey2/builds/307879639
  • Loading branch information...
TheBuildbot committed Nov 27, 2017
1 parent 0e924f6 commit f2d380af5171f079d37036370d03d6538e2f18f8
Showing with 19 additions and 4 deletions.
  1. +2 −1 src/app/shared/book-factory.ts
  2. +13 −0 src/app/shared/book-raw.ts
  3. +4 −3 src/app/shared/book-store.service.ts
@@ -1,12 +1,13 @@
import { Book } from './book';
import { BookRaw } from './book-raw';

export class BookFactory {

static empty(): Book {
return new Book('', '', [''], new Date(), '', 0, [{url: '', title: ''}], '');
}

static fromObject(rawBook: any): Book {
static fromObject(rawBook: BookRaw | any): Book {
return new Book(
rawBook.isbn,
rawBook.title,
@@ -0,0 +1,13 @@
export interface BookRaw {
isbn: string;
title: string;
authors: string[];
published: string;
subtitle: string;
rating: number;
thumbnails: {
url: string;
title: string;
}[];
description: string;
}
@@ -5,6 +5,7 @@ import { retry, map, catchError } from 'rxjs/operators';
import 'rxjs/add/observable/throw';

import { Book } from './book';
import { BookRaw } from './book-raw';
import { BookFactory } from './book-factory';

@Injectable()
@@ -15,7 +16,7 @@ export class BookStoreService {

getAll(): Observable<Array<Book>> {
return this.http
.get<any[]>(`${this.api}/books`)
.get<BookRaw[]>(`${this.api}/books`)
.pipe(
retry(3),
map(rawBooks => rawBooks
@@ -27,7 +28,7 @@ export class BookStoreService {

getSingle(isbn: string): Observable<Book> {
return this.http
.get(`${this.api}/book/${isbn}`)
.get<BookRaw>(`${this.api}/book/${isbn}`)
.pipe(
retry(3),
map(rawBook => BookFactory.fromObject(rawBook)),
@@ -73,7 +74,7 @@ export class BookStoreService {

getAllSearch(searchTerm: string): Observable<Array<Book>> {
return this.http
.get<any[]>(`${this.api}/books/search/${searchTerm}`)
.get<BookRaw[]>(`${this.api}/books/search/${searchTerm}`)
.pipe(
retry(3),
map(rawBooks => rawBooks

0 comments on commit f2d380a

Please sign in to comment.