Files
PyroFetes-Sujet1/PyroFetes/Endpoints/Brand/GetAllBrandsEndpoint.cs
2025-11-05 22:38:55 +01:00

28 lines
1.0 KiB
C#

using API.DTO.Brand.Response;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Endpoints.Brand;
public class GetAllBrandsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : EndpointWithoutRequest<List<GetBrandDto>>
{
public override void Configure()
{
Get("/api/brands"); //Endpoint qui affiche toutes les marques
AllowAnonymous(); //Autorise l'accès sans authentification
}
public override async Task HandleAsync(CancellationToken ct)
{
List<GetBrandDto> responseDto = await pyrofetesdbcontext.Brands //Création d'une liste qui récupère toutes les marques dans la bdd
.Select(a => new GetBrandDto //Sélectionne dans la liste chaque marque
{
Id = a.Id, //Affiche l'id
Name = a.Name, //Affiche le nom
}
).ToListAsync(ct); //Retourne la liste de marque
await Send.OkAsync(responseDto, ct); //Envoie de la réponse réussite 200 au client
}
}