This is a Spring Boot-based receipt processor application. It processes receipt data, calculates reward points, and exposes REST API endpoints. The application has been dockerized for easy deployment.
- Process Receipt: Accepts a receipt JSON and processes it.
- Points Calculation: Calculates the reward points based on the total of the receipt.
- Error Handling: Returns appropriate error messages for invalid receipts or failed requests.
receipt-processor/
├── src/
│ ├── main/
│ │ ├── java/
│ │ │ ├── com/
│ │ │ │ ├── receiptprocessor/
│ │ │ │ │ ├── controller/
│ │ │ │ │ ├── model/
│ │ │ │ │ ├── service/
│ │ │ │ │ ├── model/response/
│ ├── test/
├── pom.xml
├── Dockerfile
└── receipt.json (Sample Request JSON)- Maven
- Java 17 or higher
OR
(if you do not have Maven or Java installed in your system)
- Docker (to containerize and test the application)
docker build -t receipt-processor .docker run -p 8080:8080 receipt-processormvn clean installmvn spring-boot:runBy following these steps, either using docker or maven, it will start the application, and you can access the API at http://localhost:8080
- This endpoint processes the receipt.
{
"retailer": "Store Name",
"purchaseDate": "2024-12-15",
"purchaseTime": "14:30",
"total": "125.00",
"items": [
{
"shortDescription": "Item 1",
"price": "45.00"
},
{
"shortDescription": "Item 2",
"price": "80.00"
}
]
}{
"id": "12345-abcdef"
}- 200 OK: Receipt processed successfully.
- 400 Bad Request: Invalid receipt data.
- 500 Internal Server Error: Server error or unexpected failure.
- This endpoint fetches the reward points associated with a given receipt ID
GET /receipts/12345-abcdef/points{
"points": 15
}- 200 OK: Points retrieved successfully.
- 404 Not Found: Receipt ID not found.
Using curl: (make sure you are in your project root directory and modify receipt.json for desired input)
curl -X POST http://localhost:8080/receipts/process \
-H "Content-Type: application/json" \
-d @receipt.json- Set the request type to POST.
- Enter the URL http://localhost:8080/receipts/process.
- Under Body, select raw and JSON.
- Paste your JSON data and hit Send.
- Set the request type to GET.
- Enter the URL http://localhost:8080/receipts/{id}/process. (use the id generated in previous step)
- Hit Send.