Endopoint presque fini

This commit is contained in:
2025-10-16 17:00:36 +02:00
parent 8d0c2aa3f6
commit ec5149b6da
28 changed files with 551 additions and 31 deletions

View File

@@ -0,0 +1,40 @@
using FastEndpoints;
using PF3.DTO.Truck.Request;
using PF3.DTO.Truck.Response;
namespace PF3.Endpoints.Truck;
public class CreateTruckEndpoint(PF3DbContext pf3DbContext):Endpoint<CreateTruckDto, ReadTruckDto>
{
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);
}
}