Ajout d'un cache sur les appels vers les
données de type "référentiel"
This commit is contained in:
@@ -35,6 +35,7 @@ import { RequestCache } from "../services/request-cache.service";
|
|||||||
import { AuthGuardService } from "../services/auth-guard.service";
|
import { AuthGuardService } from "../services/auth-guard.service";
|
||||||
import { ImageService } from "../services/image.service";
|
import { ImageService } from "../services/image.service";
|
||||||
import { ConfigurationHelper } from "../services/configuration-helper";
|
import { ConfigurationHelper } from "../services/configuration-helper";
|
||||||
|
import { ServiceRefData } from "../services/service-ref-data.service";
|
||||||
|
|
||||||
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
|
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
|
||||||
import { FormsModule, ReactiveFormsModule } from "@angular/forms";
|
import { FormsModule, ReactiveFormsModule } from "@angular/forms";
|
||||||
@@ -68,7 +69,6 @@ import { JumpInfosComponent } from './jump-infos/jump-infos.component';
|
|||||||
|
|
||||||
const appRoutes: Routes = [
|
const appRoutes: Routes = [
|
||||||
{ path: "", component: DefaultComponent, canActivate: [AuthGuardService] },
|
{ path: "", component: DefaultComponent, canActivate: [AuthGuardService] },
|
||||||
|
|
||||||
{
|
{
|
||||||
path: "summary",
|
path: "summary",
|
||||||
component: SummaryComponent,
|
component: SummaryComponent,
|
||||||
@@ -109,10 +109,7 @@ const appRoutes: Routes = [
|
|||||||
component: UserProfileComponent,
|
component: UserProfileComponent,
|
||||||
canActivate: [AuthGuardService]
|
canActivate: [AuthGuardService]
|
||||||
},
|
},
|
||||||
|
|
||||||
{ path: "login", component: LoginComponent },
|
{ path: "login", component: LoginComponent },
|
||||||
|
|
||||||
// { path: "**", redirectTo: "" },
|
|
||||||
];
|
];
|
||||||
|
|
||||||
// Déclaration de la fonction d'initialisation de la configuration
|
// Déclaration de la fonction d'initialisation de la configuration
|
||||||
@@ -186,6 +183,7 @@ export function initConfig(configService: ConfigurationHelper) {
|
|||||||
RequestCache,
|
RequestCache,
|
||||||
ConfigurationHelper,
|
ConfigurationHelper,
|
||||||
DatePipe,
|
DatePipe,
|
||||||
|
ServiceRefData,
|
||||||
{ provide: APP_INITIALIZER, useFactory: initConfig, deps: [ConfigurationHelper], multi: true },
|
{ provide: APP_INITIALIZER, useFactory: initConfig, deps: [ConfigurationHelper], multi: true },
|
||||||
{ provide: HTTP_INTERCEPTORS, useClass: JwtAuthInterceptor, multi: true },
|
{ provide: HTTP_INTERCEPTORS, useClass: JwtAuthInterceptor, multi: true },
|
||||||
{ provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true }
|
{ provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true }
|
||||||
|
|||||||
@@ -1,11 +1,5 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import {
|
import { HttpEvent, HttpRequest, HttpResponse, HttpInterceptor, HttpHandler } from '@angular/common/http';
|
||||||
HttpEvent,
|
|
||||||
HttpRequest,
|
|
||||||
HttpResponse,
|
|
||||||
HttpInterceptor,
|
|
||||||
HttpHandler
|
|
||||||
} from '@angular/common/http';
|
|
||||||
|
|
||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
import { tap } from 'rxjs/operators';
|
import { tap } from 'rxjs/operators';
|
||||||
|
|||||||
6
Front/skydivelogs-app/src/models/ref-data.enum.ts
Normal file
6
Front/skydivelogs-app/src/models/ref-data.enum.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
export enum RefData {
|
||||||
|
JumpType,
|
||||||
|
Aircraft,
|
||||||
|
Gear,
|
||||||
|
Dropzone
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import { Observable } from 'rxjs';
|
|||||||
import { AircraftResp, AircraftReq } from '../models/aircraft';
|
import { AircraftResp, AircraftReq } from '../models/aircraft';
|
||||||
|
|
||||||
import { BaseService } from './base.service';
|
import { BaseService } from './base.service';
|
||||||
|
import { RefData } from '../models/ref-data.enum';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AircraftService extends BaseService {
|
export class AircraftService extends BaseService {
|
||||||
@@ -20,7 +21,8 @@ export class AircraftService extends BaseService {
|
|||||||
url = `${this.apiUrl}/Aircraft`;
|
url = `${this.apiUrl}/Aircraft`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.http.get<Array<AircraftResp>>(url, { headers: this.headers });
|
let callToApi = this.http.get<Array<AircraftResp>>(url, { headers: this.headers });
|
||||||
|
return this.serviceRefData.get<Array<AircraftResp>>(RefData.Aircraft, callToApi);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AddAircraft(aircraftName: string, dataImg: string) {
|
public AddAircraft(aircraftName: string, dataImg: string) {
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
import { HttpHeaders } from '@angular/common/http';
|
import { HttpHeaders } from '@angular/common/http';
|
||||||
|
|
||||||
import { ConfigurationHelper } from './configuration-helper';
|
import { ConfigurationHelper } from './configuration-helper';
|
||||||
|
import { ServiceRefData } from './service-ref-data.service';
|
||||||
|
|
||||||
export class BaseService {
|
export class BaseService {
|
||||||
protected headers: HttpHeaders;
|
protected headers: HttpHeaders;
|
||||||
protected apiUrl: string;
|
protected apiUrl: string;
|
||||||
|
protected serviceRefData : ServiceRefData;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
ConfigurationHelper.settings.subscribe(settings =>
|
ConfigurationHelper.settings.subscribe(settings =>
|
||||||
@@ -18,5 +20,7 @@ export class BaseService {
|
|||||||
this.apiUrl = tmpApiUrl + '/api';
|
this.apiUrl = tmpApiUrl + '/api';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.serviceRefData = new ServiceRefData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { map } from "rxjs/operators";
|
|||||||
import { DropZoneResp, DropZoneReq } from "../models/dropzone";
|
import { DropZoneResp, DropZoneReq } from "../models/dropzone";
|
||||||
|
|
||||||
import { BaseService } from "./base.service";
|
import { BaseService } from "./base.service";
|
||||||
|
import { RefData } from "../models/ref-data.enum";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class DropzoneService extends BaseService {
|
export class DropzoneService extends BaseService {
|
||||||
@@ -21,11 +22,12 @@ export class DropzoneService extends BaseService {
|
|||||||
url = `${this.apiUrl}/DropZone`;
|
url = `${this.apiUrl}/DropZone`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.http.get<Array<DropZoneResp>>(url, { headers: this.headers })
|
let callToApi = this.http.get<Array<DropZoneResp>>(url, { headers: this.headers })
|
||||||
.pipe(map(response => {
|
.pipe(map(response => {
|
||||||
const details = response.map(data => new DropZoneResp(data));
|
const details = response.map(data => new DropZoneResp(data));
|
||||||
return details;
|
return details;
|
||||||
}));
|
}));
|
||||||
|
return this.serviceRefData.get<Array<DropZoneResp>>(RefData.Dropzone, callToApi);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SetFavoriteDropZone(selectedDz: DropZoneResp): boolean {
|
public SetFavoriteDropZone(selectedDz: DropZoneResp): boolean {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { Observable } from "rxjs";
|
|||||||
import { GearResp, GearReq } from "../models/gear";
|
import { GearResp, GearReq } from "../models/gear";
|
||||||
|
|
||||||
import { BaseService } from "./base.service";
|
import { BaseService } from "./base.service";
|
||||||
|
import { RefData } from "../models/ref-data.enum";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class GearService extends BaseService {
|
export class GearService extends BaseService {
|
||||||
@@ -13,9 +14,8 @@ export class GearService extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public getListOfGears(): Observable<Array<GearResp>> {
|
public getListOfGears(): Observable<Array<GearResp>> {
|
||||||
return this.http.get<Array<GearResp>>(`${this.apiUrl}/Gear`, {
|
let callToApi = this.http.get<Array<GearResp>>(`${this.apiUrl}/Gear`, { headers: this.headers });
|
||||||
headers: this.headers
|
return this.serviceRefData.get<Array<GearResp>>(RefData.Gear, callToApi);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public AddGear(name: string,
|
public AddGear(name: string,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { Observable } from "rxjs";
|
|||||||
import { JumpTypeResp, JumpTypeReq } from "../models/jumpType";
|
import { JumpTypeResp, JumpTypeReq } from "../models/jumpType";
|
||||||
|
|
||||||
import { BaseService } from "./base.service";
|
import { BaseService } from "./base.service";
|
||||||
|
import { RefData } from "../models/ref-data.enum";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class JumpTypeService extends BaseService {
|
export class JumpTypeService extends BaseService {
|
||||||
@@ -13,9 +14,8 @@ export class JumpTypeService extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public getListOfJumpTypes(): Observable<Array<JumpTypeResp>> {
|
public getListOfJumpTypes(): Observable<Array<JumpTypeResp>> {
|
||||||
return this.http.get<Array<JumpTypeResp>>(`${this.apiUrl}/JumpType`, {
|
let callToApi = this.http.get<Array<JumpTypeResp>>(`${this.apiUrl}/JumpType`, { headers: this.headers });
|
||||||
headers: this.headers
|
return this.serviceRefData.get<Array<JumpTypeResp>>(RefData.JumpType, callToApi);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public AddJumpType(jumptypetName: string) {
|
public AddJumpType(jumptypetName: string) {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { Injectable } from '@angular/core';
|
|||||||
import { BehaviorSubject } from 'rxjs';
|
import { BehaviorSubject } from 'rxjs';
|
||||||
import { AddAction } from '../models/add-action.enum';
|
import { AddAction } from '../models/add-action.enum';
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ServiceComm {
|
export class ServiceComm {
|
||||||
private componentTitleSource = new BehaviorSubject<string>('');
|
private componentTitleSource = new BehaviorSubject<string>('');
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { Observable } from 'rxjs/Observable';
|
||||||
|
import { tap } from 'rxjs/operators';
|
||||||
|
import { RefData } from '../models/ref-data.enum';
|
||||||
|
import { of } from 'rxjs';
|
||||||
|
//import 'rxjs/add/observable/of';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root',
|
||||||
|
})
|
||||||
|
export class ServiceRefData {
|
||||||
|
private cache: Map<RefData, Observable<any>>;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.cache = new Map<RefData, Observable<any>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public get<T>(key: RefData, callToApi: Observable<T>) : Observable<T> {
|
||||||
|
const cached = this.cache.get(key);
|
||||||
|
|
||||||
|
if (cached) {
|
||||||
|
return cached;
|
||||||
|
} else {
|
||||||
|
return callToApi.pipe(
|
||||||
|
tap(event => {
|
||||||
|
this.cache.set(key, of(event));
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user