feat: implement IDR rate aggregator with strategy pattern and startup preloading#217
Open
joniheri wants to merge 6 commits into
Open
feat: implement IDR rate aggregator with strategy pattern and startup preloading#217joniheri wants to merge 6 commits into
joniheri wants to merge 6 commits into
Conversation
… immutable store
- add Strategy-based fetchers for latest rates, historical USD/IDR, and supported currencies
- preload external finance data once at startup via ApplicationRunner
- store data in thread-safe immutable in-memory store
- expose /api/finance/data/{resourceType} endpoint with global exception handling
- add RestTemplate FactoryBean config, OpenAPI setup, unit tests, and Postman collection
- refine strategy fetchers and service/controller data path - improve preload runner and immutable in-memory store behavior - update README and add/adjust unit + integration tests for runner/strategies
…e url in factory bean
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
This PR implements a Spring Boot REST API that aggregates Indonesian Rupiah (IDR) exchange data from the Frankfurter API.
The application exposes a single polymorphic endpoint and preloads all required data at startup into an in-memory store. It ensures no external API calls are made during request handling.
Key Features
Single endpoint:
/api/finance/data/{resourceType}Supports:
latest_idr_rateshistorical_idr_usdsupported_currenciesCustom spread calculation for
latest_idr_ratesThread-safe and immutable in-memory data store
No external API calls during runtime requests
Architectural Rationale
1. Strategy Pattern
The Strategy Pattern is used to handle multiple resource types without relying on conditional branching such as
if-elseorswitch.Each resource type is encapsulated in its own strategy class (
LatestIdrRatesFetcher,HistoricalIdrUsdFetcher,SupportedCurrenciesFetcher). This design improves extensibility, maintainability, and testability. New resource types can be added without modifying existing logic.2. Client FactoryBean
A custom
FactoryBeanis used to construct the HTTP client (RestTemplate). This ensures that all client configuration (such as base URL and timeouts) is centralized and externalized viaapplication.yml.This approach avoids tight coupling between business logic and infrastructure concerns, and aligns with Spring’s inversion of control principles.
3. ApplicationRunner
ApplicationRunneris used to preload all required data during application startup.This ensures:
Compared to alternatives like
@PostConstruct,ApplicationRunnerprovides better control over application lifecycle and initialization timing.Personalization
joniheri0.00856The
latest_idr_ratesresponse includes a custom calculated field:How to Test