Rename WebApi project to Vegasco.Server.Api
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
And update all references including comments etc.
This commit is contained in:
53
src/Vegasco.Server.Api/Consumptions/GetConsumptions.cs
Normal file
53
src/Vegasco.Server.Api/Consumptions/GetConsumptions.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Vegasco.Server.Api.Persistence;
|
||||
|
||||
namespace Vegasco.Server.Api.Consumptions;
|
||||
|
||||
public static class GetConsumptions
|
||||
{
|
||||
public class ApiResponse
|
||||
{
|
||||
public IEnumerable<ResponseDto> Consumptions { get; set; } = [];
|
||||
}
|
||||
|
||||
public record ResponseDto(
|
||||
Guid Id,
|
||||
DateTimeOffset DateTime,
|
||||
double Distance,
|
||||
double Amount,
|
||||
bool IgnoreInCalculation,
|
||||
Guid CarId);
|
||||
|
||||
public class Request
|
||||
{
|
||||
[FromQuery(Name = "page")] public int? Page { get; set; }
|
||||
[FromQuery(Name = "pageSize")] public int? PageSize { get; set; }
|
||||
}
|
||||
|
||||
public static RouteHandlerBuilder MapEndpoint(IEndpointRouteBuilder builder)
|
||||
{
|
||||
return builder
|
||||
.MapGet("consumptions", Endpoint)
|
||||
.WithDescription("Returns all consumption entries")
|
||||
.WithTags("Consumptions");
|
||||
}
|
||||
|
||||
private static async Task<Ok<ApiResponse>> Endpoint(
|
||||
[AsParameters] Request request,
|
||||
ApplicationDbContext dbContext,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
List<ResponseDto> consumptions = await dbContext.Consumptions
|
||||
.Select(x =>
|
||||
new ResponseDto(x.Id.Value, x.DateTime, x.Distance, x.Amount, x.IgnoreInCalculation, x.CarId.Value))
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
var apiResponse = new ApiResponse
|
||||
{
|
||||
Consumptions = consumptions
|
||||
};
|
||||
return TypedResults.Ok(apiResponse);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user