34 lines
1.0 KiB
TypeScript
34 lines
1.0 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
import { HttpClient } from '@angular/common/http';
|
|
import { Observable } from 'rxjs';
|
|
import { UnidadInformacion } from '../models/unidad-informacion.model';
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class UnidadInformacionService {
|
|
private apiUrl = 'api/unidades';
|
|
|
|
constructor(private http: HttpClient) {}
|
|
|
|
getUnidades(): Observable<UnidadInformacion[]> {
|
|
return this.http.get<UnidadInformacion[]>(this.apiUrl);
|
|
}
|
|
|
|
getUnidadById(id: number): Observable<UnidadInformacion> {
|
|
return this.http.get<UnidadInformacion>(`${this.apiUrl}/${id}`);
|
|
}
|
|
|
|
createUnidad(unidad: UnidadInformacion): Observable<UnidadInformacion> {
|
|
return this.http.post<UnidadInformacion>(this.apiUrl, unidad);
|
|
}
|
|
|
|
updateUnidad(unidad: UnidadInformacion): Observable<UnidadInformacion> {
|
|
return this.http.put<UnidadInformacion>(`${this.apiUrl}/${unidad.id}`, unidad);
|
|
}
|
|
|
|
deleteUnidad(id: number): Observable<void> {
|
|
return this.http.delete<void>(`${this.apiUrl}/${id}`);
|
|
}
|
|
}
|