using BookHive.DTO.Book;
using BookHive.Repositories;
using FastEndpoints;

namespace BookHive.Endpoints.Books;

public class GetBooksEndpoint(BookRepository bookRepository) : EndpointWithoutRequest<List<GetBookDto>>
{
    public override void Configure()
    {
        Get("/books/");
        AllowAnonymous();
    }

    public override async Task HandleAsync(CancellationToken ct)
    {
        await Send.OkAsync(await bookRepository.ProjectToListAsync<GetBookDto>(ct), ct);
    }
}