Revision 44638
Added by Argiro Kokogiannaki over 7 years ago
claims.service.ts | ||
---|---|---|
4 | 4 |
import {Observable} from 'rxjs/Observable'; |
5 | 5 |
import {Claim} from '../utils/entities/claim'; |
6 | 6 |
import {OpenaireProperties} from '../utils/properties/openaireProperties'; |
7 |
import 'rxjs/add/observable/of'; |
|
8 |
import 'rxjs/add/operator/do'; |
|
9 |
import 'rxjs/add/operator/share'; |
|
10 |
import { CacheService } from '../shared/cache.service'; |
|
7 | 11 |
|
8 | 12 |
@Injectable() |
9 | 13 |
export class ClaimsService { |
10 | 14 |
private baseUrl; |
11 |
constructor(private jsonp: Jsonp, private http: Http) { |
|
15 |
constructor(private jsonp: Jsonp, private http: Http, public _cache: CacheService) {
|
|
12 | 16 |
this.baseUrl = OpenaireProperties.getClaimsAPIURL(); |
13 | 17 |
} |
14 | 18 |
|
15 | 19 |
private getClaimRequest(size : number, page : number, url :string):any { |
16 | 20 |
console.info('ClaimsService: Claims request: '+url); |
21 |
let key = url; |
|
22 |
if (this._cache.has(key)) { |
|
23 |
return Observable.of(this._cache.get(key)); |
|
24 |
} |
|
17 | 25 |
return this.http.get( url) |
18 | 26 |
.map(request => <any> request.json()) |
19 | 27 |
.do(request => console.info("Get claims: offset = "+(size*(page-1)) + " limit ="+size )) |
20 |
.catch(this.handleError); |
|
28 |
.catch(this.handleError) |
|
29 |
.do(res => { |
|
30 |
this._cache.set(key, res); |
|
31 |
}); |
|
21 | 32 |
} |
22 | 33 |
getClaims( size : number, page : number, keyword:string, sortby: string, descending: boolean, types: string):any { |
23 | 34 |
console.info('ClaimsService: getClaims ' ); |
Also available in: Unified diff
use cache service in all services - fix issues with filters in search pages