Files
PyroFetes-Sujet1/PyroFetes/Endpoints/Login/GetLoginEndpoint.cs
2025-12-08 12:27:05 +01:00

40 lines
964 B
C#

using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Login.Response;
namespace PyroFetes.Endpoints.Login;
public class GetLoginRequest
{
public int Id { get; set; }
}
public class GetLoginEndpoint(PyroFetesDbContext database) : Endpoint<GetLoginRequest, GetLoginDto>
{
public override void Configure()
{
Get("/logins/{@Id}", x => new {x.Id});
AllowAnonymous();
}
public override async Task HandleAsync(GetLoginRequest req, CancellationToken ct)
{
Models.User? login = await database.Users
.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
if (login == null)
{
await Send.NotFoundAsync(ct);
return;
}
GetLoginDto responseDto = new()
{
Id = login.Id,
Name = login.Name,
Fonction = login.Fonction
};
await Send.OkAsync(responseDto, ct);
}
}