hoangsonww / hoangsonww/Library-Management-Backend

Add a loan renewal endpoint

Open
#5 0 comments 0 reactions 1 assignee Claimed by @hoangsonww View on GitHub
bug documentation enhancement good first issue help wanted
Dominant language
Go
Stars
1
Forks
0
PR merge metrics
No merged PRs in 30d

Description

## What problem does this solve?

A loan currently has one due date set at borrow time (`loanPeriodDays`), with no way to extend it. In practice borrowers want to renew a loan (extend the due date) instead of returning and immediately re-borrowing the same copy — which today would briefly free the copy for someone else and is a clunky two-call workaround anyway.

## Proposed solution

- Add `POST /api/v1/loans/{id}/renew` (JWT-gated) that extends `dueDate` by another `loanPeriodDays` (or an explicit override), inside a transaction, and rejects (`409`) if the loan is already returned or if a hold exists on the book (see the holds-queue feature) — renewals shouldn't skip a waiting line.
- Track a `renewalCount` on the loan and support an optional `MAX_RENEWALS` config cap (returning `409` once exceeded).
- Add a `loans renew ` CLI subcommand alongside the existing `loans borrow`/`loans return`.

## Alternatives considered

Return + immediately re-borrow via the existing two endpoints — already possible, but it's not atomic (another borrower could grab the copy in between) and doesn't preserve loan history as a single continuous loan.

## Area

Loans (borrow / return)

## Priority

Would significantly improve on the current borrow/return-only model — renewal is one of the most common actions in any real lending system.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.