Advanced refactoring

This commit is contained in:
Cristiano
2025-11-20 14:04:13 +01:00
parent bd653c149c
commit 7bf0b5bfd1
16 changed files with 123 additions and 207 deletions

View File

@@ -2,10 +2,11 @@
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Product.Response;
using PyroFetes.Models;
using PyroFetes.Repositories;
namespace PyroFetes.Endpoints.Products;
public class GetAllProductsEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest<List<GetProductDto>>
public class GetAllProductsEndpoint(ProductsRepository productsRepository) : EndpointWithoutRequest<List<GetProductDto>>
{
public override void Configure()
{
@@ -15,23 +16,6 @@ public class GetAllProductsEndpoint(PyroFetesDbContext database) : EndpointWitho
public override async Task HandleAsync(CancellationToken ct)
{
List<GetProductDto> product = await database.Products
.Select(product => new GetProductDto()
{
Id = product.Id,
References = product.Reference,
Name = product.Name,
Duration = product.Duration,
Caliber = product.Caliber,
ApprovalNumber = product.ApprovalNumber,
Weight = product.Weight,
Nec = product.Nec,
Image = product.Image,
Link = product.Link,
MinimalQuantity = product.MinimalQuantity,
})
.ToListAsync(ct);
await Send.OkAsync(product, ct);
await Send.OkAsync(await productsRepository.ProjectToListAsync<GetProductDto>(ct), ct);
}
}