using FastEndpoints; using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.Product.Response; namespace PyroFetes.Endpoints.Product; public class GetAllProductsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : EndpointWithoutRequest> { public override void Configure() { Get("/api/products"); AllowAnonymous(); } public override async Task HandleAsync(CancellationToken ct) { List 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); } }