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