forked from sanchezvem/PyroFetes
AJout des DTO et endpoint sur le nouveau git
This commit is contained in:
40
PyroFetes/Endpoints/Product/GetAllProductsEndpoint.cs
Normal file
40
PyroFetes/Endpoints/Product/GetAllProductsEndpoint.cs
Normal 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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user