Feat/idr rate aggregator#210
Open
Haidir-prj wants to merge 6 commits into
Open
Conversation
…bClient configuration
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.
Ringkasan
PR ini berisi implementasi REST API untuk mengagregasi data nilai tukar IDR dari Frankfurter API sesuai dengan requirement.
Data yang disediakan mencakup:
Seluruh data diambil satu kali saat aplikasi start dan disimpan di memory, sehingga endpoint tidak melakukan request ulang ke API eksternal.
Fitur yang Diimplementasikan
Endpoint:
GET /api/finance/data/{resourceType}Resource yang didukung:
latest_idr_rateshistorical_idr_usdsupported_currenciesPenambahan field:
USD_BuySpread_IDR(khusus latest rate)Pendekatan Arsitektur
Strategy Pattern
Digunakan untuk memisahkan logic pengambilan data berdasarkan resource.
Setiap resource memiliki implementasi sendiri dari interface
IDRDataFetcher, sehingga tidak perlu menggunakan if/else di controller.Pendekatan ini memudahkan jika ingin menambahkan resource baru ke depannya.
FactoryBean untuk WebClient
WebClient dibuat menggunakan FactoryBean agar konfigurasi seperti base URL dan timeout terpusat.
Dengan cara ini, pembuatan client tidak tersebar di berbagai class dan lebih mudah dikelola.
ApplicationRunner
Digunakan untuk load data dari external API saat aplikasi start.
Alasan penggunaan:
Response Design
Response dibuat konsisten menggunakan wrapper:
[ { "resourceType": "latest_idr_rates", "data": { ... } } ]Pendekatan ini memudahkan parsing di sisi client dan menjaga konsistensi antar endpoint.
Error Handling & Timeout
Contoh response saat error:
{ "error": "Failed to fetch data", "message": "TimeoutException" }Testing
Unit test mencakup:
WebClient dimock agar test tidak bergantung ke API eksternal.
Cara Menjalankan
Contoh Penggunaan
Personalisasi Spread
GitHub Username: haidir
Spread dihitung menggunakan:
(sum ASCII username % 1000) / 100000.0
Catatan
Penutup
Implementasi ini dibuat dengan fokus pada clean architecture, maintainability, dan testability.