using BookHive.DTO.Loan;
using BookHive.Repositories;
using FastEndpoints;

namespace BookHive.Endpoints.Loans;

public class GetLoansEndpoint(LoanRepository loanRepository) : EndpointWithoutRequest<List<GetLoanDto>>
{
    public override void Configure()
    {
        Get("/loans/");
        AllowAnonymous();
    }

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