Initial commit: Angular PV Pulse App
This commit is contained in:
27
src/app/core/services/pv-plant.service.ts
Normal file
27
src/app/core/services/pv-plant.service.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user