import { Injectable } from '@angular/core'; import { HttpClient, HttpParams } from '@angular/common/http'; import { Observable } from 'rxjs/Observable'; import { map } from 'rxjs/operators'; import { Quotes, Quote } from '../models/quotes'; @Injectable() export class QuotesService { constructor(private http: HttpClient) { } findQuotes( filter = '', sortBy = 'id', sortOrder = 'desc', pageNumber = 0, pageSize = 10): Observable { return this.http.get('/api/quotes', { observe: 'response', params: new HttpParams() .set('filter', filter) .set('sort_by', sortBy) .set('sort_order', sortOrder) .set('page_number', pageNumber.toString()) .set('page_size', pageSize.toString()) }).pipe( map(res => { quotes: res.body, totalCount: parseInt(res.headers.get('X-Total-Count')) }) ); } }