Giter Site home page Giter Site logo

barrettk8090 / fetch-rewards-receipt-processor-challenge Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 14.68 MB

The Fetch Rewards Receipt Processor is a web service that provides rewards points to users who provide receipt JSON.

Python 96.86% Dockerfile 3.14%

fetch-rewards-receipt-processor-challenge's Introduction

Fetch Rewards Receipt Processor

The Fetch Rewards Receipt Processor is a web service that provides rewards points to users who provide receipt JSON. This service was developed using Python and Flask, but can also be run on any device using the included Dockerfile. Instructions for running the application can be found below.

The original task for this web service can be found at the link here

API Endpoints

There are two endpoints users can use to 1) Process their receipt and 2) Earn rewards points based on the receipt ID.

Endpoint 1: Process Receipts

  • Path: /receipts/process
  • Method: POST
  • Payload: Receipt JSON
  • Response: JSON containing an id for the receipt.

Description:

Takes in a JSON receipt (see example in the example directory) and returns a JSON object with an ID generated by your code.

The ID returned is the ID that should be passed into /receipts/{id}/points to get the number of points the receipt was awarded.

How many points should be earned are defined by the rules below.

Example Response:

{ "id": "7fb1377b-b223-49d9-a31a-5a02701dd310" }

Endpoint 2: Earn Points

  • Path: /receipts/{id}/points
  • Method: GET
  • Response: A JSON object containing the number of points awarded.

A simple Getter endpoint that looks up the receipt by the ID and returns an object specifying the points awarded.

Example Response:

{ "points": 32 }

Running the Application

Using Docker

Clone the repository and ensure that you have Docker installed on your computer.

To run the application in Docker:

  1. Navigate to the project directory and open a terminal window.
  2. Run the folloiwing command and allow the build to finish before proceeding:

docker build -t fetch-rewards .

  1. To start the container, run:

docker run -p 8000:8000 fetch-rewards

  1. The Flask app should now be running at

http://localhost:8000

  1. Now that the app is running, follow the instructions in the below section, "Testing Endpoints".

Testing Endpoints

Once the application is up and running, I recommend using a service like Postman to test the endpoints with valid receipt JSON.

You can follow the instructions below, or watch the video for an overview:

Receipt Testing Video

First, make a POST request to the http://localhost:8000/receipts/process endpoint by pasting in your valid receipt JSON in the body. Once you click send, you should receive an ID (uuid), which is required for the rewards endpoint. Copy the ID to your clipboard.

Next, switch to a GET request for the http://localhost:8000/receipts/{id}/points endpoint. In place of {id}, paste in the ID that you copied from the previous step and hit send.

You should receive a response with the number of points earned for that receipt.

Receipt Reward Requirements and Points Structure

Receipt Requirements: Receipts must be in JSON format, and adhere to the schema defined in the YAML file here. To simplify this project, JSON receipts that don't adhere to this schema will not be accepted, and will result in an error.

These rules collectively define how many points should be awarded to a receipt.

  • One point for every alphanumeric character in the retailer name.
  • 50 points if the total is a round dollar amount with no cents.
  • 25 points if the total is a multiple of 0.25.
  • 5 points for every two items on the receipt.
  • If the trimmed length of the item description is a multiple of 3, multiply the price by 0.2 and round up to the nearest integer. The result is the number of points earned.
  • 6 points if the day in the purchase date is odd.
  • 10 points if the time of purchase is after 2:00pm and before 4:00pm.

Examples

{
  "retailer": "Target",
  "purchaseDate": "2022-01-01",
  "purchaseTime": "13:01",
  "items": [
    {
      "shortDescription": "Mountain Dew 12PK",
      "price": "6.49"
    },
    {
      "shortDescription": "Emils Cheese Pizza",
      "price": "12.25"
    },
    {
      "shortDescription": "Knorr Creamy Chicken",
      "price": "1.26"
    },
    {
      "shortDescription": "Doritos Nacho Cheese",
      "price": "3.35"
    },
    {
      "shortDescription": "   Klarbrunn 12-PK 12 FL OZ  ",
      "price": "12.00"
    }
  ],
  "total": "35.35"
}
Total Points: 28
Breakdown:
     6 points - retailer name has 6 characters
    10 points - 4 items (2 pairs @ 5 points each)
     3 Points - "Emils Cheese Pizza" is 18 characters (a multiple of 3)
                item price of 12.25 * 0.2 = 2.45, rounded up is 3 points
     3 Points - "Klarbrunn 12-PK 12 FL OZ" is 24 characters (a multiple of 3)
                item price of 12.00 * 0.2 = 2.4, rounded up is 3 points
     6 points - purchase day is odd
  + ---------
  = 28 points

{
  "retailer": "M&M Corner Market",
  "purchaseDate": "2022-03-20",
  "purchaseTime": "14:33",
  "items": [
    {
      "shortDescription": "Gatorade",
      "price": "2.25"
    },
    {
      "shortDescription": "Gatorade",
      "price": "2.25"
    },
    {
      "shortDescription": "Gatorade",
      "price": "2.25"
    },
    {
      "shortDescription": "Gatorade",
      "price": "2.25"
    }
  ],
  "total": "9.00"
}
Total Points: 109
Breakdown:
    50 points - total is a round dollar amount
    25 points - total is a multiple of 0.25
    14 points - retailer name (M&M Corner Market) has 14 alphanumeric characters
                note: '&' is not alphanumeric
    10 points - 2:33pm is between 2:00pm and 4:00pm
    10 points - 4 items (2 pairs @ 5 points each)
  + ---------
  = 109 points

fetch-rewards-receipt-processor-challenge's People

Contributors

barrettk8090 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.