forked from sanchezvem/PyroFetes
46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
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<List<GetWarehouseDto>>
|
|
{
|
|
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);
|
|
}
|
|
} |