using API.DTO.Supplier.Response; using FastEndpoints; using Microsoft.EntityFrameworkCore; namespace PyroFetes.Endpoints.Supplier; public class GetSupplierRequest { public int Id { get; set; } } public class GetSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint { public override void Configure() { Get("/api/suppliers/{@id}", x => new { x.Id }); AllowAnonymous(); } public override async Task HandleAsync(GetSupplierRequest req, CancellationToken ct) { Models.Supplier? supplier = await pyrofetesdbcontext .Suppliers .SingleOrDefaultAsync(s => s.Id == req.Id, cancellationToken: ct); if (supplier == null) { Console.WriteLine($"Aucun fournisseur avec l'ID {req.Id} trouvé."); await Send.NotFoundAsync(ct); return; } GetSupplierDto responseDto = new() { Id = supplier.Id, Name = supplier.Name!, Email = supplier.Email!, PhoneNumber = supplier.Phone!, Adress = supplier.Address!, ZipCode = supplier.ZipCode, City = supplier.City! }; await Send.OkAsync(responseDto, ct); } }