forked from sanchezvem/PyroFetes
Ajouter PyroFetes/Endpoints/Effect/GetEffectEndpoint
This commit is contained in:
42
PyroFetes/Endpoints/Effect/GetEffectEndpoint
Normal file
42
PyroFetes/Endpoints/Effect/GetEffectEndpoint
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
using API.DTO.Effect.Response;
|
||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.AspNetCore.Authentication;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace API.Endpoints.Effect;
|
||||||
|
|
||||||
|
public class GetEffectRequest
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class GetEffectEndpoint(AppDbContext appDbContext) : Endpoint<GetEffectRequest, GetEffectDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Get("/effect/{@id}", x => new { x.Id });
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(GetEffectRequest req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Models.Effect? effect = await appDbContext
|
||||||
|
.Effects
|
||||||
|
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
||||||
|
|
||||||
|
if (effect == null)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Aucun effet avec l'ID {req.Id} trouvé.");
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
GetEffectDto responseDto = new()
|
||||||
|
{
|
||||||
|
Id = effect.Id,
|
||||||
|
Label = effect.Label,
|
||||||
|
};
|
||||||
|
await Send.OkAsync(responseDto, ct);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user