Skip to content

Account Concurrency#53

Open
Jase35 wants to merge 1 commit into
abhi9720:mainfrom
Jase35:account-concurrency
Open

Account Concurrency#53
Jase35 wants to merge 1 commit into
abhi9720:mainfrom
Jase35:account-concurrency

Conversation

@Jase35

@Jase35 Jase35 commented May 7, 2026

Copy link
Copy Markdown

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:

  • entity/Currency.java — JPA entity with id, ISO-4217 code (unique, length 3), name, and display symbol.
  • repository/CurrencyRepository.java — JpaRepository<Currency, Long> with findByCode(String).
  • config/CurrencySeeder.java — CommandLineRunner that:
    • Idempotently seeds USD, EUR, GBP, INR, JPY, AUD, CAD on every startup.
    • Back-fills any pre-existing Account rows whose currency_id IS NULL with the configured default currency, so legacy databases migrate cleanly.

Modified

  • entity/Account.java — adds @manytoone Currency currency via a currency_id join column (nullable for safe migration; the service layer always sets it on new accounts).
  • dto/AccountResponse.java — exposes currencyCode and currencySymbol so the UI/API consumers can render balances correctly.
  • service/AccountService.java — adds an overload createAccount(User, String currencyCode) for callers that want to pick a non-default currency.
  • service/AccountServiceImpl.java:
    • Injects CurrencyRepository and reads app.default-currency.
    • createAccount(User) now delegates to the new overload using the configured default.
    • resolveCurrency(...) looks up by code (case-insensitive), falling back to the default and finally throwing NotFoundException if neither exists.
    • fundTransfer(...) now rejects cross-currency transfers with a clear FundTransferException (FX conversion is intentionally deferred — see Follow-ups).
  • resources/application.properties.sample — documents the new app.default-currency=INR property and lists the seeded codes.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Currency persistence (entity + repository) and startup seeding/back-fill via CurrencySeeder.
  • Extends Account / AccountResponse / AccountService to support assigning and exposing account currency (including a createAccount(User, currencyCode) overload and a configurable default currency).
  • Updates fundTransfer to 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);
});
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.

2 participants