created all endpoints

This commit is contained in:
2026-03-09 22:31:49 +01:00
parent 22014f6878
commit 679c552a3f
5 changed files with 177 additions and 2 deletions

View File

@@ -0,0 +1,35 @@
using BookHive.Models;
using BookHive.Repositories;
using BookHive.Specifications.Loans;
using FastEndpoints;
namespace BookHive.Endpoints.Loans;
public class PatchReturnLoanRequest
{
public int Id { get; set; }
public DateOnly ReturnDate { get; set; }
}
public class PatchReturnLoanEndpoint(LoanRepository loanRepository) : Endpoint<PatchReturnLoanRequest>
{
public override void Configure()
{
Patch("/loans/{@Id}/return/", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(PatchReturnLoanRequest req, CancellationToken ct)
{
Loan? loan = await loanRepository.SingleOrDefaultAsync(new GetLoanByIdSpec(req.Id), ct);
if (loan is null)
{
await Send.NotFoundAsync(ct);
await Send.OkAsync(cancellation: ct);
}
loan?.ReturnDate = req.ReturnDate;
await loanRepository.SaveChangesAsync(ct);
await Send.OkAsync(cancellation: ct);
}
}