Ajout d'un système de cache des
requêtes HTTP
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { DropZoneResp } from '../models/dropzone';
|
||||
import { JumpResp } from '../models/jump';
|
||||
import { AircraftResp } from '../models/aircraft';
|
||||
import { JumpTypeResp } from '../models/jumpType';
|
||||
import {
|
||||
StatsResp,
|
||||
StatsByDzResp,
|
||||
StatsByAircraftResp,
|
||||
StatsByJumpTypeResp,
|
||||
StatsByRigResp,
|
||||
StatsByYearResp
|
||||
} from '../models/statsresp';
|
||||
import { environment } from '../environments/environment';
|
||||
|
||||
@Injectable()
|
||||
export class ServiceApiGet {
|
||||
private readonly headers = new HttpHeaders({
|
||||
'Access-Control-Allow-Origin': environment.urlApi
|
||||
});
|
||||
constructor(private http: HttpClient) { }
|
||||
|
||||
public getListOfDropZones(): Observable<Array<DropZoneResp>> {
|
||||
return this.http.get<Array<DropZoneResp>>(`${environment.urlApi}/api/DropZone`, {
|
||||
headers: this.headers
|
||||
})
|
||||
.pipe(
|
||||
map(response => {
|
||||
const details = response.map(data => new DropZoneResp(data));
|
||||
return details;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
public getListOfJumps(): Observable<Array<JumpResp>> {
|
||||
return this.http.get<Array<JumpResp>>(`${environment.urlApi}/api/Jump`, {
|
||||
headers: this.headers
|
||||
});
|
||||
}
|
||||
|
||||
public getListOfAircrafts(): Observable<Array<AircraftResp>> {
|
||||
return this.http.get<Array<AircraftResp>>(
|
||||
`${environment.urlApi}/api/Aircraft`,
|
||||
{ headers: this.headers }
|
||||
);
|
||||
}
|
||||
|
||||
public getListOfJumpTypes(): Observable<Array<JumpTypeResp>> {
|
||||
return this.http.get<Array<JumpTypeResp>>(
|
||||
`${environment.urlApi}/api/JumpType`,
|
||||
{ headers: this.headers }
|
||||
);
|
||||
}
|
||||
|
||||
public getStatsOfJumps(): StatsResp {
|
||||
const resultat = new StatsResp();
|
||||
resultat.statsByDz = this.http.get<StatsByDzResp>(
|
||||
`${environment.urlApi}/api/Stats/ByDz`,
|
||||
{ headers: this.headers }
|
||||
);
|
||||
resultat.statsByAircraft = this.http.get<StatsByAircraftResp>(
|
||||
`${environment.urlApi}/api/Stats/ByAircraft`,
|
||||
{ headers: this.headers }
|
||||
);
|
||||
resultat.statsByJumpType = this.http.get<StatsByJumpTypeResp>(
|
||||
`${environment.urlApi}/api/Stats/ByJumpType`,
|
||||
{ headers: this.headers }
|
||||
);
|
||||
resultat.statsByRig = this.http.get<StatsByRigResp>(
|
||||
`${environment.urlApi}/api/Stats/ByRig`,
|
||||
{ headers: this.headers }
|
||||
);
|
||||
resultat.statsByYear = this.http.get<StatsByYearResp>(
|
||||
`${environment.urlApi}/api/Stats/ByYear`,
|
||||
{ headers: this.headers }
|
||||
);
|
||||
|
||||
return resultat;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user