forked from sanchezvem/PyroFetes
Ajouter PyroFetes/Endpoints/Color/CreateColorEndpoint
This commit is contained in:
35
PyroFetes/Endpoints/Color/CreateColorEndpoint
Normal file
35
PyroFetes/Endpoints/Color/CreateColorEndpoint
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
using API.DTO.Color.Request;
|
||||||
|
using API.DTO.Color.Response;
|
||||||
|
using FastEndpoints;
|
||||||
|
|
||||||
|
namespace API.Endpoints.Color;
|
||||||
|
|
||||||
|
public class CreateColorEndpoint(AppDbContext appDbContext) : Endpoint<CreateColorDto, GetColorDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Post("/color/create");
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(CreateColorDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Models.Color color = new()
|
||||||
|
{
|
||||||
|
Label = req.Label,
|
||||||
|
};
|
||||||
|
|
||||||
|
appDbContext.Colors.Add(color);
|
||||||
|
await appDbContext.SaveChangesAsync(ct);
|
||||||
|
Console.WriteLine("Added Color");
|
||||||
|
|
||||||
|
GetColorDto responseDto = new()
|
||||||
|
{
|
||||||
|
Id = color.Id,
|
||||||
|
Label = req.Label,
|
||||||
|
};
|
||||||
|
|
||||||
|
await Send.OkAsync(responseDto, ct);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user