Compare commits

...

2 Commits

Author SHA1 Message Date
edafe0e4ec Fix API return type mismatch
All checks were successful
continuous-integration/drone/push Build is passing
2025-06-15 11:30:03 +02:00
a1174e3b42 Expose swagger UI again 2025-06-15 11:29:46 +02:00
5 changed files with 41 additions and 24 deletions

View File

@@ -0,0 +1,3 @@
interface GetConsumptionEntriesResponse {
consumptions: ConsumptionEntry[];
}

View File

@@ -1,22 +1,22 @@
@if (consumptionEntries$ | async; as consumptionEntries) {
<div>
<table>
<thead>
<tr>
<th>Datum</th>
<th>Distanz</th>
<th>Menge</th>
</tr>
</thead>
<tbody>
@for (entry of consumptionEntries; track entry.id) {
<tr>
<td>{{ entry.dateTime | date }}</td>
<td>{{ entry.distance }} km</td>
<td>{{ entry.amount }} l</td>
</tr>
}
</tbody>
</table>
</div>
}
<div>
<table>
<thead>
<tr>
<th>Datum</th>
<th>Distanz</th>
<th>Menge</th>
</tr>
</thead>
<tbody>
@for (entry of consumptionEntries; track entry.id) {
<tr>
<td>{{ entry.dateTime | date }}</td>
<td>{{ entry.distance }} km</td>
<td>{{ entry.amount }} l</td>
</tr>
}
</tbody>
</table>
</div>
}

View File

@@ -2,7 +2,7 @@ import { AsyncPipe, DatePipe } from '@angular/common';
import { HttpClient } from '@angular/common/http';
import { Component, inject } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { Observable, tap } from 'rxjs';
import { map, Observable, tap } from 'rxjs';
@Component({
selector: 'app-entries',
@@ -16,12 +16,13 @@ export class EntriesComponent {
protected readonly consumptionEntries$: Observable<ConsumptionEntry[]>;
constructor() {
this.consumptionEntries$ = this.http.get<ConsumptionEntry[]>('/api/v1/consumptions')
this.consumptionEntries$ = this.http.get<GetConsumptionEntriesResponse>('/api/v1/consumptions')
.pipe(
takeUntilDestroyed(),
tap((response) => {
console.log('Entries response:', response);
}),
map(response => response.consumptions)
);
}
}

View File

@@ -1,4 +1,5 @@
using Vegasco.Server.Api.Endpoints;
using Asp.Versioning.ApiExplorer;
using Vegasco.Server.Api.Endpoints;
using Vegasco.Server.ServiceDefaults;
namespace Vegasco.Server.Api.Common;
@@ -36,6 +37,17 @@ internal static class StartupExtensions
if (app.Environment.IsDevelopment())
{
app.MapOpenApi("/swagger/{documentName}/swagger.json");
app.UseSwaggerUI(o =>
{
// Create a Swagger endpoint for each API version
IReadOnlyList<ApiVersionDescription> apiVersions = app.DescribeApiVersions();
foreach (ApiVersionDescription apiVersionDescription in apiVersions)
{
string url = $"/swagger/{apiVersionDescription.GroupName}/swagger.json";
string name = apiVersionDescription.GroupName.ToUpperInvariant();
o.SwaggerEndpoint(url, name);
}
});
}
return app;

View File

@@ -31,6 +31,7 @@
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.12.0" />
<PackageReference Include="StronglyTypedId" Version="1.0.0-beta08" PrivateAssets="all" ExcludeAssets="runtime" />
<PackageReference Include="StronglyTypedId.Templates" Version="1.0.0-beta08" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.1" />
</ItemGroup>
<ItemGroup>