Files
PyroFetes-Sujet1/PyroFetes/Endpoints/Effect/CreateEffectEndpoint.cs
2025-10-09 17:17:42 +02:00

34 lines
850 B
C#

using API.DTO.Effect.Request;
using API.DTO.Effect.Response;
using FastEndpoints;
namespace PyroFetes.Endpoints.Effect;
public class CreateEffectEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<CreateEffectDto, GetEffectDto>
{
public override void Configure()
{
Post("/effect/create");
AllowAnonymous();
}
public override async Task HandleAsync(CreateEffectDto req, CancellationToken ct)
{
Models.Effect effect = new()
{
Label = req.Label,
};
pyrofetesdbcontext.Effects.Add(effect);
await pyrofetesdbcontext.SaveChangesAsync(ct);
Console.WriteLine("Effect added");
GetEffectDto responseDto = new()
{
Id = effect.Id,
Label = req.Label,
};
await Send.OkAsync(responseDto, ct);
}
}