This service is mainly responsible for managing transfers between 'Accounts'.
-
To add a new table, alter an existing one or any other db operation please add a 'migration' file in
src/main/resources/db.migration -
The current DB configuration is using MYSQL db and the configuration properties are found in
src/main/resources/application.propertiesyou can use H2 in memory db by commenting theMySql Configurationpart and commentingH2 Configurationpart.- Note: the current H2 configuration persists the DB on file.
see:
spring.datasource.url=jdbc:h2:file:./data/fund_transfer_service
- Note: the current H2 configuration persists the DB on file.
see:
-
freecurrencyapi is used to retrieve current conversion rates. The api is free and is updated daily. For the API to work some configuration properties must be provided.
clients.freeCurrencyApi.base-urlRepresenting the base URL for the apiclients.freeCurrencyApi.api-keyRepresenting the api key that is used for authentication by the API
Caching is configured to cache the API response and the cache is cleared at midnight. this is done to save network overhead and to make sure the the free api quota is not met.
- caching config:
src/main/java/com/example/fundTransferService/external/client/FreeCurrencyApiClient.java@Cacheable(value = "getLatestRates")- caching clearing:
src/main/java/com/example/fundTransferService/external/client/FreeCurrencyApiClient.javaclearGetLatestRatesCache()
-
A variation of Strategy design pattern is used in the service for:
- A) Defining business rules in
src/main/java/com/example/fundTransferService/business/strategy/rule/FundsTransferRule.java- Implementations of that interface should provide new business rules that should be met
- This was it is much easier to maintain funds transfer rule, easier to add new rules and the code of funds transfer is decoupled from checking constraint
- B) Defining currency exchange strategies:
src/main/java/com/example/fundTransferService/business/strategy/exchange/ExchangeStrategy.java- Implementations of that interface should provide new strategies for transferring funds; for example, the system now doesn't have a strategy for transferring funds outside EU, a business case that could have different implementation like adding extra fees
- Again, this way it is much easier to maintain and extend currency conversion strategies
- A) Defining business rules in
-
Multiple business exceptions were defined in
src/main/java/com/example/fundTransferService/exceptionto have more control over exception handling in our system. Thrown exceptions are handled insrc/main/java/com/example/fundTransferService/exception/ExceptionHandler.javawhich uses Spring's@ControllerAdvice. This way when an exception is caught it is processed and a descriptive error response is returned by the API -
There a use of "Factory":
src/main/java/com/example/fundTransferService/factoryand "Mappers" (mapstruct):src/main/java/com/example/fundTransferService/business/mapper: -- The philosophy here is to use factories when there is some logic in creating new instances like generating IBAN or TransactionId, and for simple mapping between objects mappers are used -
Swagger is used to document rest APIs. check: http://localhost:8080/swagger-ui/index.html#
Unit and Integrations tests were added for different components in the system. but note that, some functionalities were left out of testing on purpose to save time. the reason is that those
components, like adding account holders or creating accounts are kind of out of scope of the task and only serve a complementary purpose.