17:17 09/10

This commit is contained in:
2025-10-09 17:17:42 +02:00
parent 1734ec0219
commit 91b4aca2fa
76 changed files with 815 additions and 388 deletions

View File

@@ -1,35 +1,34 @@
using PyroFetes.DTO.Material.Request;
using PyroFetes.DTO.Material.Response;
using API.DTO.Material.Request;
using API.DTO.Material.Response;
using FastEndpoints;
using Microsoft.AspNetCore.Server.Kestrel;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Endpoints.Material;
public class UpdateMaterialEndpoint(PyroFetesDbContext appDbContext) : Endpoint<UpdateMaterialDto, GetMaterialDto>
public class UpdateMaterialEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<UpdateMaterialDto, GetMaterialDto>
{
public override void Configure()
{
Put("/api/material/{@id}", x => new { x.Id });
Put("/material/{@id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(UpdateMaterialDto req, CancellationToken ct)
{
Models.Material? materialToEdit = await appDbContext
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é.");
Console.WriteLine("Aucun matériel avec l'id {req.Id} trouvé.");
await Send.NotFoundAsync(ct);
return;
}
materialToEdit.Label = req.Label;
materialToEdit.Name = req.Label;
materialToEdit.WarehouseId = req.WarehouseId;
await appDbContext.SaveChangesAsync(ct);
await pyrofetesdbcontext.SaveChangesAsync(ct);
GetMaterialDto responseDto = new()
{