MaJ des .txt en .cs

This commit is contained in:
2025-10-09 16:09:30 +02:00
parent 44da6ed371
commit c5805d979b
15 changed files with 65 additions and 70 deletions

View File

@@ -0,0 +1,42 @@
using API.DTO.Material.Request;
using API.DTO.Material.Response;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Endpoints.Material;
public class UpdateMaterialEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<UpdateMaterialDto, GetMaterialDto>
{
public override void Configure()
{
Put("/material/{@id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(UpdateMaterialDto req, CancellationToken ct)
{
Models.Material? materialToEdit = await pyrofetesdbcontext
.Materials
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
if (materialToEdit == null)
{
Console.WriteLine("Aucun matériel avec l'id {req.Id} trouvé.");
await Send.NotFoundAsync(ct);
return;
}
materialToEdit.Name = req.Label;
materialToEdit.WarehouseId = req.WarehouseId;
await pyrofetesdbcontext.SaveChangesAsync(ct);
GetMaterialDto responseDto = new()
{
Id = req.Id,
Label = req.Label,
WarehouseId = req.WarehouseId,
};
await Send.OkAsync(responseDto, ct);
}
}