A Spring Boot application that provides a REST API for currency conversion. This project was created to demonstrate the application of design patterns in a real-world algorithm.
The Currency Conversion API allows users to convert amounts from Brazilian Real (BRL) to other currencies like US Dollar (USD) and Euro (EUR). The application implements the Strategy Pattern to handle different conversion strategies based on the source and target currencies.
- Java 24
- Spring Boot 3.5.0
- Maven
- RESTful API
- Convert BRL to USD
- Convert BRL to EUR
- Extensible architecture for adding new currency conversions
The project follows a clean architecture with the following components:
- Controller: Handles HTTP requests and responses
- Service: Contains the business logic for currency conversion
- Strategy Resolver: Selects the appropriate conversion strategy based on input
- Converters: Implement specific conversion algorithms for different currency pairs
- DTOs: Data Transfer Objects for API input and output
- Java 24 or higher
- Maven 3.6 or higher
-
Clone the repository:
git clone https://github.com/yourusername/conversion-api.git cd conversion-api -
Build the project:
mvn clean install
-
Run the application:
mvn spring-boot:run
The application will start on http://localhost:8080.
Converts an amount from one currency to another.
Endpoint: GET /conversions
Query Parameters:
from: Source currency code (e.g., BRL)to: Target currency code (e.g., USD, EUR)amount: The amount to convert
Example Request:
GET /conversions?from=BRL&to=USD&amount=100
Example Response:
{
"conversion": 18.0505,
"formattedConversion": null,
"fromCurrencySign": null,
"toCurrencySign": null
}The application uses the following fixed exchange rates:
- 1 USD = 5.54 BRL
- 1 EUR = 6.40 BRL
To add a new currency converter:
- Create a new class that implements the
CurrencyConverterinterface - Implement the
convertmethod with the appropriate conversion logic - Add the new converter to the
ConversionStrategyResolver
Example:
@Service
public class BRLtoGBPConverter implements CurrencyConverter {
@Override
public ConversionResponse convert(BigDecimal amount) {
return new ConversionResponse(
amount.divide(new BigDecimal("7.50"), 4, RoundingMode.HALF_UP)
);
}
}This project is open source and available under the MIT License.
- Your Name - Initial work