initalisation
This commit is contained in:
33
PyroFetes/Endpoints/Truck/GetAllTruckEndpoint.cs
Normal file
33
PyroFetes/Endpoints/Truck/GetAllTruckEndpoint.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using PF3.DTO.Truck.Response;
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PF3;
|
||||
|
||||
namespace PF3.Endpoints.Truck;
|
||||
|
||||
public class GetAllTrucksEndpoint(PF3DbContext pf3DbContext) : EndpointWithoutRequest<List<ReadTruckDto>>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/trucks");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
var trucks = await pf3DbContext.Trucks.ToListAsync(ct);
|
||||
|
||||
var result = trucks
|
||||
.Select(truck => new ReadTruckDto
|
||||
{
|
||||
Id = truck.Id,
|
||||
Type = truck.Type,
|
||||
MaxExplosiveCapacity = truck.MaxExplosiveCapacity,
|
||||
Sizes = truck.Sizes,
|
||||
Statut = truck.Statut,
|
||||
ShowId = truck.ShowId
|
||||
})
|
||||
.ToList();
|
||||
|
||||
await Send.OkAsync(result, ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user