using FastEndpoints; using PF3.DTO.Truck.Request; using PF3.DTO.Truck.Response; namespace PF3.Endpoints.Truck; public class CreateTruckEndpoint(PF3DbContext pf3DbContext):Endpoint { public override void Configure() { Post("/api/truck"); AllowAnonymous(); } public override async Task HandleAsync(CreateTruckDto req, CancellationToken ct) { var truck = new Models.Truck { Type = req.Type, MaxExplosiveCapacity = req.MaxExplosiveCapacity, Sizes = req.Sizes, Statut = req.Statut }; pf3DbContext.Trucks.Add(truck); await pf3DbContext.SaveChangesAsync(ct); var result = new ReadTruckDto() { Id = truck.Id, Type = truck.Type, MaxExplosiveCapacity = truck.MaxExplosiveCapacity, Sizes = truck.Sizes, Statut = truck.Statut }; await Send.OkAsync(result, ct); } }