MaJ des .txt en .cs

This commit is contained in:
2025-10-09 16:09:30 +02:00
parent 44da6ed371
commit c5805d979b
15 changed files with 65 additions and 70 deletions

View File

@@ -0,0 +1,41 @@
using API.DTO.Effect.Request;
using API.DTO.Effect.Response;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Endpoints.Effect;
public class UpdateEffectEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<UpdateEffectDto, GetEffectDto>
{
public override void Configure()
{
Put("/effect/{@id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(UpdateEffectDto req, CancellationToken ct)
{
Models.Effect? effectToEdit = await pyrofetesdbcontext
.Effects
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
if (effectToEdit == null)
{
Console.WriteLine("Aucun effet avec l'id {req.Id} trouvé.");
await Send.NotFoundAsync(ct);
return;
}
effectToEdit.Label = req.Label;
await pyrofetesdbcontext.SaveChangesAsync(ct);
GetEffectDto responseDto = new()
{
Id = req.Id,
Label = req.Label,
};
await Send.OkAsync(responseDto, ct);
}
}