/foreignexchangeexample

Case Study - Openpayd Foreign Exchange Example (Spring Boot, Java 21, Docker, Maven, JUnit Test, Integration Test, In-Memory Database (H2 Database), Github Actions, Spring Open Api, Mapstruct, Spring Cache, Resillience4j (Rate Limiter))

Primary LanguageJava

Case Study - Foreign Exchange Example

Main Information

📖 Information

  • This project demonstrates a Spring Boot application for managing foreign exchange operations. It allows users to convert currencies, retrieve current exchange rates, and view conversion history.
  • The application integrates with an external service provider for fetching exchange rates and performing currency conversion calculations.
  • The application includes three main endpoints:
    • Exchange Rate Endpoint: Fetches the current exchange rate between two currencies.
    • Currency Conversion Endpoint: Converts a given amount from one currency to another and returns a unique transaction identifier.
    • Conversion History Endpoint: Retrieves the history of currency conversions based on transaction identifiers or dates.

Explore Rest APIs

Endpoints Summary

Method Url Description Request Body Path Variable Response
POST /api/v1/exchange-rate Fetches the current exchange rate between two currencies. ExchangeRateRequest None ExchangeRateResponse
POST /api/v1/convert Converts currency based on the provided ConvertRequest. ConvertRequest None ConvertResponse
POST /api/v1/history Retrieves the conversion history based on the provided ConversionHistoryFilterRequest. ConversionHistoryFilterRequest None CustomPage<ConvertHistoryResponse>

Technologies


  • Java 21
  • Spring Boot 3.0
  • Restful API
  • Mapstruct
  • Open Api (Swagger)
  • Maven
  • Junit5
  • Mockito
  • Integration Tests
  • Docker
  • Docker Compose
  • CI/CD (Github Actions)
  • Postman
  • H2 Database (In-Memory)
  • Spring Boot Actuator
  • Spring Cache
  • Resilience4j (Rate Limiter)

Postman

Import postman collection under postman_collection folder

Prerequisites

Define Variable in .env file for http://api.currencylayer.com/

EXCHANGE_API_API_KEY={EXCHANGE_API_API_KEY}

Open Api (Swagger)

http://localhost:1331/swagger-ui/index.html

  • Maven or Docker

Docker Run

The application can be built and run by the Docker engine. The Dockerfile has multistage build, so you do not need to build and run separately.

Please follow directions shown below in order to build and run the application with Docker Compose file;

$ cd foreignexchangeexample
$ docker-compose up -d

If you change anything in the project and run it on Docker, you can also use this command shown below

$ cd foreignexchangeexample
$ docker-compose up --build

Maven Run

To build and run the application with Maven, please follow the directions shown below;

$ cd foreignexchangeexample
$ mvn clean install
$ mvn spring-boot:run

Docker Image Location

https://hub.docker.com/repository/docker/noyandocker/foreignexchangeexample/general

Screenshots

Click here to show the screenshots of project

Figure 1

Figure 2

Figure 3

Figure 4

Figure 5

Figure 6

Figure 7

Figure 8

Contributors