Spring Boot microservice to:
- store purchase transactions in USD;
- retrieve transactions by ID;
- convert transaction amounts to another currency using Treasury API rates.
- Java 25
- Spring Boot 4
- Spring Data JDBC
- H2 Database (in-memory)
- SpringDoc OpenAPI (Swagger UI)
- Gradle Wrapper
- JDK 25 installed and configured in
JAVA_HOME - Internet access to query the Treasury API (currency conversion)
- Port
8080available (or configure a different port)
./gradlew clean bootRunApplication starts at:
http://localhost:8080
./gradlew bootRun --args="--server.port=8085"./gradlew clean testFull build:
./gradlew clean buildWith the application running:
- Swagger UI: http://localhost:8080/swagger-ui/index.html
- OpenAPI JSON: http://localhost:8080/v3/api-docs
To make API validation easier, version the Postman assets inside the repository:
- Collection:
postman/collection/purchase-transaction-api.postman_collection.json - Environment template (optional):
postman/environment/local.postman_environment.template.json
How to import:
- Open Postman and click Import.
- Select the JSON file from the
postman/collectionfolder. - (Optional) Import the environment template and set
baseUrl(for example,http://localhost:8080).
Base URL: http://localhost:8080
-
POST /api/transactions
Creates a new purchase transaction. -
GET /api/transactions/{id}
Retrieves a transaction by ID. -
GET /api/transactions/{id}/convert?currency=EUR
Retrieves the transaction and converts its amount to the target currency.
For GET /api/transactions/{id}/convert:
- The exchange rate must have a
record_dateless than or equal to the purchasetransaction_date. - The exchange rate must be within the previous 6 months from the purchase date.
- If multiple rates match, the API uses the most recent valid one.
- If no valid rate exists in this 6-month window, the API returns
EXCHANGE_RATE_NOT_FOUND. - The converted amount is rounded to 2 decimal places.
The application uses explicit currency-name mapping for Treasury API filters via configuration in application.properties (wex.treasury.currency-name-mapping.*):
BRL->RealEUR->EuroJPY->YenGBP->PoundCAD->DollarAUD->DollarCHF->Franc
For other 3-letter ISO currency codes, the application attempts a fallback using Java Currency display names in English.
If the Treasury API does not support that name/code combination, conversion may return EXCHANGE_RATE_NOT_FOUND.
curl -s -X POST "http://localhost:8080/api/transactions" \
-H "Content-Type: application/json" \
-d '{
"description":"Office Supplies",
"transactionDate":"2024-08-15",
"amount":100.00
}'curl -i "http://localhost:8080/api/transactions/{id}"curl -i "http://localhost:8080/api/transactions/{id}/convert?currency=EUR"- H2 is configured in-memory (
jdbc:h2:mem), so data is lost when the application restarts. - If the conversion endpoint returns an exchange-rate error, verify Treasury API connectivity and data availability for the requested currency/date.