Découpage en 1 service par composant
This commit is contained in:
35
Front/skydivelogs-app/src/services/aircraft.service.ts
Normal file
35
Front/skydivelogs-app/src/services/aircraft.service.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { environment } from '../environments/environment';
|
||||
import { AircraftResp, AircraftReq } from '../models/aircraft';
|
||||
|
||||
@Injectable()
|
||||
export class AircraftService {
|
||||
|
||||
private readonly headers = new HttpHeaders({
|
||||
'Access-Control-Allow-Origin': environment.urlApi
|
||||
});
|
||||
constructor(private http: HttpClient) { }
|
||||
|
||||
public getListOfAircrafts(): Observable<Array<AircraftResp>> {
|
||||
return this.http.get<Array<AircraftResp>>(
|
||||
`${environment.urlApi}/api/Aircraft`,
|
||||
{ headers: this.headers }
|
||||
);
|
||||
}
|
||||
|
||||
public AddAircraft(aircraftName: string) {
|
||||
const bodyNewAircraft: AircraftReq = {
|
||||
id: 0,
|
||||
name: aircraftName
|
||||
};
|
||||
|
||||
this.http
|
||||
.post(`${environment.urlApi}/api/Aircraft`, bodyNewAircraft, {
|
||||
headers: this.headers
|
||||
})
|
||||
.subscribe(data => console.log(data));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user