1 | import {Injectable} from '@angular/core';
|
---|
2 | import {Observable} from "rxjs";
|
---|
3 | import {StartRouteInstanceRequest} from "../../model/requests/StartRouteInstanceRequest";
|
---|
4 | import {RouteInstanceResponse} from "../../model/responses/RouteInstanceResponse";
|
---|
5 | import {HttpClient, HttpHeaders} from "@angular/common/http";
|
---|
6 | import {StartCommuteRequest} from "../../model/requests/StartCommuteRequest";
|
---|
7 | import {CommuteResponse} from "../../model/responses/CommuteResponse";
|
---|
8 |
|
---|
9 | @Injectable({
|
---|
10 | providedIn: 'root'
|
---|
11 | })
|
---|
12 | export class RouteInstanceService {
|
---|
13 | private url = '/api/route-instances'
|
---|
14 |
|
---|
15 | constructor(private http: HttpClient) {
|
---|
16 | }
|
---|
17 |
|
---|
18 | start(request: StartRouteInstanceRequest): Observable<RouteInstanceResponse> {
|
---|
19 | return this.http.post<RouteInstanceResponse>(`${this.url}/start`, JSON.stringify(request), {
|
---|
20 | headers: new HttpHeaders({'Content-Type': 'application/json'})
|
---|
21 | })
|
---|
22 | }
|
---|
23 |
|
---|
24 | getById(id: number): Observable<RouteInstanceResponse> {
|
---|
25 | return this.http.get<RouteInstanceResponse>(`${this.url}/${id}`)
|
---|
26 | }
|
---|
27 |
|
---|
28 | stop(id: number): Observable<RouteInstanceResponse> {
|
---|
29 | return this.http.patch<RouteInstanceResponse>(`${this.url}/stop`, JSON.stringify(id), {
|
---|
30 | headers: new HttpHeaders({'Content-Type': 'application/json'})
|
---|
31 | })
|
---|
32 | }
|
---|
33 |
|
---|
34 | getForStation(id: number): Observable<RouteInstanceResponse[]> {
|
---|
35 | return this.http.get<RouteInstanceResponse[]>(`${this.url}/station/${id}`)
|
---|
36 | }
|
---|
37 |
|
---|
38 | getAll(): Observable<RouteInstanceResponse[]> {
|
---|
39 | return this.http.get<RouteInstanceResponse[]>(`${this.url}`)
|
---|
40 | }
|
---|
41 | }
|
---|