Git Product home page Git Product logo

food-delivery-api's Introduction

Food Delivery API

Live API URL

Setup Locally

Follow the below process to setup locally:

  1. Run npm i to install all the required packages.
  2. Create .env file and initialize DATABASE_URL and declare its value.
  DATABASE_URL= Your PostreSQL database (Get a free one either from Supabase, Render, Vercel, etc.)
  1. Run these following commands in the terminal
  • npx prisma generate This auto-generates database client into the node_modules/.prisma/client folder. (Optional)
  • npx prisma db push This executes the changes required to make our database schema reflect the state of our Prisma schema.
  • npx prisma db seed This adds our custom row datas into the Organization, Item and Pricing tables.
  1. Now since everything is setup, we can finally run npm run dev command in terminal to start the development server locally.

Usage

Send POST request on the https://localhost:5000/api/calculate-price route with JSON content:

  • perishable food item
    {
      "zone": "central",
      "organization_id": "005",
      "total_distance": 12,
      "item_type": "perishable"
    }
    
    to get the response with status code 200
    {
      "success": true,
      "total_price": 20.5
    }
    
  • non-perishable food item
    {
      "zone": "north",
      "organization_id": "004",
      "total_distance": 4,
      "item_type": "non-perishable"
    }
    
    to get the response with status code 200
    {
      "success": true,
      "total_price": 10
    }
    

API Testing

Created price.test.js inside test directory. Run npm test in terminal to check if the test passed or not. List of total 10 test cases:

  1. Return an error for missing required fields;
  2. Return an error for incorrect zone;
  3. Return an error for invalid organization_id;
  4. Return an error for incorrect total_distance;
  5. Return an error for invalid item_type;
  6. Calculate total_price for perishable items within base distance;
  7. Calculate total_price for non-perishable items within base distance;
  8. Calculate total_price for perishable items beyond base distance;
  9. Calculate total_price for non-perishable items beyond base distance.
  10. Return an error for no pricing found for given parameters
{
  "zone": "central",
  "organization_id": "005",
  "total_distance": 12,
  "item_type": "non-perishable" // should have been "perishable"
}

Database Tables

  1. Organization
id name
001 Amul
002 Parle
003 Kissan
004 Emami
005 Patanjali
  1. Item
id type description
1 perishable Butter
2 non_perishable Biscuit
3 perishable Fruit Jam
4 non_perishable Cooking Oil
5 perishable Ghee
  1. Pricing
id organizationId itemId zone
6 001 1 north
7 002 2 east
8 003 3 west
9 004 4 north
10 005 5 central

Explanation

Database schema design View here

Calculate price controller View here

food-delivery-api's People

Contributors

shubham-lal 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.