Modif des services avec l'utilisation d'un "BaseService"
This commit is contained in:
@@ -1,20 +1,21 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
import { HttpClient } from '@angular/common/http';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { environment } from '../environments/environment';
|
|
||||||
import { AircraftResp, AircraftReq } from '../models/aircraft';
|
import { AircraftResp, AircraftReq } from '../models/aircraft';
|
||||||
|
|
||||||
@Injectable()
|
import { BaseService } from './base.service';
|
||||||
export class AircraftService {
|
|
||||||
|
|
||||||
private readonly headers = new HttpHeaders({
|
|
||||||
'Access-Control-Allow-Origin': environment.apiUrl
|
@Injectable()
|
||||||
});
|
export class AircraftService extends BaseService {
|
||||||
constructor(private http: HttpClient) { }
|
constructor(private http: HttpClient) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
public getListOfAircrafts(): Observable<Array<AircraftResp>> {
|
public getListOfAircrafts(): Observable<Array<AircraftResp>> {
|
||||||
return this.http.get<Array<AircraftResp>>(
|
return this.http.get<Array<AircraftResp>>(
|
||||||
`${environment.apiUrl}/api/Aircraft`,
|
`${this.apiUrl}/Aircraft`,
|
||||||
{ headers: this.headers }
|
{ headers: this.headers }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -26,7 +27,7 @@ export class AircraftService {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.http
|
this.http
|
||||||
.post(`${environment.apiUrl}/api/Aircraft`, bodyNewAircraft, {
|
.post(`${this.apiUrl}/Aircraft`, bodyNewAircraft, {
|
||||||
headers: this.headers
|
headers: this.headers
|
||||||
})
|
})
|
||||||
.subscribe(data => console.log(data));
|
.subscribe(data => console.log(data));
|
||||||
|
|||||||
@@ -1,24 +1,23 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
import { HttpClient } from '@angular/common/http';
|
||||||
|
|
||||||
import { BehaviorSubject, Observable } from 'rxjs';
|
import { BehaviorSubject, Observable } from 'rxjs';
|
||||||
import { map } from 'rxjs/operators';
|
import { map } from 'rxjs/operators';
|
||||||
|
|
||||||
import { environment } from '../environments/environment';
|
|
||||||
import { User } from '../models/user';
|
import { User } from '../models/user';
|
||||||
|
import { BaseService } from './base.service';
|
||||||
|
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class AuthenticationService {
|
export class AuthenticationService extends BaseService {
|
||||||
private readonly headers = new HttpHeaders({
|
|
||||||
'Access-Control-Allow-Origin': environment.apiUrl
|
|
||||||
});
|
|
||||||
private currentUserSubject: BehaviorSubject<User>;
|
private currentUserSubject: BehaviorSubject<User>;
|
||||||
public currentUser: Observable<User>;
|
public currentUser: Observable<User>;
|
||||||
|
|
||||||
constructor(private http: HttpClient) {
|
constructor(private http: HttpClient) {
|
||||||
|
super();
|
||||||
|
|
||||||
this.currentUserSubject = new BehaviorSubject<User>(JSON.parse(localStorage.getItem('currentUser')));
|
this.currentUserSubject = new BehaviorSubject<User>(JSON.parse(localStorage.getItem('currentUser')));
|
||||||
this.currentUser = this.currentUserSubject.asObservable();
|
this.currentUser = this.currentUserSubject.asObservable();
|
||||||
}
|
}
|
||||||
@@ -33,7 +32,7 @@ export class AuthenticationService {
|
|||||||
password: password
|
password: password
|
||||||
};
|
};
|
||||||
|
|
||||||
return this.http.post<any>(`${environment.apiUrl}/api/User/Authenticate`, bodyLogin, {
|
return this.http.post<any>(`${this.apiUrl}/User/Authenticate`, bodyLogin, {
|
||||||
headers: this.headers
|
headers: this.headers
|
||||||
})
|
})
|
||||||
.pipe(map(user => {
|
.pipe(map(user => {
|
||||||
|
|||||||
18
Front/skydivelogs-app/src/services/base.service.ts
Normal file
18
Front/skydivelogs-app/src/services/base.service.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { HttpHeaders } from '@angular/common/http';
|
||||||
|
import { environment } from '../environments/environment';
|
||||||
|
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class BaseService {
|
||||||
|
protected readonly headers: HttpHeaders;
|
||||||
|
protected readonly apiUrl: string;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.headers = new HttpHeaders({
|
||||||
|
'Access-Control-Allow-Origin': environment.apiUrl
|
||||||
|
});
|
||||||
|
|
||||||
|
this.apiUrl = environment.apiUrl + '/api';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,22 +1,22 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
import { HttpClient } from '@angular/common/http';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { map } from 'rxjs/operators';
|
import { map } from 'rxjs/operators';
|
||||||
import { environment } from '../environments/environment';
|
|
||||||
import { DropZoneResp } from '../models/dropzone';
|
import { DropZoneResp } from '../models/dropzone';
|
||||||
|
|
||||||
|
import { BaseService } from './base.service';
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class DropzoneService {
|
export class DropzoneService extends BaseService {
|
||||||
|
constructor(private http: HttpClient) {
|
||||||
private readonly headers = new HttpHeaders({
|
super();
|
||||||
'Access-Control-Allow-Origin': environment.apiUrl
|
}
|
||||||
});
|
|
||||||
constructor(private http: HttpClient) { }
|
|
||||||
|
|
||||||
public getListOfDropZones(): Observable<Array<DropZoneResp>> {
|
public getListOfDropZones(): Observable<Array<DropZoneResp>> {
|
||||||
return this.http
|
return this.http
|
||||||
.get<Array<DropZoneResp>>(`${environment.apiUrl}/api/DropZone`, {
|
.get<Array<DropZoneResp>>(`${this.apiUrl}/DropZone`, {
|
||||||
headers: this.headers
|
headers: this.headers
|
||||||
})
|
})
|
||||||
.pipe(
|
.pipe(
|
||||||
@@ -30,7 +30,7 @@ export class DropzoneService {
|
|||||||
public SetFavoriteDropZone(selectedDz: DropZoneResp): boolean {
|
public SetFavoriteDropZone(selectedDz: DropZoneResp): boolean {
|
||||||
selectedDz.isFavorite = true;
|
selectedDz.isFavorite = true;
|
||||||
this.http
|
this.http
|
||||||
.put(`${environment.apiUrl}/api/DropZone/${selectedDz.id}`, selectedDz, {
|
.put(`${this.apiUrl}/DropZone/${selectedDz.id}`, selectedDz, {
|
||||||
headers: this.headers
|
headers: this.headers
|
||||||
})
|
})
|
||||||
.subscribe(data => console.log(data));
|
.subscribe(data => console.log(data));
|
||||||
@@ -41,12 +41,11 @@ export class DropzoneService {
|
|||||||
public RemoveFavoriteDropZone(selectedDz: DropZoneResp): boolean {
|
public RemoveFavoriteDropZone(selectedDz: DropZoneResp): boolean {
|
||||||
selectedDz.isFavorite = false;
|
selectedDz.isFavorite = false;
|
||||||
this.http
|
this.http
|
||||||
.put(`${environment.apiUrl}/api/DropZone/${selectedDz.id}`, selectedDz, {
|
.put(`${this.apiUrl}/DropZone/${selectedDz.id}`, selectedDz, {
|
||||||
headers: this.headers
|
headers: this.headers
|
||||||
})
|
})
|
||||||
.subscribe(data => console.log(data));
|
.subscribe(data => console.log(data));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
import { HttpClient } from '@angular/common/http';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { environment } from '../environments/environment';
|
|
||||||
import { GearResp, GearReq } from '../models/gear';
|
import { GearResp, GearReq } from '../models/gear';
|
||||||
|
|
||||||
|
import { BaseService } from './base.service';
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class GearService {
|
export class GearService extends BaseService {
|
||||||
|
constructor(private http: HttpClient) {
|
||||||
private readonly headers = new HttpHeaders({
|
super();
|
||||||
'Access-Control-Allow-Origin': environment.apiUrl
|
}
|
||||||
});
|
|
||||||
constructor(private http: HttpClient) { }
|
|
||||||
|
|
||||||
public getListOfGears(): Observable<Array<GearResp>> {
|
public getListOfGears(): Observable<Array<GearResp>> {
|
||||||
return this.http.get<Array<GearResp>>(`${environment.apiUrl}/api/Gear`, {
|
return this.http.get<Array<GearResp>>(`${this.apiUrl}/Gear`, {
|
||||||
headers: this.headers
|
headers: this.headers
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -38,7 +38,7 @@ export class GearService {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.http
|
this.http
|
||||||
.post(`${environment.apiUrl}/api/Gear`, bodyNewGear, {
|
.post(`${this.apiUrl}/Gear`, bodyNewGear, {
|
||||||
headers: this.headers
|
headers: this.headers
|
||||||
})
|
})
|
||||||
.subscribe(data => console.log(data));
|
.subscribe(data => console.log(data));
|
||||||
|
|||||||
@@ -1,20 +1,21 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
import { HttpClient } from '@angular/common/http';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { environment } from '../environments/environment';
|
|
||||||
import { JumpTypeResp } from '../models/jumpType';
|
import { JumpTypeResp } from '../models/jumpType';
|
||||||
|
|
||||||
@Injectable()
|
import { BaseService } from './base.service';
|
||||||
export class JumpTypeService {
|
|
||||||
|
|
||||||
private readonly headers = new HttpHeaders({
|
|
||||||
'Access-Control-Allow-Origin': environment.apiUrl
|
@Injectable()
|
||||||
});
|
export class JumpTypeService extends BaseService {
|
||||||
constructor(private http: HttpClient) { }
|
constructor(private http: HttpClient) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
public getListOfJumpTypes(): Observable<Array<JumpTypeResp>> {
|
public getListOfJumpTypes(): Observable<Array<JumpTypeResp>> {
|
||||||
return this.http.get<Array<JumpTypeResp>>(
|
return this.http.get<Array<JumpTypeResp>>(
|
||||||
`${environment.apiUrl}/api/JumpType`,
|
`${this.apiUrl}/JumpType`,
|
||||||
{ headers: this.headers }
|
{ headers: this.headers }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,22 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
import { HttpClient } from '@angular/common/http';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { map } from 'rxjs/operators';
|
import { map } from 'rxjs/operators';
|
||||||
import { environment } from '../environments/environment';
|
|
||||||
import { DateService } from './date.service';
|
|
||||||
import { JumpResp, JumpReq } from '../models/jump';
|
import { JumpResp, JumpReq } from '../models/jump';
|
||||||
|
|
||||||
@Injectable()
|
import { DateService } from './date.service';
|
||||||
export class JumpService {
|
import { BaseService } from './base.service';
|
||||||
|
|
||||||
private readonly headers = new HttpHeaders({
|
|
||||||
'Access-Control-Allow-Origin': environment.apiUrl
|
@Injectable()
|
||||||
});
|
export class JumpService extends BaseService {
|
||||||
constructor(private http: HttpClient, private dateService: DateService) { }
|
constructor(private http: HttpClient, private dateService: DateService) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
public getListOfJumps(): Observable<Array<JumpResp>> {
|
public getListOfJumps(): Observable<Array<JumpResp>> {
|
||||||
return this.http.get<Array<JumpResp>>(`${environment.apiUrl}/api/Jump`, {
|
return this.http.get<Array<JumpResp>>(`${this.apiUrl}/Jump`, {
|
||||||
headers: this.headers
|
headers: this.headers
|
||||||
})
|
})
|
||||||
.pipe(
|
.pipe(
|
||||||
@@ -98,7 +99,7 @@ export class JumpService {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.http
|
this.http
|
||||||
.post(`${environment.apiUrl}/api/Jump`, bodyNewjump, {
|
.post(`${this.apiUrl}/Jump`, bodyNewjump, {
|
||||||
headers: this.headers
|
headers: this.headers
|
||||||
})
|
})
|
||||||
.subscribe(data => console.log(data));
|
.subscribe(data => console.log(data));
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
import { HttpClient } from '@angular/common/http';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { map } from 'rxjs/operators';
|
import { map } from 'rxjs/operators';
|
||||||
import { environment } from '../environments/environment';
|
|
||||||
import {
|
import {
|
||||||
StatsResp,
|
StatsResp,
|
||||||
StatsByDzResp,
|
StatsByDzResp,
|
||||||
@@ -15,13 +15,14 @@ import {
|
|||||||
SimpleSummary
|
SimpleSummary
|
||||||
} from '../models/stats';
|
} from '../models/stats';
|
||||||
|
|
||||||
@Injectable()
|
import { BaseService } from './base.service';
|
||||||
export class StatsService {
|
|
||||||
private readonly headers = new HttpHeaders({
|
|
||||||
'Access-Control-Allow-Origin': environment.apiUrl
|
|
||||||
});
|
|
||||||
|
|
||||||
constructor(private http: HttpClient) { }
|
|
||||||
|
@Injectable()
|
||||||
|
export class StatsService extends BaseService {
|
||||||
|
constructor(private http: HttpClient) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
public getStatsOfJumps(): StatsResp {
|
public getStatsOfJumps(): StatsResp {
|
||||||
const resultats = new StatsResp();
|
const resultats = new StatsResp();
|
||||||
@@ -42,7 +43,7 @@ export class StatsService {
|
|||||||
|
|
||||||
private getSimpleSummary(): Observable<SimpleSummary> {
|
private getSimpleSummary(): Observable<SimpleSummary> {
|
||||||
return this.http
|
return this.http
|
||||||
.get<Array<SimpleSummary>>(`${environment.apiUrl}/api/Stats/Simple`, {
|
.get<Array<SimpleSummary>>(`${this.apiUrl}/Stats/Simple`, {
|
||||||
headers: this.headers
|
headers: this.headers
|
||||||
})
|
})
|
||||||
.pipe(
|
.pipe(
|
||||||
@@ -55,7 +56,7 @@ export class StatsService {
|
|||||||
|
|
||||||
private getStatsByDz(): Observable<Array<StatsByDzResp>> {
|
private getStatsByDz(): Observable<Array<StatsByDzResp>> {
|
||||||
return this.http
|
return this.http
|
||||||
.get<Array<StatsByDzResp>>(`${environment.apiUrl}/api/Stats/ByDz`, {
|
.get<Array<StatsByDzResp>>(`${this.apiUrl}/Stats/ByDz`, {
|
||||||
headers: this.headers
|
headers: this.headers
|
||||||
})
|
})
|
||||||
.pipe(
|
.pipe(
|
||||||
@@ -69,7 +70,7 @@ export class StatsService {
|
|||||||
private getStatsByAircraft(): Observable<Array<StatsByAircraftResp>> {
|
private getStatsByAircraft(): Observable<Array<StatsByAircraftResp>> {
|
||||||
return this.http
|
return this.http
|
||||||
.get<Array<StatsByAircraftResp>>(
|
.get<Array<StatsByAircraftResp>>(
|
||||||
`${environment.apiUrl}/api/Stats/ByAircraft`,
|
`${this.apiUrl}/Stats/ByAircraft`,
|
||||||
{ headers: this.headers }
|
{ headers: this.headers }
|
||||||
)
|
)
|
||||||
.pipe(
|
.pipe(
|
||||||
@@ -83,7 +84,7 @@ export class StatsService {
|
|||||||
private getStatsByJumpType(): Observable<Array<StatsByJumpTypeResp>> {
|
private getStatsByJumpType(): Observable<Array<StatsByJumpTypeResp>> {
|
||||||
return this.http
|
return this.http
|
||||||
.get<Array<StatsByJumpTypeResp>>(
|
.get<Array<StatsByJumpTypeResp>>(
|
||||||
`${environment.apiUrl}/api/Stats/ByJumpType`,
|
`${this.apiUrl}/Stats/ByJumpType`,
|
||||||
{ headers: this.headers }
|
{ headers: this.headers }
|
||||||
)
|
)
|
||||||
.pipe(
|
.pipe(
|
||||||
@@ -96,7 +97,7 @@ export class StatsService {
|
|||||||
|
|
||||||
private getStatsByGear(): Observable<Array<StatsByGearResp>> {
|
private getStatsByGear(): Observable<Array<StatsByGearResp>> {
|
||||||
return this.http
|
return this.http
|
||||||
.get<Array<StatsByGearResp>>(`${environment.apiUrl}/api/Stats/ByGear`, {
|
.get<Array<StatsByGearResp>>(`${this.apiUrl}/Stats/ByGear`, {
|
||||||
headers: this.headers
|
headers: this.headers
|
||||||
})
|
})
|
||||||
.pipe(
|
.pipe(
|
||||||
@@ -109,7 +110,7 @@ export class StatsService {
|
|||||||
|
|
||||||
private getStatsByYear(): Observable<Array<StatsByYearResp>> {
|
private getStatsByYear(): Observable<Array<StatsByYearResp>> {
|
||||||
return this.http
|
return this.http
|
||||||
.get<Array<StatsByYearResp>>(`${environment.apiUrl}/api/Stats/ByYear`, {
|
.get<Array<StatsByYearResp>>(`${this.apiUrl}/Stats/ByYear`, {
|
||||||
headers: this.headers
|
headers: this.headers
|
||||||
})
|
})
|
||||||
.pipe(
|
.pipe(
|
||||||
@@ -123,7 +124,7 @@ export class StatsService {
|
|||||||
private getStatsOfLastYear(): Observable<StatsForLastYearResp> {
|
private getStatsOfLastYear(): Observable<StatsForLastYearResp> {
|
||||||
return this.http
|
return this.http
|
||||||
.get<StatsForLastYearResp>(
|
.get<StatsForLastYearResp>(
|
||||||
`${environment.apiUrl}/api/Stats/ForLastYear`,
|
`${this.apiUrl}/Stats/ForLastYear`,
|
||||||
{ headers: this.headers }
|
{ headers: this.headers }
|
||||||
)
|
)
|
||||||
.pipe(
|
.pipe(
|
||||||
@@ -141,7 +142,7 @@ export class StatsService {
|
|||||||
private getStatsOfLastMonth(): Observable<StatsForLastMonthResp> {
|
private getStatsOfLastMonth(): Observable<StatsForLastMonthResp> {
|
||||||
return this.http
|
return this.http
|
||||||
.get<StatsForLastYearResp>(
|
.get<StatsForLastYearResp>(
|
||||||
`${environment.apiUrl}/api/Stats/ForLastMonth`,
|
`${this.apiUrl}/Stats/ForLastMonth`,
|
||||||
{ headers: this.headers }
|
{ headers: this.headers }
|
||||||
)
|
)
|
||||||
.pipe(
|
.pipe(
|
||||||
|
|||||||
Reference in New Issue
Block a user