You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.0 KiB

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<Quotes> {
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>{
quotes: <Quote[]>res.body,
totalCount: parseInt(res.headers.get('X-Total-Count'))
})
);
}
}