forked from sanchezvem/PyroFetes
34 lines
1.0 KiB
C#
34 lines
1.0 KiB
C#
using API.DTO.Brand.Response;
|
|
using FastEndpoints;
|
|
using PyroFetes.DTO.Brand.Request;
|
|
|
|
namespace PyroFetes.Endpoints.Brand;
|
|
|
|
public class UpdateBrandEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<UpdateBrandDto, GetBrandDto>
|
|
{
|
|
public override void Configure()
|
|
{
|
|
Put("/api/brands/{Id}"); //Met à jour la marque en fonction de l'id
|
|
AllowAnonymous(); //Autorise l'accès sans authentification
|
|
}
|
|
|
|
public override async Task HandleAsync(UpdateBrandDto req, CancellationToken ct)
|
|
{
|
|
|
|
Models.Brand brand = new() //Met à jour la marque
|
|
{
|
|
Name = req.Name
|
|
};
|
|
pyrofetesdbcontext.Add(brand); //ajoute la marque dans la bdd
|
|
await pyrofetesdbcontext.SaveChangesAsync(ct); //Sauvegarde les changements
|
|
|
|
GetBrandDto response = new() //renvoie l'id et le nom
|
|
{
|
|
Id = req.Id,
|
|
Name = req.Name
|
|
};
|
|
|
|
await Send.OkAsync(response, ct); //Envoie de la réponse réussite 200 au client
|
|
|
|
}
|
|
} |