Skip to content

ashish-kd/fetchProject

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Receipt Processor API

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.

Endpoints

Process Receipt

  • 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"
}

Get Points

  • URL: /receipts/{id}/points
  • Method: GET
  • Response: JSON object containing the calculated points

Example Response:

{
  "points": 109
}

Reward Points Calculation Rules

The service calculates points for a receipt based on these rules:

  1. Retailer Name: One point for every alphanumeric character.
  2. Total Amount (Round Dollar): 50 points if the total has no cents.
  3. Total Amount (Multiple of 0.25): 25 points if the total is a multiple of 0.25.
  4. Items Count: 5 points for every two items.
  5. 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.
  6. Purchase Date: 6 points if the day in the purchase date is odd.
  7. Purchase Time: 10 points if the purchase time is after 2:00 PM and before 4:00 PM.

Running the API Using Docker

Prerequisites

  • Docker installed on your system

Build the Docker Image

  1. Clone this repository and navigate into the project folder (fetchProject):

    git clone <repository-url>
    cd fetchProject
  2. Build the Docker image:

    docker build -t receipt-processor .

Run the Docker Container

Run the container by mapping port 8080 of the container to port 8080 on your host:

docker run -p 8080:8080 receipt-processor

The API is now accessible at http://localhost:8080.

Testing the API

Process a Receipt

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/process

This returns a JSON response with an id.

Get Receipt Points

Use the receipt ID from the previous response to query the points:

curl http://localhost:8080/receipts/<id>/points

Replace <id> with the actual receipt ID.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published