From feadab4dff1f57e377c23af59dffd3835fa2980b Mon Sep 17 00:00:00 2001 From: ThompsonNye Date: Thu, 19 Jun 2025 18:56:40 +0200 Subject: [PATCH] Sort entries both on the backend and frontend --- .../entries/services/entries-overview.service.ts | 10 ++++++---- src/Vegasco.Server.Api/Consumptions/GetConsumptions.cs | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Vegasco-Web/src/app/modules/entries/entries/services/entries-overview.service.ts b/src/Vegasco-Web/src/app/modules/entries/entries/services/entries-overview.service.ts index 1483dd4..d3eb91e 100644 --- a/src/Vegasco-Web/src/app/modules/entries/entries/services/entries-overview.service.ts +++ b/src/Vegasco-Web/src/app/modules/entries/entries/services/entries-overview.service.ts @@ -34,10 +34,12 @@ export class EntriesOverviewService { return combineLatest([this.cachedCars$!, entries$]) .pipe( map(([cars, entries]) => { - return entries.map((entry): Consumption => ({ - ...entry, - car: cars.find(car => car.id === entry.carId)! - })); + return entries + .sort((a, b) => b.dateTime.localeCompare(a.dateTime)) + .map((entry): Consumption => ({ + ...entry, + car: cars.find(car => car.id === entry.carId)! + })); }) ) } diff --git a/src/Vegasco.Server.Api/Consumptions/GetConsumptions.cs b/src/Vegasco.Server.Api/Consumptions/GetConsumptions.cs index 1d1c4c7..a472df0 100644 --- a/src/Vegasco.Server.Api/Consumptions/GetConsumptions.cs +++ b/src/Vegasco.Server.Api/Consumptions/GetConsumptions.cs @@ -41,6 +41,7 @@ public static class GetConsumptions CancellationToken cancellationToken) { List consumptions = await dbContext.Consumptions + .OrderByDescending(x => x.DateTime) .Select(x => new ResponseDto(x.Id.Value, x.DateTime, x.Distance, x.Amount, x.IgnoreInCalculation, x.CarId.Value)) .ToListAsync(cancellationToken);