forked from sanchezvem/PyroFetes
MAJ Mathilde
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
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 pyrofetesdbcontext) : EndpointWithoutRequest<List<GetWarehouseDto>>
|
||||
public class GetAllWarehouseEndpoint(PyroFetesDbContext db)
|
||||
: EndpointWithoutRequest<List<GetWarehouseDto>>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
@@ -14,20 +17,30 @@ public class GetAllWarehouseEndpoint(PyroFetesDbContext pyrofetesdbcontext) : En
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
List<GetWarehouseDto> responseDto = await pyrofetesdbcontext.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
|
||||
})
|
||||
// 🔹 On inclut les relations avec WarehouseProducts et Product
|
||||
var warehouses = await db.Warehouses
|
||||
.Include(w => w.WarehouseProducts)
|
||||
.ThenInclude(wp => wp.Product)
|
||||
.ToListAsync(ct);
|
||||
|
||||
await Send.OkAsync(responseDto, 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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user