This project implements a web service that processes receipts and calculates reward points based on specific rules. The API is built in Go using the Gin framework and can be run via Docker.
- URL:
/receipts/process - Method:
POST - Payload: JSON receipt object
- Response: JSON object containing a generated receipt ID
Example Payload:
{
"retailer": "M&M Corner Market",
"purchaseDate": "2022-03-20",
"purchaseTime": "14:33",
"items": [
{
"shortDescription": "Gatorade",
"price": "2.25"
}
],
"total": "9.00"
}Example Response:
{
"id": "f535e91e-692f-4669-a773-9b9dbade78fe"
}- URL:
/receipts/{id}/points - Method:
GET - Response: JSON object containing the calculated points
Example Response:
{
"points": 109
}The service calculates points for a receipt based on these rules:
- Retailer Name: One point for every alphanumeric character.
- Total Amount (Round Dollar): 50 points if the total has no cents.
- Total Amount (Multiple of 0.25): 25 points if the total is a multiple of 0.25.
- Items Count: 5 points for every two items.
- Item Description: For each item whose trimmed description length is a multiple of 3, multiply the price by 0.2 and round up to the nearest integer.
- Purchase Date: 6 points if the day in the purchase date is odd.
- Purchase Time: 10 points if the purchase time is after 2:00 PM and before 4:00 PM.
- Docker installed on your system
-
Clone this repository and navigate into the project folder (
fetchProject):git clone <repository-url> cd fetchProject
-
Build the Docker image:
docker build -t receipt-processor .
Run the container by mapping port 8080 of the container to port 8080 on your host:
docker run -p 8080:8080 receipt-processorThe API is now accessible at http://localhost:8080.
Send a POST request to process a receipt:
curl -XPOST -H "Content-Type: application/json" -d '{
"retailer": "M&M Corner Market",
"purchaseDate": "2022-03-20",
"purchaseTime": "14:33",
"items": [
{
"shortDescription": "Gatorade",
"price": "2.25"
}
],
"total": "9.00"
}' http://localhost:8080/receipts/processThis returns a JSON response with an id.
Use the receipt ID from the previous response to query the points:
curl http://localhost:8080/receipts/<id>/pointsReplace <id> with the actual receipt ID.