https://github.com/sachith89/currencydiscountcalculator
A demo project
https://github.com/sachith89/currencydiscountcalculator
checkstyle docker docker-compose jacoco kubernetes linting sonarqube springboot webflux
Last synced: 4 months ago
JSON representation
A demo project
- Host: GitHub
- URL: https://github.com/sachith89/currencydiscountcalculator
- Owner: sachith89
- Created: 2025-03-11T07:29:53.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-22T06:02:12.000Z (about 1 year ago)
- Last Synced: 2025-10-10T19:32:49.946Z (8 months ago)
- Topics: checkstyle, docker, docker-compose, jacoco, kubernetes, linting, sonarqube, springboot, webflux
- Language: Java
- Homepage: http://sachith.dev
- Size: 62.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://github.com/sachith89/CurrencyDiscountCalculator/actions/workflows/maven.yml)
# ๐ฑ Currency Exchange and Discount Calculation API
## ๐ Project Description
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.
---
## ๐ฆ Features
- 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.
---
## ๐๏ธ Tech Stack
- 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).
---
```mermaid
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 {
}
<> 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
```
---
## โ๏ธ Setup Instructions
1. **Clone the Repository:**
```bash
git clone https://github.com/sachith89/CurrencyDiscountCalculator.git
cd CurrencyDiscountCalculator
```
2. **Configure API Key:**
- Add your API key in `application.properties`:
```properties
currency.api.url=https://open.er-api.com/v6/latest/
currency.api.key=your-api-key
```
3. **Build and Run:**
```bash
./mvnw clean install
./mvnw spring-boot:run
```
4. **Access the API:**
- Base URL: `http://localhost:8080`
---
## ๐ค API Endpoints
### ๐งพ Calculate Payable Amount
**Endpoint:** `POST /api/calculate`
**Request Body:**
```json
{
"items": [
{"name": "item1", "category": "grocery", "price": 50},
{"name": "item2", "category": "electronics", "price": 150}
],
"userType": "employee",
"customerTenure": 3,
"originalCurrency": "USD",
"targetCurrency": "EUR"
}
```
**Response:**
```json
{
"payableAmount": 120.50,
"currency": "EUR"
}
```
---
## ๐งช Testing
1. **Run Unit Tests:**
```bash
./mvnw test
```
2. **Generate Coverage Reports:**
```bash
./mvnw jacoco:report
```
---
## ๐ Code Quality
1. **Run SonarQube:**
```bash
./mvnw sonar:sonar
```
---
## โ๏ธ Build Automation
- Run build and tests with:
```bash
./mvnw clean install
```
- Generate reports and analyze code quality:
```bash
./mvnw verify
```
---
## ๐ Assumptions
- 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.