forked from sanchezvem/PyroFetes
Ajouter PyroFetes/Endpoints/Color/GetAllColorsEndpoint
This commit is contained in:
26
PyroFetes/Endpoints/Color/GetAllColorsEndpoint
Normal file
26
PyroFetes/Endpoints/Color/GetAllColorsEndpoint
Normal file
@@ -0,0 +1,26 @@
|
||||
using API.DTO.Color.Response;
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace API.Endpoints.Color;
|
||||
|
||||
public class GetAllColorsEndpoint(AppDbContext appDbContext) : EndpointWithoutRequest<List<GetColorDto>>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/colors");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
List<GetColorDto> responseDto = await appDbContext.Colors
|
||||
.Select(a => new GetColorDto
|
||||
{
|
||||
Id = a.Id,
|
||||
Label = a.Label,
|
||||
}
|
||||
).ToListAsync(ct);
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user