Files
PyroFetes-Sujet1/PyroFetes/Endpoints/Product/GetAllProductsEndpoint.cs

41 lines
1.3 KiB
C#

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