AJout des DTO et endpoint sur le nouveau git

This commit is contained in:
2025-10-08 15:46:36 +02:00
parent 04cb47802b
commit c729af3d32
66 changed files with 1703 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
using API.DTO.Product.Response;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Endpoints.Product;
public class GetAllProductsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : EndpointWithoutRequest<List<GetProductDto>>
{
public override void Configure()
{
Get("/api/products");
AllowAnonymous();
}
public override async Task HandleAsync(CancellationToken ct)
{
List<GetProductDto> responseDto = await pyrofetesdbcontext.Products
.Select(p => new GetProductDto()
{
Id = p.Id,
Reference = p.References,
Name = p.Name,
Duration = p.Duration,
Caliber = p.Caliber,
ApprovalNumber = p.ApprovalNumber,
Weight = p.Weight,
Nec = p.Nec,
SellingPrice = p.SellingPrice,
Image = p.Image,
Link = p.Link,
ClassificationId = p.ClassificationId,
ClassificationLabel = p.Classification!.Label,
ProductCategoryId = p.ProductCategoryId,
ProductCategoryLabel = p.ProductCategory!.Label,
}
).ToListAsync(ct);
await Send.OkAsync(responseDto, ct);
}
}