Skip to content

subramanyam23/product-catalog-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Product Catalog API - Golang

This is a product catalog API which has a list of products that can be added to the cart. This works similar to how normal e-com website works, but in the form of API.

Dependencies

Install Postgresql

sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get -y install postgresql

Install the following packages using go get

go get github.com/gorilla/mux
go get github.com/google/uuid
go get github.com/lib/pq

Environment Setup

Start the Postgresql server

sudo service postgresql start

Connect to the psql server

sudo -u postgres psql

Create a database user for the application

createuser service-pc-api

Create a database for the API

createdb -O service-pc-api product-catalog -h localhost -U service-pc-api

Initialize the Database schema

psql -h localhost -U service-pc-api -f sql_commands/init.sql

Environment Variables

To run this project, you will need to add the following environment variables to your .env file

CONNECTION_STRING - Postgres connection string/url

Database Design

alt text

API Reference

Product

Get Products

Sends the list of all products in an array

GET /products

Query Parameters

Field Type Description
page int Optional. Default Value: 1
items_per_page int Optional. Default Value: 20
Get Product

Sends a single product referenced by id

GET /product/${id}
Add Product

Adds a product to the database

POST /product

Request Body

Field Type Description
product_id int Required. ID of the product.
name int Required. The name of the product.
specification JSON Required. The Specifications of the product.
sku string Required. The product's category ID (FK).
category_id int Required. The name of the product.
price float Required. The product's price
Delete Product

Deletes a product from the database referenced by the id

DELETE /product/${id}
Update a Product

Updates a product in the database referenced by id

PUT /product/${id}

Request Body

Field Type Description
product_id int Optional. ID of the product.
name int Optional. The name of the product.
specification JSON Optional. The Specifications of the product.
sku string Optional. The product's category ID (FK).
category_id int Optional. The name of the product.
price float Optional. The product's price

Note: product_id cannot be updated.

Category

Add Category

Adds a new category to the database

POST /category

Request Body

Field Type Description
category_id int Required. Unique ID for the Category.
name string Required. The name of the category.
Get Categories

Get an array of all Categories

GET /categories
Delete Category

Deletes a category from the database referenced by id

DELETE /category/${id}
Update Category

Update the category field referenced by id

PUT /category/${id}

Inventory

Get Inventory

View the current stock in inventory

GET /inventory
Update Inventory Item

Add/Update the inventory.

POST /inventory

Request Body: JSON

Field Type Description
product_id int Required. Product ID to update/update in inventory.
quantity int Required. The quantity to update/update

Cart

Add Item to Cart

Add new item or increase existing quantity.

POST /additemtocart

Query Parameters:

Field Type Description
ref string Optional. Cart Reference ID. New cart is created if not passed.

Request Body:

Field Type Description
product_id int Required. Product ID
quantity int Required. Quantity of the product to add
Add items to cart

Add new items or increase existing quantity.

POST /additemstocart

Query Parameters:

Field Type Description
ref string Required. Cart Reference ID

Request Body

Array of JSON of structure:

Field Type Description
product_id int Required. Product ID
quantity int Required. Quantity of the product to add
Get Cart

Get the cart referenced by ref

GET /cart

Query Parameters:

Field Type Description
ref string Required. Cart Reference ID
Remove Item from Cart

Remove a Product ID from a cart referenced by

DELETE /removeitemfromcart

Query Parameters:

Field Type Description
ref string Required. Cart Reference ID.

Request Body:

Field Type Description
product_id int Required. Product ID
quantity int Required. Quantity of the product to remove

Acknowledgements

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages