]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | import { HttpClient } from '@angular/common/http'; |
2 | import { Injectable } from '@angular/core'; | |
3 | ||
9f95a23c TL |
4 | import { Observable } from 'rxjs'; |
5 | import { map } from 'rxjs/operators'; | |
6 | ||
7 | import { Daemon } from '../models/daemon.interface'; | |
8 | import { CdDevice } from '../models/devices'; | |
9 | import { SmartDataResponseV1 } from '../models/smart'; | |
10 | import { DeviceService } from '../services/device.service'; | |
11fdf7f2 TL |
11 | import { ApiModule } from './api.module'; |
12 | ||
13 | @Injectable({ | |
14 | providedIn: ApiModule | |
15 | }) | |
16 | export class HostService { | |
9f95a23c TL |
17 | baseURL = 'api/host'; |
18 | ||
19 | constructor(private http: HttpClient, private deviceService: DeviceService) {} | |
11fdf7f2 TL |
20 | |
21 | list() { | |
9f95a23c TL |
22 | return this.http.get(this.baseURL); |
23 | } | |
24 | ||
25 | create(hostname: string) { | |
26 | return this.http.post(this.baseURL, { hostname: hostname }, { observe: 'response' }); | |
27 | } | |
28 | ||
29 | delete(hostname: string) { | |
30 | return this.http.delete(`${this.baseURL}/${hostname}`, { observe: 'response' }); | |
31 | } | |
32 | ||
33 | getDevices(hostname: string): Observable<CdDevice[]> { | |
11fdf7f2 | 34 | return this.http |
9f95a23c TL |
35 | .get<CdDevice[]>(`${this.baseURL}/${hostname}/devices`) |
36 | .pipe(map((devices) => devices.map((device) => this.deviceService.prepareDevice(device)))); | |
37 | } | |
38 | ||
39 | getSmartData(hostname: string) { | |
40 | return this.http.get<SmartDataResponseV1>(`${this.baseURL}/${hostname}/smart`); | |
41 | } | |
42 | ||
43 | getDaemons(hostname: string): Observable<Daemon[]> { | |
44 | return this.http.get<Daemon[]>(`${this.baseURL}/${hostname}/daemons`); | |
11fdf7f2 TL |
45 | } |
46 | } |