21 lines
567 B
C#
21 lines
567 B
C#
using BookHive.DTO.Loan;
|
|
using BookHive.Models;
|
|
using BookHive.Repositories;
|
|
using FastEndpoints;
|
|
|
|
namespace BookHive.Endpoints.Loans;
|
|
|
|
public class CreateLoanEndpoint(LoanRepository loanRepository, AutoMapper.IMapper mapper) : Endpoint<CreateLoanDto>
|
|
{
|
|
public override void Configure()
|
|
{
|
|
Post("/loans/");
|
|
AllowAnonymous();
|
|
}
|
|
|
|
public override async Task HandleAsync(CreateLoanDto req, CancellationToken ct)
|
|
{
|
|
await loanRepository.AddAsync(mapper.Map<Loan>(req), ct);
|
|
await Send.OkAsync(cancellation: ct);
|
|
}
|
|
} |