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 PrinterService {
|
||||
private http = inject(HttpClient);
|
||||
private log = inject(ErrorLoggerService);
|
||||
|
||||
get(id: string | null): Observable<Printer> {
|
||||
const getUrl: string = id === null ? url : `${url}/${id}`;
|
||||
return this.http
|
||||
.get<Printer>(getUrl)
|
||||
.pipe(catchError(this.log.handleError(serviceName, `get id=${id}`))) as Observable<Printer>;
|
||||
get(id: Signal<string | null> | string | null): HttpResourceRef<Printer | undefined> {
|
||||
return httpResource<Printer>(() => {
|
||||
const idVal = typeof id === 'function' ? id() : id;
|
||||
return idVal === null || idVal === undefined ? url : `${url}/${idVal}`;
|
||||
});
|
||||
}
|
||||
|
||||
list(): Observable<Printer[]> {
|
||||
return this.http
|
||||
.get<Printer[]>(`${url}/list`)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable<Printer[]>;
|
||||
list(): HttpResourceRef<Printer[] | undefined> {
|
||||
return httpResource<Printer[]>(() => `${url}/list`);
|
||||
}
|
||||
|
||||
save(printer: Printer): Observable<Printer> {
|
||||
|
||||
Reference in New Issue
Block a user