Deployed here: Shopify Inventory
Shopify Backend Developer Intern Challenge - Summer 2022
Inventory Tracking web app for products of a company.
Candidate: Ashish Manoj Chourasia
Additional Feature Chosen: Push a button export product data to a CSV
assets: Contains images for this readme file.
index.html: The HMTL page containing JS and CSS that is rendered at the home page.
server.js: The starting file of the server application.
db.js : Database Connection
database.sql: SQL commands to be run on the database before the start of the application
routes.js: CRUD API routes operations on the products and inventory table
exportRoutes.js: Routes for exporting the data as a CSV File
package* : Configuration/Dependency file for the node application
.env.example: Example of how should the original .env file contain
Node should be installed on the system
PostgreSQL should be installed and configured on the system.
-
Clone the repo:
git clone https://github.com/am-chourasia/shopify-backend-challenge.git
-
Start the postresql database service:
sudo service postgresql start
-
Login to the postgresql with your credentials.
-
Run the database commands in the database file to create the tables.
-
Setup your environement variables in .env file from the .env environment example given.
-
Open the terminal and start the server in the dev environment.
This will expose the API Endpoints on the host and port specified in the .env file:npm run dev
Endpoint | Method | Description |
---|---|---|
/products | GET | View all products: |
/product | POST | Add a new Product in the products table which also reflects in the inventory table: |
//product/id | PUT | Update an existing product with the given id |
/product/id | DELETE | delete a product and therefore it's inventory |
/inventory | GET | view all inventory details |
/inventory/id | GET | get a row from inventory |
/inventory/id | PUT | update an inventory |
/export/product | GET | Export the product details to a csv file |
/export/inventory | GET | Export the inventory details to a csv file |
-
GET Products:
curl --request GET 'http://localhost:5000/products'
[ { "product_id": 8, "product_sku": '159632', "product_name": "Killer", "product_description": "Shirts like no other", "product_price": 999 }, { "product_id": 9, "product_sku": '147852', "product_name": "Bummer", "product_description": "Luxury like never before", "product_price": 400 } ]
-
POST Product:
curl --location --request POST 'http://localhost:5000/product' \ --header 'Content-Type: text/plain' \ --data-raw '{ "sku" : "456123", "name" : "Laptops", "description": "Laptops for work", "price" : 70000 }'
{ "product_id": 11, "product_sku": "456123", "product_name": "Laptops", "product_description": "Laptops for work", "product_price": 70000 }
-
DELETE Product with given ID:
curl --location --request DELETE 'http://alocalhost:5000/product/11'
{ "product_id": 11, "product_sku": "456123", "product_name": "Laptops", "product_description": "Laptops for work", "product_price": 70000 }
-
GET Inventory of all the products:
curl --location --request GET 'http://localhost:5000/inventory'
[ { "inventory_id": 6, "product_id": 8, "product_sku": "159632", "incoming": 0, "available": 0, "ordered": 0, "sold": 0 }, { "inventory_id": 7, "product_id": 9, "product_sku": "147852", "incoming": 0, "available": 0, "ordered": 0, "sold": 0 } ]
-
GET Invetory of a particular Product:
curl --location --request GET 'http://localhost:5000/inventory/6'
[ { "inventory_id": 6, "product_id": 8, "product_sku": "159632", "incoming": 0, "available": 0, "ordered": 0, "sold": 0 } ]
-
PUT Update Inventory Details of a product:
curl --location --request PUT 'http://localhost:5000/inventory/6' \ --header 'Content-Type: application/json' \ --data-raw '{ "incoming": 10, "available": 50, "ordered": 18, "sold": 25 }'
{ "inventory_id": 6, "product_id": 8, "product_sku": "159632", "incoming": 10, "available": 50, "ordered": 18, "sold": 25 }
-
EXPORT Product Details:
curl --location --request GET 'http://localhost:5000/export/products'
CSV File containing the product details
-
EXPORT Inventory Details:
curl --location --request GET 'http://localhost:5000/export/inventory'
CSV File containing the Inventory Details of all Products