Ajout de Login et du model réuni avec tout les autres Sujet

This commit is contained in:
2025-10-16 16:30:17 +02:00
parent b3347fe163
commit 2112605cf3
20 changed files with 340 additions and 36 deletions

View File

@@ -1,9 +1,7 @@
using PyroFetes.DTO.Product.Request;
using PyroFetes.DTO.Product.Response;
using PyroFetes.DTO.Product.Response;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Product.Request;
using PyroFetes.DTO.Product.Response;
using PyroFetes.Models;
namespace PyroFetes.Endpoints.Product;
@@ -23,20 +21,22 @@ public class GetAllProductsEndpoint(PyroFetesDbContext db)
var products = await db.Products
.Include(p => p.Prices)
.Include(p => p.WarehouseProducts)
.ThenInclude(wp => wp.Warehouse)
.ThenInclude(wp => wp.Warehouse)
.ToListAsync(ct);
var responseDto = products.Select(p => new GetProductDto
{
Id = p.Id,
Reference = p.References,
// Le modèle Product contient "Reference" (string) — pas "References" (int)
Reference = int.TryParse(p.Reference, out var refInt) ? refInt : 0,
Name = p.Name,
Duration = p.Duration,
Caliber = p.Caliber,
ApprovalNumber = p.ApprovalNumber,
Weight = p.Weight,
Nec = p.Nec,
SellingPrice = p.SellingPrice,
// Le prix de vente nest pas dans Product, on le récupère via Prices
SellingPrice = p.Prices.FirstOrDefault()?.SellingPrice ?? 0,
Image = p.Image,
Link = p.Link,
ClassificationId = p.ClassificationId,
@@ -49,7 +49,7 @@ public class GetAllProductsEndpoint(PyroFetesDbContext db)
SellingPrice = pr.SellingPrice
}).ToList(),
// Liste des entrepôts via WarehouseProduct
// Liste des entrepôts liés via WarehouseProduct
Warehouses = p.WarehouseProducts.Select(wp => new GetProductWarehouseDto
{
WarehouseId = wp.WarehouseId,
@@ -60,4 +60,4 @@ public class GetAllProductsEndpoint(PyroFetesDbContext db)
await Send.OkAsync(responseDto, ct);
}
}
}