34 lines
820 B
C#
34 lines
820 B
C#
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);
|
|
}
|
|
} |