17:17 09/10

This commit is contained in:
2025-10-09 17:17:42 +02:00
parent 1734ec0219
commit 91b4aca2fa
76 changed files with 815 additions and 388 deletions

View File

@@ -1,4 +1,5 @@
using API.DTO.Supplier.Response;
using PyroFetes.DTO.Supplier.Request;
using PyroFetes.DTO.Supplier.Response;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
@@ -9,7 +10,8 @@ public class GetSupplierRequest
public int Id { get; set; }
}
public class GetSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<GetSupplierRequest, GetSupplierDto>
public class GetSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext)
: Endpoint<GetSupplierRequest, GetSupplierDto>
{
public override void Configure()
{
@@ -19,9 +21,9 @@ public class GetSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoi
public override async Task HandleAsync(GetSupplierRequest req, CancellationToken ct)
{
Models.Supplier? supplier = await pyrofetesdbcontext
.Suppliers
.SingleOrDefaultAsync(s => s.Id == req.Id, cancellationToken: ct);
var supplier = await pyrofetesdbcontext.Suppliers
.Include(s => s.Prices)
.SingleOrDefaultAsync(s => s.Id == req.Id, ct);
if (supplier == null)
{
@@ -30,7 +32,7 @@ public class GetSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoi
return;
}
GetSupplierDto responseDto = new()
var responseDto = new GetSupplierDto
{
Id = supplier.Id,
Name = supplier.Name!,
@@ -38,7 +40,14 @@ public class GetSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoi
PhoneNumber = supplier.Phone!,
Adress = supplier.Address!,
ZipCode = supplier.ZipCode,
City = supplier.City!
City = supplier.City!,
// Produits liés
Products = supplier.Prices.Select(p => new SupplierProductPriceDto
{
ProductId = p.ProductId,
SellingPrice = p.SellingPrice
}).ToList()
};
await Send.OkAsync(responseDto, ct);