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

35 lines
857 B
C#

using PyroFetes.DTO.Brand.Request;
using PyroFetes.DTO.Brand.Response;
using FastEndpoints;
namespace PyroFetes.Endpoints.Brand;
public class CreateBrandEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<CreateBrandDto, GetBrandDto>
{
public override void Configure()
{
Post("/api/brands");
AllowAnonymous();
}
public override async Task HandleAsync(CreateBrandDto req, CancellationToken ct)
{
Models.Brand brand = new ()
{
Name = req.Name
};
pyrofetesdbcontext.Brands.Add(brand);
await pyrofetesdbcontext.SaveChangesAsync(ct);
Console.WriteLine("Marque créé avec succès !");
GetBrandDto responseDto = new ()
{
Name = req.Name
};
await Send.OkAsync(responseDto, ct);
}
}