forked from sanchezvem/PyroFetes
28 lines
1.1 KiB
C#
28 lines
1.1 KiB
C#
using API.DTO.Classification.Response;
|
|
using FastEndpoints;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace PyroFetes.Endpoints.Classification;
|
|
|
|
public class GetAllClassificationsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : EndpointWithoutRequest<List<GetClassificationDto>>
|
|
{
|
|
public override void Configure()
|
|
{
|
|
Get("/api/classifications"); //Endpoint qui affiche toutes les classifications
|
|
AllowAnonymous(); //Autorise l'accès sans authentification
|
|
}
|
|
|
|
public override async Task HandleAsync(CancellationToken ct)
|
|
{
|
|
|
|
List<GetClassificationDto> responseDto = await pyrofetesdbcontext.Classifications //Création d'une liste qui récupère toutes les classifications dans la bdd
|
|
.Select(a => new GetClassificationDto //Sélectionne dans la liste chaque classification
|
|
{
|
|
Id = a.Id, //Récupère l'id
|
|
Label = a.Label, //Récupère le label
|
|
}
|
|
).ToListAsync(ct); //Retourne la liste de classification
|
|
|
|
await Send.OkAsync(responseDto, ct); //Envoie de la réponse réussite 200 au client
|
|
}
|
|
} |