using FastEndpoints;
using Knots.DTO.User;
using Microsoft.EntityFrameworkCore;

namespace Knots.Endpoints.User;

public class GetAllUsersEndpoint(KnotsDbContext knotsDbContext) : EndpointWithoutRequest<List<GetUserDto>>
{
    public override void Configure()
    { 
        Get ("/users");
        AllowAnonymous();
    }

    public override async Task HandleAsync(CancellationToken ct)
    {
        List<GetUserDto> users= await knotsDbContext.Users.Select(x => new GetUserDto()
        {
            Username = x.Username,
        }).ToListAsync(ct);
        
        await Send.OkAsync(users, ct);
    }
}