This Spring Boot application integrates with a third-party currency exchange API to retrieve real-time exchange rates. It calculates the total payable amount for a bill in a specified currency after applying applicable discounts. The project demonstrates object-oriented design, authentication, testing, and modern coding practices.
- Real-time currency conversion using third-party APIs.
- Discounts based on user type and tenure.
- Supports flat discounts on bills over $100.
- Authentication for secure endpoints.
- Java 23 with Spring Boot. 3.4.3
- Maven.
- JUnit5 and Mockito for testing.
- SonarQube for code quality.
- External Currency Exchange API (e.g., ExchangeRate-API or Open Exchange Rates).
classDiagram
direction BT
class AffiliateDiscount {
+ checkEligibility(UserDto, Item) boolean
}
class CustomerDiscount {
+ checkEligibility(UserDto, Item) boolean
}
class Discount {
+ checkEligibility(UserDto, Item) boolean
}
class DiscountCalculateService {
+ calculate(ShoppingCartEntity) InvoiceDto
+ applyDiscount(Item, UserDto) void
}
class DiscountCalculateServiceImpl {
+ calculate(ShoppingCartEntity) InvoiceDto
+ applyDiscount(Item, UserDto) void
}
class EmployeeDiscount {
+ checkEligibility(UserDto, Item) boolean
}
class FlatDiscount {
}
class FlatFiveForHundredBillDiscount {
+ checkEligibility(UserDto, Item) boolean
}
class PercentageDiscount {
}
<<Interface>> DiscountCalculateService
AffiliateDiscount --> PercentageDiscount
CustomerDiscount --> PercentageDiscount
DiscountCalculateServiceImpl ..> DiscountCalculateService
EmployeeDiscount --> PercentageDiscount
FlatDiscount --> Discount
FlatFiveForHundredBillDiscount --> FlatDiscount
PercentageDiscount --> Discount
class Discount:::Peach
class DiscountCalculateService:::Ash
class FlatDiscount:::Sky
class PercentageDiscount:::Sky
- Clone the Repository:
git clone https://github.com/sachith89/CurrencyDiscountCalculator.git
cd CurrencyDiscountCalculator- Configure API Key:
- Add your API key in
application.properties:
- Add your API key in
currency.api.url=https://open.er-api.com/v6/latest/
currency.api.key=your-api-key- Build and Run:
./mvnw clean install
./mvnw spring-boot:run- Access the API:
- Base URL:
http://localhost:8080
- Base URL:
Endpoint: POST /api/calculate
Request Body:
{
"items": [
{"name": "item1", "category": "grocery", "price": 50},
{"name": "item2", "category": "electronics", "price": 150}
],
"userType": "employee",
"customerTenure": 3,
"originalCurrency": "USD",
"targetCurrency": "EUR"
}Response:
{
"payableAmount": 120.50,
"currency": "EUR"
}- Run Unit Tests:
./mvnw test- Generate Coverage Reports:
./mvnw jacoco:report- Run SonarQube:
./mvnw sonar:sonar- Run build and tests with:
./mvnw clean install- Generate reports and analyze code quality:
./mvnw verify- Only one percentage-based discount applies per bill.
- Percentage-based discounts do not apply to groceries.
- A $5 flat discount applies per $100 on the bill.