import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Injectable, inject } from '@angular/core'; import { Observable } from 'rxjs'; import { catchError } from 'rxjs/operators'; import { ErrorLoggerService } from '../core/error-logger.service'; import { Product } from '../core/product'; const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }), }; const url = '/api/temporal-products'; const serviceName = 'ProductService'; @Injectable({ providedIn: 'root' }) export class TemporalProductService { private http = inject(HttpClient); private log = inject(ErrorLoggerService); get(id: string): Observable { return this.http .get(`${url}/${id}`) .pipe(catchError(this.log.handleError(serviceName, `get id=${id}`))) as Observable; } list(): Observable { return this.http .get(`${url}/list`) .pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable; } update(product: Product): Observable { return this.http .put(`${url}/${product.versionId}`, product, httpOptions) .pipe(catchError(this.log.handleError(serviceName, 'update'))) as Observable; } delete(id: string): Observable { return this.http .delete(`${url}/${id}`, httpOptions) .pipe(catchError(this.log.handleError(serviceName, 'delete'))) as Observable; } }