using API.DTO.Warehouse.Response; using API.DTO.Warehouse.Request; using FastEndpoints; using Microsoft.EntityFrameworkCore; using PyroFetes.Models; namespace PyroFetes.Endpoints.Warehouse; public class GetAllWarehouseEndpoint(PyroFetesDbContext db) : EndpointWithoutRequest> { public override void Configure() { Get("/api/warehouses"); AllowAnonymous(); } public override async Task HandleAsync(CancellationToken ct) { // 🔹 On inclut les relations avec WarehouseProducts et Product var warehouses = await db.Warehouses .Include(w => w.WarehouseProducts) .ThenInclude(wp => wp.Product) .ToListAsync(ct); var response = warehouses.Select(w => new GetWarehouseDto { Id = w.Id, Name = w.Name, MaxWeight = w.MaxWeight, Current = w.Current, MinWeight = w.MinWeight, Adress = w.Address, ZipCode = w.ZipCode, City = w.City, Products = w.WarehouseProducts.Select(wp => new WarehouseProductDto { ProductId = wp.ProductId, ProductName = wp.Product?.Name, Quantity = wp.Quantity }).ToList() }).ToList(); await Send.OkAsync(response, ct); } }