New Angular based web version #1

Closed
thomas.nuyken wants to merge 150 commits from main into ddd
12 changed files with 108 additions and 0 deletions
Showing only changes of commit 0fa5b080d8 - Show all commits

View 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');

View 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)
);
}
}

View File

@@ -0,0 +1,4 @@
interface Car {
id: string;
name: string;
}

View File

@@ -0,0 +1,3 @@
interface CreateCarRequest {
name: string;
}

View File

@@ -0,0 +1,3 @@
interface GetCarsResponse {
cars: Car[];
}

View File

@@ -0,0 +1,3 @@
interface UpdateCarRequest {
name: string;
}

View File

@@ -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),
);
}
}

View File

@@ -0,0 +1,7 @@
interface CreateConsumptionEntry {
dateTime: string;
distance: number;
amount: number;
ignoreInCalculation: boolean;
carId: string;
}

View File

@@ -0,0 +1,7 @@
interface UpdateConsumptionEntry {
dateTime: string;
distance: number;
amount: number;
ignoreInCalculation: boolean;
carId: string;
}

View File

@@ -7,6 +7,7 @@ import { includeBearerTokenInterceptor } from 'keycloak-angular';
import { providePrimeNG } from 'primeng/config';
import { routes } from './app.routes';
import { provideKeycloakAngular } from './auth/auth.config';
import {API_BASE_PATH} from './api/api-base-path';
export const appConfig: ApplicationConfig = {
providers: [
@@ -21,5 +22,9 @@ export const appConfig: ApplicationConfig = {
},
ripple: true
}),
{
provide: API_BASE_PATH,
useValue: '/api'
}
]
};