From cc56f3def0f80ce70b5d6534aaad8c8f97fcccef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20ANDRE?= Date: Thu, 29 Jun 2023 16:00:28 +0200 Subject: [PATCH] Call API to get the tunnel flights --- .../new-tunnel-flight.component.ts | 2 +- .../src/models/tunnel-flight.ts | 26 +++++++++++++++++++ .../src/services/tunnel-flight.service.ts | 25 +++++++++++++----- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/Front/skydivelogs-app/src/app/new-tunnel-flight/new-tunnel-flight.component.ts b/Front/skydivelogs-app/src/app/new-tunnel-flight/new-tunnel-flight.component.ts index d0abb01..a67bd56 100644 --- a/Front/skydivelogs-app/src/app/new-tunnel-flight/new-tunnel-flight.component.ts +++ b/Front/skydivelogs-app/src/app/new-tunnel-flight/new-tunnel-flight.component.ts @@ -106,7 +106,7 @@ export class NewTunnelFlightComponent implements OnInit { private updateTitle() { this.translateService.get("NewTunnelFlight_Title").subscribe( - data => { this.serviceComm.UpdatedComponentTitle(data); } + data => { this.serviceComm.updatedComponentTitle(data); } ); } diff --git a/Front/skydivelogs-app/src/models/tunnel-flight.ts b/Front/skydivelogs-app/src/models/tunnel-flight.ts index c05403f..43c9b91 100644 --- a/Front/skydivelogs-app/src/models/tunnel-flight.ts +++ b/Front/skydivelogs-app/src/models/tunnel-flight.ts @@ -8,4 +8,30 @@ export class TunnelFlightReq { public nbMinutes: number; public notes: string; public flightDate: string; +} + +export class TunnelFlightResp { + constructor(data: any) { + Object.assign(this, data); + this.flightDate = new Date(data.flightDate); + } + + public id: number; + public tunnelId: number; + public nbMinutes: number; + public notes: string; + public flightDate: Date; +} + +export class TunnelFlight { + constructor(data: any) { + Object.assign(this, data); + this.flightDate = new Date(data.flightDate); + } + + public id: number; + public tunnelId: number; + public nbMinutes: number; + public notes: string; + public flightDate: Date; } \ No newline at end of file diff --git a/Front/skydivelogs-app/src/services/tunnel-flight.service.ts b/Front/skydivelogs-app/src/services/tunnel-flight.service.ts index bd40229..95e1dd2 100644 --- a/Front/skydivelogs-app/src/services/tunnel-flight.service.ts +++ b/Front/skydivelogs-app/src/services/tunnel-flight.service.ts @@ -1,23 +1,23 @@ import { Injectable } from "@angular/core"; import { DatePipe } from "@angular/common"; import { HttpClient } from "@angular/common/http"; +import { Observable } from "rxjs"; +import { map } from "rxjs/operators"; -import { TunnelFlightReq } from "../models/tunnel-flight"; +import { TunnelFlightReq, TunnelFlightResp, TunnelFlight } from "../models/tunnel-flight"; import { BaseService } from "./base.service"; @Injectable() export class TunnelFlightService extends BaseService { - constructor(private http: HttpClient, - private datePipe: DatePipe) { + constructor(private http: HttpClient, private datePipe: DatePipe) { super(); } public addFlight(selectedTunnel: number, flightDate: Date, nbMinutes: number, - comment: string) - { + comment: string) { const bodyNewFlight: TunnelFlightReq = { id: 0, @@ -27,6 +27,19 @@ export class TunnelFlightService extends BaseService { nbMinutes: nbMinutes }; - return this.http.post(`${this.apiUrl}/TunnelFlight`, bodyNewFlight, { headers: this.headers}); + return this.http.post(`${this.apiUrl}/TunnelFlight`, bodyNewFlight, { headers: this.headers }); + } + + public getTunnelFlights(begin: Date, end: Date): Observable> { + let beginDate = this.datePipe.transform(begin, "yyyyMMdd"); + let endDate = this.datePipe.transform(end, "yyyyMMdd"); + + return this.http.get>(`${this.apiUrl}/TunnelFlight/${beginDate}/${endDate}`, { headers: this.headers }) + .pipe( + map(response => { + const stats = response.map(data => new TunnelFlightResp(data)); + return stats; + }) + ); } }