Finalisation endpoints

This commit is contained in:
2025-11-13 15:11:34 +01:00
parent 5c12a45ae6
commit 3a09bfc8ad
20 changed files with 922 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
using FastEndpoints;
using PyroFetes.DTO.Truck.Request;
using PyroFetes.DTO.Truck.Response;
namespace PyroFetes.Endpoints.Truck;
public class CreateTruckEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint<CreateTruckDto, ReadTruckDto>
{
public override void Configure()
{
Post("/api/trucks");
AllowAnonymous();
}
public override async Task HandleAsync(CreateTruckDto req, CancellationToken ct)
{
var truck = new PyroFetes.Models.Truck
{
Type = req.Type ?? string.Empty,
MaxExplosiveCapacity = req.MaxExplosiveCapacity,
Sizes = req.Sizes,
Status = req.Status
};
pyroFetesDbContext.Trucks.Add(truck);
await pyroFetesDbContext.SaveChangesAsync(ct);
// Ajouter la relation ShowTruck si ShowId est fourni
if (req.ShowId.HasValue && req.ShowId.Value != 0)
{
var showTruck = new PyroFetes.Models.ShowTruck
{
TruckId = truck.Id,
ShowId = req.ShowId.Value
};
pyroFetesDbContext.ShowTrucks.Add(showTruck);
await pyroFetesDbContext.SaveChangesAsync(ct);
}
var result = new ReadTruckDto
{
Id = truck.Id,
Type = truck.Type,
MaxExplosiveCapacity = truck.MaxExplosiveCapacity,
Sizes = truck.Sizes,
Statut = truck.Status,
ShowId = req.ShowId
};
await Send.OkAsync(result, ct);
}
}