MAJ Mathilde

This commit is contained in:
2025-10-09 15:16:08 +02:00
parent f155d03559
commit d1fa3aca68
24 changed files with 628 additions and 211 deletions

View File

@@ -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);
}
}