Account Concurrency#53
Open
Jase35 wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds first-class multi-currency support to the BankingPortal domain model by introducing a Currency entity, wiring it into Account creation/serialization, and enforcing same-currency-only transfers (FX deferred). Also seeds a baseline set of ISO-4217 currencies and back-fills legacy accounts with a default currency on startup.
Changes:
- Introduces
Currencypersistence (entity + repository) and startup seeding/back-fill viaCurrencySeeder. - Extends
Account/AccountResponse/AccountServiceto support assigning and exposing account currency (including acreateAccount(User, currencyCode)overload and a configurable default currency). - Updates
fundTransferto reject cross-currency transfers.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| src/main/resources/application.properties.sample | Documents app.default-currency and supported seeded currency codes. |
| src/main/java/com/webapp/bankingportal/service/AccountServiceImpl.java | Resolves/assigns currency on account creation; blocks cross-currency transfers. |
| src/main/java/com/webapp/bankingportal/service/AccountService.java | Adds createAccount(User, String currencyCode) overload. |
| src/main/java/com/webapp/bankingportal/repository/CurrencyRepository.java | Adds Spring Data repository for currency lookup by code. |
| src/main/java/com/webapp/bankingportal/entity/Currency.java | Adds JPA entity for currencies (code/name/symbol). |
| src/main/java/com/webapp/bankingportal/entity/Account.java | Adds currency association (currency_id) to Account. |
| src/main/java/com/webapp/bankingportal/dto/AccountResponse.java | Exposes currencyCode and currencySymbol in API responses. |
| src/main/java/com/webapp/bankingportal/config/CurrencySeeder.java | Seeds base currencies and back-fills legacy accounts with default currency. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+64
to
+68
| String code = (currencyCode == null || currencyCode.isBlank()) | ||
| ? defaultCurrencyCode | ||
| : currencyCode.toUpperCase(); | ||
| return currencyRepository.findByCode(code) | ||
| .orElseGet(() -> currencyRepository.findByCode(defaultCurrencyCode) |
Comment on lines
+248
to
+252
| // Reject cross-currency transfers; FX conversion can be added later. | ||
| val sourceCurrency = sourceAccount.getCurrency(); | ||
| val targetCurrency = targetAccount.getCurrency(); | ||
| if (sourceCurrency != null && targetCurrency != null | ||
| && !sourceCurrency.getCode().equals(targetCurrency.getCode())) { |
Comment on lines
49
to
+53
| public Account createAccount(User user) { | ||
| return createAccount(user, defaultCurrencyCode); | ||
| } | ||
|
|
||
| @Override |
Comment on lines
+42
to
+43
| Currency defaultCurrency = currencyRepository.findByCode(defaultCurrencyCode) | ||
| .orElseGet(() -> currencyRepository.findByCode("INR").orElse(null)); |
Comment on lines
+50
to
+54
| accountRepository.findAll().stream() | ||
| .filter(account -> account.getCurrency() == null) | ||
| .forEach(account -> { | ||
| account.setCurrency(defaultCurrency); | ||
| accountRepository.save(account); |
Comment on lines
+1
to
+10
| package com.webapp.bankingportal.config; | ||
| import java.util.List; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.boot.CommandLineRunner; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import com.webapp.bankingportal.entity.Currency; | ||
| import com.webapp.bankingportal.repository.AccountRepository; | ||
| import com.webapp.bankingportal.repository.CurrencyRepository; | ||
| import lombok.extern.slf4j.Slf4j; |
Comment on lines
+1
to
+5
| package com.webapp.bankingportal.repository; | ||
| import java.util.Optional; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.stereotype.Repository; | ||
| import com.webapp.bankingportal.entity.Currency; |
Comment on lines
+34
to
+37
| # Multi-currency support: ISO 4217 code used as the default for newly | ||
| # created accounts and to back-fill existing accounts on startup. | ||
| # Supported out-of-the-box: USD, EUR, GBP, INR, JPY, AUD, CAD. | ||
| app.default-currency=INR |
Comment on lines
+35
to
+40
| for (Currency seed : DEFAULTS) { | ||
| currencyRepository.findByCode(seed.getCode()) | ||
| .orElseGet(() -> { | ||
| log.info("Seeding currency {}", seed.getCode()); | ||
| return currencyRepository.save(seed); | ||
| }); |
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:
Introduces multi-currency support to the Banking Portal so accounts can be denominated in different ISO 4217 currencies (USD, EUR, GBP, INR, JPY, AUD, CAD out of the box). This future-proofs the application for international usage and lays the groundwork for follow-up features such as FX conversion, exchange-rate tracking, and multi-currency balances.
Closes Issue: "The current account model lacks currency support…"
What's changed
New:
Modified