Commit 9399ec8c authored by Thomas Frion's avatar Thomas Frion

[FEAT] Add Station api client

parent 3a3cb821
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import * as models from '../models/models';
import { ApiService } from '../api';
import { IClient } from './iclient';
import { AuthGuard } from 'src/app/services/auth-guard.service';
@Injectable({
providedIn: 'root'
})
export class StationService extends ApiService<models.IStation> implements IClient<models.IStation> {
constructor(protected http: HttpClient, protected authGuard : AuthGuard) {
super(http, authGuard);
}
public all(headers?: HttpHeaders): Promise<models.IStation[]> {
return this.get('/units/police', headers);
}
public one(selector: any, headers?: HttpHeaders): Promise<models.IStation> {
return this.read('/units/police'+selector, headers);
}
public save(elem: models.IStation, headers?: HttpHeaders): Promise<models.IStation> {
let res : Promise<models.IStation>;
if(elem.id !== undefined){
res = this.update('/units/police'+elem.id, JSON.stringify(elem), headers);
} else {
res = this.create('/units/police', JSON.stringify(elem), headers);
}
return res;
}
public remove(elem: models.IStation, headers?: HttpHeaders): boolean {
return this.delete('/units/police'+elem.id, headers);
}
}
......@@ -2,4 +2,5 @@ export * from './service';
export * from './token';
export * from './unit';
export * from './user';
export * from './webcam';
\ No newline at end of file
export * from './webcam';
export * from './station';
\ No newline at end of file
import { Webcam } from './webcam';
export interface IStation {
readonly id?: number,
name : string,
dept : string,
location : string,
area : string,
webcams : Webcam[]
}
export class Station {
readonly id?: number;
name : string;
dept : string;
location : string;
area : string;
webcams : Webcam[];
constructor(contract : IStation){
this.id = contract.id;
this.name = contract.name;
this.dept = contract.dept;
this.location = contract.location
this.area = contract.area;
this.webcams = contract.webcams;
}
public getWebcam(name : string) : Webcam {
let webcam : Webcam = null;
let i = 0;
while(webcam == null && i < this.webcams.length){
if(this.webcams[i].name == name){
webcam = this.webcams[i];
}
i++;
}
return webcam;
}
}
\ No newline at end of file
......@@ -5,6 +5,7 @@ import { AuthService } from './auth.service';
import { GendUnitService } from './api/clients/gendunit.service';
import { PoliceService } from './api/clients/police.service';
import { ServiceService } from './api/clients/service.service'
import { StationService } from './api/clients/station.service';
import { TokenService } from './api/clients/token.service'
import { UnitService } from './api/clients/unit.service'
import { UserService } from './api/clients/user.service'
......@@ -20,6 +21,7 @@ import { WebcamService } from './api/clients/webcam.service'
GendUnitService,
PoliceService,
ServiceService,
StationService,
TokenService,
UnitService,
UserService,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment