Repository navigation
feature: enforce configurable $5,000 daily withdrawal limit - #377
Open
devin-ai-integration[bot] wants to merge 2 commits into
Open
devin-ai-integration[bot] wants to merge 2 commits into
devin-ai-integration[bot] wants to merge 2 commits into
Conversation
Co-Authored-By: Grace Juan <grace.juan@cognition.ai>
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Comment on lines
+70
to
+72
| if (getWithdrawnToday(account).add(amount).compareTo(dailyWithdrawalLimit) > 0) { | ||
| throw new RuntimeException("Daily withdrawal limit of $" + dailyWithdrawalLimit.toPlainString() + " exceeded"); | ||
| } |
Author
There was a problem hiding this comment.
Author
There was a problem hiding this comment.
This race is real. The existing "Insufficient funds" check already has it: withdraw isn't @Transactional, and it works on an Account the controller loaded earlier, with no lock. Fixing it properly means locking the account row for the whole read-check-write, for example a @Lock(PESSIMISTIC_WRITE) lookup inside a @Transactional withdraw, and that would also change the balance and transfer paths. That's outside what this PR was asked to do, so I'm leaving it open for the requester to decide whether it goes here or in a separate PR.
…ithdrawal Co-Authored-By: Grace Juan <grace.juan@cognition.ai>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Caps each account's withdrawals at a configurable total per calendar day (default $5,000). A violation throws a
RuntimeExceptionfromAccountService.withdraw, so it reaches the dashboard through the same path as "Insufficient funds" (BankController.withdrawcatch →errormodel attribute →.errorparagraph indashboard.html). No controller or template changes.application.properties:bankapp.daily-withdrawal-limit=5000, injected through@Valueas aBigDecimal.TransactionRepository: new derived queryfindByAccountIdAndTimestampBetween(Long, LocalDateTime, LocalDateTime). The field nametimestampwas checked against theTransactionentity.type"Withdrawal"count toward the limit. Deposits and"Transfer Out to …"rows don't count. Withdrawing exactly up to the limit is allowed (the check is>, not>=).withdrawreads the clock once intonow. That value sets the "today" window (getWithdrawnOn(account, now.toLocalDate())) and also stamps the newTransaction, so a request that crosses midnight is checked and recorded against the same day. The window uses the JVM default timezone.withdrawnow rejectsnull, zero and negative amounts with"Withdrawal amount must be positive". Without this, a negative "Withdrawal" row would lower the day's total and reopen the allowance. This error reaches the dashboard by the same path as the others.Testing
AccountServiceDailyWithdrawalLimitTest(Mockito, 6 cases). It covers a withdrawal up to the limit, a cumulative overage (balance and transactions left unsaved), a single withdrawal over the limit, ignoring non-Withdrawal types, the insufficient-funds check still working, and rejection of non-positive amounts../mvnw clean test: 7 tests, 0 failures../mvnw clean compilealso passes.Sources
Wiki answers: none used. A DeepWiki query for
COG-GTM/Springboot-BankAppreturned "Repository not found" because the repo isn't indexed. Everything below comes from reading files onDevOps.application.properties, where the limit property is added: https://github.com/COG-GTM/Springboot-BankApp/blob/DevOps/src/main/resources/application.properties#L1-L11TransactionRepository, existingfindByAccountIdthat the new query follows: https://github.com/COG-GTM/Springboot-BankApp/blob/DevOps/src/main/java/com/example/bankapp/repository/TransactionRepository.java#L1-L9Transactionentity fieldsamount/type/timestamp: https://github.com/COG-GTM/Springboot-BankApp/blob/DevOps/src/main/java/com/example/bankapp/model/Transaction.java#L13-L19AccountServicerepository injection: https://github.com/COG-GTM/Springboot-BankApp/blob/DevOps/src/main/java/com/example/bankapp/service/AccountService.java#L22-L32AccountService.withdraw, with the"Insufficient funds"check and"Withdrawal"transaction type: https://github.com/COG-GTM/Springboot-BankApp/blob/DevOps/src/main/java/com/example/bankapp/service/AccountService.java#L64-L78BankController.withdraw, whereRuntimeExceptionbecomes theerrormodel attribute: https://github.com/COG-GTM/Springboot-BankApp/blob/DevOps/src/main/java/com/example/bankapp/controller/BankController.java#L58-L72dashboard.htmlerror paragraph: https://github.com/COG-GTM/Springboot-BankApp/blob/DevOps/src/main/resources/templates/dashboard.html#L191-L191Devin-Org: engineering
Link to Devin session: https://devin-gtm.devinenterprise.com/sessions/6f971cc34dc74af9ba938ccf24cdac22
Open in Devin Desktop: https://devin-gtm.devinenterprise.com/desktop/session/6f971cc34dc74af9ba938ccf24cdac22?variant=devin
Requested by: @gracejuan-star
Note
Devin errored when opening this Pull Request as gracejuan-star.
As a fallback, Devin opened this PR as itself.
Devin Review