Files
pv-pulse-angular-app/src/app/core/services/pv-plant.service.ts

28 lines
1.0 KiB
TypeScript

import { inject, Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { PvPlant } from '../models/pv-plant.model';
import { ApiResponse } from '../models/api-response.model';
import { SettingsService } from './settings.service';
@Injectable({ providedIn: 'root' })
export class PvPlantService {
private readonly http = inject(HttpClient);
private readonly settingsService = inject(SettingsService);
getAll(): Observable<PvPlant[]> {
const { apiBaseUrl, endpointPlants } = this.settingsService.settings();
return this.http
.get<ApiResponse<PvPlant[]>>(apiBaseUrl + endpointPlants)
.pipe(map((res) => res.data));
}
getById(id: string): Observable<PvPlant> {
const { apiBaseUrl, endpointPlants } = this.settingsService.settings();
return this.http
.get<ApiResponse<PvPlant>>(`${apiBaseUrl}${endpointPlants}/${encodeURIComponent(id)}`)
.pipe(map((res) => res.data));
}
}