diff --git a/apps/quotes/src/app/models/quotes.ts b/apps/quotes/src/app/models/quote.ts similarity index 56% rename from apps/quotes/src/app/models/quotes.ts rename to apps/quotes/src/app/models/quote.ts index f921745..3b50b3d 100644 --- a/apps/quotes/src/app/models/quotes.ts +++ b/apps/quotes/src/app/models/quote.ts @@ -4,8 +4,3 @@ export interface Quote { game: string; date: Date; } - -export interface Quotes { - quotes: Quote[]; - totalCount: number; -} diff --git a/apps/quotes/src/app/quotes/quotes.component.ts b/apps/quotes/src/app/quotes/quotes.component.ts index aef2ce3..fc34d05 100644 --- a/apps/quotes/src/app/quotes/quotes.component.ts +++ b/apps/quotes/src/app/quotes/quotes.component.ts @@ -29,7 +29,6 @@ import { fromEvent } from 'rxjs/observable/fromEvent'; import { saveAs } from 'file-saver'; -import { Quotes } from '../models/quotes'; import { QuotesService } from '../services/quotes.service'; import { QuotesDataSource } from '../services/quotes.datasource'; @@ -112,8 +111,6 @@ export class QuotesComponent implements OnInit, AfterViewInit { export() { this.quotesService.findQuotes('', 'id', 'asc', 0, 0) - .subscribe(quotes => { - this.saveFile((quotes).quotes) - }); + .subscribe(data => this.saveFile(data.quotes)); } } diff --git a/apps/quotes/src/app/services/quotes.datasource.ts b/apps/quotes/src/app/services/quotes.datasource.ts index c12f794..1e92e97 100644 --- a/apps/quotes/src/app/services/quotes.datasource.ts +++ b/apps/quotes/src/app/services/quotes.datasource.ts @@ -14,10 +14,7 @@ import { import { QuotesService } from './quotes.service'; -import { - Quotes, - Quote -} from '../models/quotes'; +import { Quote } from '../models/quote'; export class QuotesDataSource implements DataSource { @@ -44,9 +41,9 @@ export class QuotesDataSource implements DataSource { catchError(() => of([])), finalize(() => this.loadingSubject.next(false)) ) - .subscribe(quotes => { - this.quotesSubject.next((quotes).quotes); - this.countSubject.next((quotes).totalCount) + .subscribe(data => { + this.quotesSubject.next(data.quotes); + this.countSubject.next(data.totalCount); }); } diff --git a/apps/quotes/src/app/services/quotes.service.ts b/apps/quotes/src/app/services/quotes.service.ts index 649a9b3..8ec8fb9 100644 --- a/apps/quotes/src/app/services/quotes.service.ts +++ b/apps/quotes/src/app/services/quotes.service.ts @@ -9,10 +9,7 @@ import { Observable } from 'rxjs/Observable'; import { map } from 'rxjs/operators'; -import { - Quotes, - Quote -} from '../models/quotes'; +import { Quote } from '../models/quote'; @Injectable() @@ -21,7 +18,7 @@ export class QuotesService { findQuotes( filter = '', sortBy = 'id', sortOrder = 'desc', - pageNumber = 0, pageSize = 20): Observable { + pageNumber = 0, pageSize = 20): Observable { return this.http.get('/quotes/api/quotes', { observe: 'response', @@ -32,10 +29,10 @@ export class QuotesService { .set('page_number', pageNumber.toString()) .set('page_size', pageSize.toString()) }).pipe( - map(res => { + map(res => ({ quotes: res.body, totalCount: parseInt(res.headers.get('X-Total-Count')) - }) + })) ); } }