Ensure correct sorting and thus also correct liter per 100km calculation
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-06-24 20:35:49 +02:00
parent 4b377ce9f4
commit b41d5c5d33
2 changed files with 6 additions and 4 deletions

View File

@@ -73,7 +73,7 @@ export class EntriesComponent implements OnInit {
const entries = this.consumptionClient.getAll() const entries = this.consumptionClient.getAll()
.pipe( .pipe(
takeUntilDestroyed(), takeUntilDestroyed(),
map(response => response.consumptions), map(response => response.consumptions.sort((a, b) => b.dateTime.localeCompare(a.dateTime))),
catchError((error) => this.handleGetEntriesError(error)) catchError((error) => this.handleGetEntriesError(error))
); );

View File

@@ -52,10 +52,9 @@ public static class GetConsumptions
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
Dictionary<CarId, List<Consumption>> consumptionsByCar = await dbContext.Consumptions Dictionary<CarId, List<Consumption>> consumptionsByCar = await dbContext.Consumptions
.OrderByDescending(x => x.DateTime)
.Include(x => x.Car) .Include(x => x.Car)
.GroupBy(x => x.CarId) .GroupBy(x => x.CarId)
.ToDictionaryAsync(x => x.Key, x => x.ToList(), cancellationToken); .ToDictionaryAsync(x => x.Key, x => x.OrderByDescending(x => x.DateTime).ToList(), cancellationToken);
List<ResponseDto> responses = []; List<ResponseDto> responses = [];
@@ -85,7 +84,10 @@ public static class GetConsumptions
} }
} }
ApiResponse apiResponse = new() { Consumptions = responses }; ApiResponse apiResponse = new()
{
Consumptions = responses
};
return TypedResults.Ok(apiResponse); return TypedResults.Ok(apiResponse);
} }
} }