Skip to content
rbdnvPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

12 Commits

Folders and files

Repository files navigation

Currency Parser

Console application that downloads daily exchange rates from the Bank of Russia, stores them in PostgreSQL, shows rates for a selected date, and converts amounts between currencies.

Technology stack

  • Java 21
  • Spring Boot 4
  • Spring Shell
  • PostgreSQL 17
  • Flyway
  • Maven Wrapper
  • Testcontainers

Requirements

  • Java 21
  • Docker with Docker Compose

Maven does not have to be installed because the project includes Maven Wrapper.

For VS Code, the recommended extensions are Extension Pack for Java and Docker.

Run the application

  1. Open a terminal in the project directory.

  2. Start PostgreSQL:

    docker compose up -d
  3. Check that the database is running and healthy:

    docker compose ps
  4. Start the application:

    ./mvnw spring-boot:run

    On Windows PowerShell without WSL, use:

    .\mvnw.cmd spring-boot:run

Flyway creates the required database tables automatically. When the Spring Shell prompt appears, the application is ready to accept commands.

Console commands

Download and save rates for a date:

rates import --date 2026-08-26

Show all stored rates for a date:

rates show --date 2026-08-26

Convert 100 Japanese yen to Belarusian rubles using the stored rates:

currency convert --amount 100 --from JPY --to BYN --date 2026-08-26

The conversion command requires rates for the selected date to be imported first. Currency codes are case-insensitive and must contain three letters.

Use help to list all commands and exit to stop the application.

Scheduled import

The application imports rates for the current date every day at 02:00 in the Europe/Moscow time zone. The schedule uses a six-field Spring cron expression.

The default settings are:

app.import.cron=0 0 2 * * *
app.import.zone=Europe/Moscow

If a scheduled request fails, the error is logged and existing rates remain in the database. A failed import can be repeated manually with rates import.

Configuration

The default configuration works with PostgreSQL from compose.yaml. It can be overridden with environment variables:

Environment variable Default value
DB_URL jdbc:postgresql://localhost:5432/currency_parser
DB_USER currency_parser
DB_PASSWORD currency_parser
APP_CBR_BASE_URL https://www.cbr.ru/scripts/XML_daily.asp
APP_CBR_CONNECT_TIMEOUT 5s
APP_CBR_REQUEST_TIMEOUT 10s
APP_IMPORT_CRON 0 0 2 * * *
APP_IMPORT_ZONE Europe/Moscow

Example with a different database URL:

DB_URL=jdbc:postgresql://localhost:5433/currency_parser \
DB_USER=currency_parser \
DB_PASSWORD=currency_parser \
./mvnw spring-boot:run

Do not store production database passwords in the repository.

Tests

Make sure Docker is running, then execute:

./mvnw test

Integration tests start temporary PostgreSQL containers automatically and do not use the database from compose.yaml. The CBR API is replaced with a local test server, so the tests do not depend on internet access.

Build and run the JAR

./mvnw clean package
java -jar target/currency-parser-0.0.1-SNAPSHOT.jar

PostgreSQL must be running before the JAR is started.

Stop the application

Exit Spring Shell with:

exit

Then stop PostgreSQL:

docker compose down

The postgres_data volume keeps the imported rates between restarts. To remove the database together with all stored rates, explicitly run:

docker compose down -v

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages