36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
import { HttpClient } from '@angular/common/http';
|
|
import { inject, Injectable } from "@angular/core";
|
|
import { map, Observable } from 'rxjs';
|
|
import { API_BASE_PATH } from "../api-base-path";
|
|
|
|
@Injectable({
|
|
providedIn: 'root',
|
|
})
|
|
export class CarClient {
|
|
private readonly http = inject(HttpClient);
|
|
private readonly apiBasePath = inject(API_BASE_PATH, { optional: true });
|
|
|
|
getAll(): Observable<GetCarsResponse> {
|
|
return this.http.get<GetCarsResponse>(`${this.apiBasePath}/v1/cars`);
|
|
}
|
|
|
|
getSingle(id: string): Observable<Car> {
|
|
return this.http.get<Car>(`${this.apiBasePath}/v1/cars/${id}`);
|
|
}
|
|
|
|
create(request: CreateCarRequest): Observable<Car> {
|
|
return this.http.post<Car>(`${this.apiBasePath}/v1/cars`, request);
|
|
}
|
|
|
|
update(id: string, request: UpdateCarRequest): Observable<Car> {
|
|
return this.http.put<Car>(`${this.apiBasePath}/v1/cars/${id}`, request);
|
|
}
|
|
|
|
delete(id: string): Observable<void> {
|
|
return this.http.delete(`${this.apiBasePath}/v1/cars/${id}`)
|
|
.pipe(
|
|
map(_ => undefined)
|
|
);
|
|
}
|
|
}
|