Files
PyroFetes-Sujet1/PyroFetes/Endpoints/Material/GetAllMaterialsEndpoint.cs
2025-10-09 16:55:29 +02:00

28 lines
830 B
C#

using PyroFetes.DTO.Material.Response;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Endpoints.Material;
public class GetAllMaterialsEndpoint(PyroFetesDbContext appDbContext) : EndpointWithoutRequest<List<GetMaterialDto>>
{
public override void Configure()
{
Get("/api/material");
AllowAnonymous();
}
public override async Task HandleAsync(CancellationToken ct)
{
List<GetMaterialDto> responseDto = await appDbContext.Materials
.Select(a => new GetMaterialDto
{
Id = a.Id,
Label = a.Label,
Quantity = a.Quantity,
WarehouseId = a.WarehouseId,
}
).ToListAsync(ct);
await Send.OkAsync(responseDto, ct);
}
}