Add API models and clients manually
This commit is contained in:
6
src/Vegasco-Web/src/app/api/api-base-path.ts
Normal file
6
src/Vegasco-Web/src/app/api/api-base-path.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import { InjectionToken } from "@angular/core";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The base path for all API requests, e.g. when using a proxy on the origin's address.
|
||||||
|
*/
|
||||||
|
export const API_BASE_PATH = new InjectionToken<string>('API_BASE_PATH');
|
||||||
35
src/Vegasco-Web/src/app/api/cars/car-client.ts
Normal file
35
src/Vegasco-Web/src/app/api/cars/car-client.ts
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import {inject, Injectable} from "@angular/core";
|
||||||
|
import {HttpClient} from '@angular/common/http';
|
||||||
|
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(request: UpdateCarRequest): Observable<Car> {
|
||||||
|
return this.http.put<Car>(`${this.apiBasePath}/v1/cars`, request);
|
||||||
|
}
|
||||||
|
|
||||||
|
delete(id: string): Observable<void> {
|
||||||
|
return this.http.delete(`${this.apiBasePath}/v1/cars/${id}`)
|
||||||
|
.pipe(
|
||||||
|
map(_ => undefined)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
4
src/Vegasco-Web/src/app/api/cars/car.ts
Normal file
4
src/Vegasco-Web/src/app/api/cars/car.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
interface Car {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
3
src/Vegasco-Web/src/app/api/cars/create-car-request.ts
Normal file
3
src/Vegasco-Web/src/app/api/cars/create-car-request.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
interface CreateCarRequest {
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
3
src/Vegasco-Web/src/app/api/cars/get-cars-response.ts
Normal file
3
src/Vegasco-Web/src/app/api/cars/get-cars-response.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
interface GetCarsResponse {
|
||||||
|
cars: Car[];
|
||||||
|
}
|
||||||
3
src/Vegasco-Web/src/app/api/cars/update-car-request.ts
Normal file
3
src/Vegasco-Web/src/app/api/cars/update-car-request.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
interface UpdateCarRequest {
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
import {inject, Injectable} from '@angular/core';
|
||||||
|
import {HttpClient} from '@angular/common/http';
|
||||||
|
import {API_BASE_PATH} from '../api-base-path';
|
||||||
|
import {map, Observable} from 'rxjs';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root',
|
||||||
|
})
|
||||||
|
export class ConsumptionClient {
|
||||||
|
private readonly http = inject(HttpClient);
|
||||||
|
private readonly apiBasePath = inject(API_BASE_PATH, {optional: true});
|
||||||
|
|
||||||
|
getAll(): Observable<GetConsumptionEntriesResponse> {
|
||||||
|
return this.http.get<GetConsumptionEntriesResponse>(`${this.apiBasePath}/v1/consumptions`);
|
||||||
|
}
|
||||||
|
|
||||||
|
getSingle(id: string): Observable<ConsumptionEntry> {
|
||||||
|
return this.http.get<ConsumptionEntry>(`${this.apiBasePath}/v1/consumptions/${id}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
create(request: CreateCarRequest): Observable<ConsumptionEntry> {
|
||||||
|
return this.http.post<ConsumptionEntry>(`${this.apiBasePath}/v1/consumptions`, request);
|
||||||
|
}
|
||||||
|
|
||||||
|
update(request: UpdateCarRequest): Observable<ConsumptionEntry> {
|
||||||
|
return this.http.put<ConsumptionEntry>(`${this.apiBasePath}/v1/consumptions`, request);
|
||||||
|
}
|
||||||
|
|
||||||
|
delete(id: string): Observable<void> {
|
||||||
|
return this.http.delete(`${this.apiBasePath}/v1/consumptions/${id}`)
|
||||||
|
.pipe(
|
||||||
|
map(_ => undefined),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
interface CreateConsumptionEntry {
|
||||||
|
dateTime: string;
|
||||||
|
distance: number;
|
||||||
|
amount: number;
|
||||||
|
ignoreInCalculation: boolean;
|
||||||
|
carId: string;
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
interface UpdateConsumptionEntry {
|
||||||
|
dateTime: string;
|
||||||
|
distance: number;
|
||||||
|
amount: number;
|
||||||
|
ignoreInCalculation: boolean;
|
||||||
|
carId: string;
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ import { includeBearerTokenInterceptor } from 'keycloak-angular';
|
|||||||
import { providePrimeNG } from 'primeng/config';
|
import { providePrimeNG } from 'primeng/config';
|
||||||
import { routes } from './app.routes';
|
import { routes } from './app.routes';
|
||||||
import { provideKeycloakAngular } from './auth/auth.config';
|
import { provideKeycloakAngular } from './auth/auth.config';
|
||||||
|
import {API_BASE_PATH} from './api/api-base-path';
|
||||||
|
|
||||||
export const appConfig: ApplicationConfig = {
|
export const appConfig: ApplicationConfig = {
|
||||||
providers: [
|
providers: [
|
||||||
@@ -21,5 +22,9 @@ export const appConfig: ApplicationConfig = {
|
|||||||
},
|
},
|
||||||
ripple: true
|
ripple: true
|
||||||
}),
|
}),
|
||||||
|
{
|
||||||
|
provide: API_BASE_PATH,
|
||||||
|
useValue: '/api'
|
||||||
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user