Skip to content

feat(ledger): add deduct_credits and get_history [REN-77] - #111

Merged
Scott Graham (cheddarfox) merged 1 commit into
devfrom
REN-77-deduct-credits-service
Mar 9, 2026
Merged

Scott Graham (cheddarfox) merged 1 commit into
devfrom
REN-77-deduct-credits-service

Conversation

@cheddarfox

Copy link
Copy Markdown
Member

Summary

  • Add deduct_credits() service function with idempotency, SELECT FOR UPDATE locking, and custom InsufficientCreditsError exception
  • Add get_history() for paginated transaction history (limit/offset, max 100)
  • 7 unit tests covering debit operations, idempotency, insufficient balance, and history queries

Test plan

  • test_deduct_credits_basic — allocate 100, deduct 30, verify balance=70
  • test_deduct_credits_idempotent — same reference_id returns existing entry
  • test_deduct_credits_insufficient — raises InsufficientCreditsError
  • test_deduct_credits_zero_or_negative — raises ValueError
  • test_get_history_default — created_at DESC ordering
  • test_get_history_pagination — limit/offset correctness
  • test_get_history_empty — returns [] for new user

🤖 Generated with Claude Code

…EN-77]

Add deduct_credits() with idempotency via reference_id, SELECT FOR UPDATE
row locking, and pre-flush InsufficientCreditsError check to prevent
negative balances. Add get_history() with limit/offset pagination and
silent clamping at max 100 entries. Includes 7 test cases covering basic
deduction, idempotency, insufficient funds, invalid amounts, ordering,
pagination, and empty results.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@cheddarfox
Scott Graham (cheddarfox) merged commit 4527795 into dev Mar 9, 2026
13 of 15 checks passed
@cheddarfox
Scott Graham (cheddarfox) deleted the REN-77-deduct-credits-service branch March 9, 2026 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant