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

34 lines
795 B
C#

using PyroFetes.DTO.Brand.Request;
using PyroFetes.DTO.Brand.Response;
using FastEndpoints;
namespace PyroFetes.Endpoints.Brand;
public class UpdateBrandEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<UpdateBrandDto, GetBrandDto>
{
public override void Configure()
{
Post("/api/brands");
AllowAnonymous();
}
public override async Task HandleAsync(UpdateBrandDto req, CancellationToken ct)
{
Models.Brand brand = new()
{
Name = req.Name
};
pyrofetesdbcontext.Add(brand);
await pyrofetesdbcontext.SaveChangesAsync(ct);
GetBrandDto response = new()
{
Id = req.Id,
Name = req.Name
};
await Send.OkAsync(response, ct);
}
}