forked from sanchezvem/PyroFetes
Ajouter PyroFetes/Endpoints/Effect/CreateEffectEndpoint
This commit is contained in:
34
PyroFetes/Endpoints/Effect/CreateEffectEndpoint
Normal file
34
PyroFetes/Endpoints/Effect/CreateEffectEndpoint
Normal file
@@ -0,0 +1,34 @@
|
||||
using API.DTO.Effect.Request;
|
||||
using API.DTO.Effect.Response;
|
||||
|
||||
using FastEndpoints;
|
||||
namespace API.Endpoints.Effect;
|
||||
|
||||
public class CreateEffectEndpoint(AppDbContext appDbContext) : 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,
|
||||
};
|
||||
|
||||
appDbContext.Effects.Add(effect);
|
||||
await appDbContext.SaveChangesAsync(ct);
|
||||
Console.WriteLine("Effect added");
|
||||
|
||||
GetEffectDto responseDto = new()
|
||||
{
|
||||
Id = effect.Id,
|
||||
Label = req.Label,
|
||||
};
|
||||
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user