From 81ab26f76550b8f4e8eae4b7a869e1364a440797 Mon Sep 17 00:00:00 2001 From: kieva Date: Wed, 8 Oct 2025 16:44:35 +0200 Subject: [PATCH] Ajouter PyroFetes/Endpoints/Material/GetMaterialEndpoint --- .../Endpoints/Material/GetMaterialEndpoint | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 PyroFetes/Endpoints/Material/GetMaterialEndpoint diff --git a/PyroFetes/Endpoints/Material/GetMaterialEndpoint b/PyroFetes/Endpoints/Material/GetMaterialEndpoint new file mode 100644 index 0000000..0f05f23 --- /dev/null +++ b/PyroFetes/Endpoints/Material/GetMaterialEndpoint @@ -0,0 +1,43 @@ +using API.DTO.Material.Response; +using FastEndpoints; +using Microsoft.AspNetCore.Authentication; +using Microsoft.EntityFrameworkCore; + +namespace API.Endpoints.Material; + +public class GetMaterialRequest +{ + public int Id { get; set; } +} + +public class GetMaterialEndpoint(AppDbContext appDbContext) : Endpoint +{ + public override void Configure() + { + Get("/material/{@id}", x => new { x.Id }); + AllowAnonymous(); + } + + public override async Task HandleAsync(GetMaterialRequest req, CancellationToken ct) + { + Models.Material? material = await appDbContext + .Materials + .SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct); + + if (material == null) + { + Console.WriteLine("Aucun matériel avec l'ID {req.Id} trouvé."); + await Send.NotFoundAsync(ct); + return; + } + + GetMaterialDto responseDto = new() + { + Id = material.Id, + Name = material.Name, + WarehouseId = material.WarehouseId, + }; + await Send.OkAsync(responseDto, ct); + + } +} \ No newline at end of file