27 lines
819 B
C#
27 lines
819 B
C#
|
|
using Microsoft.EntityFrameworkCore;
|
|||
|
|
using Vegasco.WebApi.Persistence;
|
|||
|
|
|
|||
|
|
namespace Vegasco.WebApi.Consumptions;
|
|||
|
|
|
|||
|
|
public static class GetConsumptions
|
|||
|
|
{
|
|||
|
|
public record Response(Guid Id, DateTimeOffset DateTime, double Distance, double Amount, bool IgnoreInCalculation, Guid CarId);
|
|||
|
|
|
|||
|
|
public static RouteHandlerBuilder MapEndpoint(IEndpointRouteBuilder builder)
|
|||
|
|
{
|
|||
|
|
return builder
|
|||
|
|
.MapGet("consumptions", Endpoint)
|
|||
|
|
.WithTags("Consumptions");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private static async Task<IResult> Endpoint(
|
|||
|
|
ApplicationDbContext dbContext,
|
|||
|
|
CancellationToken cancellationToken)
|
|||
|
|
{
|
|||
|
|
var consumptions = await dbContext.Consumptions
|
|||
|
|
.Select(x => new Response(x.Id.Value, x.DateTime, x.Distance, x.Amount, x.IgnoreInCalculation, x.CarId.Value))
|
|||
|
|
.ToListAsync(cancellationToken);
|
|||
|
|
|
|||
|
|
return TypedResults.Ok(consumptions);
|
|||
|
|
}
|
|||
|
|
}
|