using PyroFetes.DTO.Supplier.Response; using PyroFetes.DTO.Supplier.Request; using FastEndpoints; using Microsoft.EntityFrameworkCore; using PyroFetes.Models; namespace PyroFetes.Endpoints.Supplier; public class GetAllSuppliersEndpoint(PyroFetesDbContext pyrofetesdbcontext) : EndpointWithoutRequest> { public override void Configure() { Get("/api/suppliers"); AllowAnonymous(); } public override async Task HandleAsync(CancellationToken ct) { var suppliers = await pyrofetesdbcontext.Suppliers .Include(s => s.Prices) .ToListAsync(ct); var responseDto = suppliers.Select(s => new GetSupplierDto { Id = s.Id, Name = s.Name!, Email = s.Email!, PhoneNumber = s.Phone!, Adress = s.Address!, ZipCode = s.ZipCode, City = s.City!, // 🔹 Liste des produits liés via Price Products = s.Prices.Select(pr => new SupplierProductPriceDto { ProductId = pr.ProductId, SellingPrice = pr.SellingPrice }).ToList() }).ToList(); await Send.OkAsync(responseDto, ct); } }