using BlogPlatform.DTO.Comment.Response;
using BlogPlatform.DTO.User.Response;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;

namespace BlogPlatform.Endpoints.User;

public class GetAllUserEndpoint(BlogPlatformDbContext db) : EndpointWithoutRequest<List<GetUserDto>>
{
    public override void Configure()
    {
        Get("/api/users");
    }

    public override async Task HandleAsync(CancellationToken ct)
    {
       
        List<GetUserDto> Response = await db.Users
            .Select(user=>new GetUserDto()
            {
                Id = user.Id,
                Username = user.Username,
                Email = user.Email,
                
            })
            .ToListAsync(ct);
        
        await Send.OkAsync(Response, ct);
      
    }
}