toSignal via Gemini
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { HttpClient, HttpHeaders, httpResource, HttpResourceRef } from '@angular/common/http';
|
||||
import { Injectable, Signal, inject } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { catchError } from 'rxjs/operators';
|
||||
|
||||
@@ -19,17 +19,15 @@ export class TaxService {
|
||||
private http = inject(HttpClient);
|
||||
private log = inject(ErrorLoggerService);
|
||||
|
||||
get(id: string | null): Observable<Tax> {
|
||||
const getUrl: string = id === null ? url : `${url}/${id}`;
|
||||
return this.http
|
||||
.get<Tax>(getUrl)
|
||||
.pipe(catchError(this.log.handleError(serviceName, `get id=${id}`))) as Observable<Tax>;
|
||||
get(id: Signal<string | null> | string | null): HttpResourceRef<Tax | undefined> {
|
||||
return httpResource<Tax>(() => {
|
||||
const idVal = typeof id === 'function' ? id() : id;
|
||||
return idVal === null || idVal === undefined ? url : `${url}/${idVal}`;
|
||||
});
|
||||
}
|
||||
|
||||
list(): Observable<Tax[]> {
|
||||
return this.http
|
||||
.get<Tax[]>(`${url}/list`)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable<Tax[]>;
|
||||
list(): HttpResourceRef<Tax[] | undefined> {
|
||||
return httpResource<Tax[]>(() => `${url}/list`);
|
||||
}
|
||||
|
||||
save(tax: Tax): Observable<Tax> {
|
||||
|
||||
Reference in New Issue
Block a user