Files
pyrofetes-backend/PyroFetes/Endpoints/Users/GetUserEndpoint.cs
T
2026-05-28 15:39:55 +01:00

30 lines
834 B
C#

using FastEndpoints;
using PyroFetes.DTO.User.Response;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.Users;
namespace PyroFetes.Endpoints.Users;
public class GetUserEndpoint(UsersRepository usersRepository, AutoMapper.IMapper mapper) : EndpointWithoutRequest<GetUserDto>
{
public override void Configure()
{
Get("/user/");
Roles("Admin","Employe");
}
public override async Task HandleAsync(CancellationToken ct)
{
int userId = int.Parse(User.FindFirst("Id")!.Value);
User? user = await usersRepository.SingleOrDefaultAsync(new GetUserByIdSpec(userId), ct);
if (user is null)
{
await Send.NotFoundAsync(ct);
return;
}
await Send.OkAsync(mapper.Map<GetUserDto>(user), ct);
}
}