forked from sanchezvem/PyroFetes
MAJ Mathilde
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
using API.DTO.Supplier.Response;
|
||||
using API.DTO.Supplier.Request;
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.Models;
|
||||
|
||||
namespace PyroFetes.Endpoints.Supplier;
|
||||
|
||||
public class GetAllSuppliersEndpoint(PyroFetesDbContext pyrofetesdbcontext) : EndpointWithoutRequest<List<GetSupplierDto>>
|
||||
public class GetAllSuppliersEndpoint(PyroFetesDbContext pyrofetesdbcontext)
|
||||
: EndpointWithoutRequest<List<GetSupplierDto>>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
@@ -14,19 +17,28 @@ public class GetAllSuppliersEndpoint(PyroFetesDbContext pyrofetesdbcontext) : En
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
List<GetSupplierDto> responseDto = await pyrofetesdbcontext.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!
|
||||
})
|
||||
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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user