1 import { HttpClient } from '@angular/common/http';
2 import { Injectable } from '@angular/core';
4 import { Observable } from 'rxjs';
5 import { map } from 'rxjs/operators';
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';
11 import { ApiModule } from './api.module';
16 export class HostService {
19 constructor(private http: HttpClient, private deviceService: DeviceService) {}
22 return this.http.get(this.baseURL);
25 create(hostname: string) {
26 return this.http.post(this.baseURL, { hostname: hostname }, { observe: 'response' });
29 delete(hostname: string) {
30 return this.http.delete(`${this.baseURL}/${hostname}`, { observe: 'response' });
33 getDevices(hostname: string): Observable<CdDevice[]> {
35 .get<CdDevice[]>(`${this.baseURL}/${hostname}/devices`)
36 .pipe(map((devices) => devices.map((device) => this.deviceService.prepareDevice(device))));
39 getSmartData(hostname: string) {
40 return this.http.get<SmartDataResponseV1>(`${this.baseURL}/${hostname}/smart`);
43 getDaemons(hostname: string): Observable<Daemon[]> {
44 return this.http.get<Daemon[]>(`${this.baseURL}/${hostname}/daemons`);