first commit
This commit is contained in:
21
BookHive/Endpoints/Loans/CreateLoanEndpoint.cs
Normal file
21
BookHive/Endpoints/Loans/CreateLoanEndpoint.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
19
BookHive/Endpoints/Loans/GetLoansEndpoint.cs
Normal file
19
BookHive/Endpoints/Loans/GetLoansEndpoint.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user