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.
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 postgresqlInstall the following packages using go get
go get github.com/gorilla/mux
go get github.com/google/uuid
go get github.com/lib/pqStart the Postgresql server
sudo service postgresql startConnect to the psql server
sudo -u postgres psqlCreate a database user for the application
createuser service-pc-apiCreate a database for the API
createdb -O service-pc-api product-catalog -h localhost -U service-pc-apiInitialize the Database schema
psql -h localhost -U service-pc-api -f sql_commands/init.sqlTo run this project, you will need to add the following environment variables to your .env file
CONNECTION_STRING - Postgres connection string/url
Get Products
Sends the list of all products in an array
GET /products| 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| 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}| 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.
Add Category
Adds a new category to the database
POST /category| 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 /categoriesDelete 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}Get Inventory
View the current stock in inventory
GET /inventoryUpdate Inventory Item
Add/Update the inventory.
POST /inventory| Field | Type | Description |
|---|---|---|
product_id |
int |
Required. Product ID to update/update in inventory. |
quantity |
int |
Required. The quantity to update/update |
Add Item to Cart
Add new item or increase existing quantity.
POST /additemtocart| Field | Type | Description |
|---|---|---|
ref |
string |
Optional. Cart Reference ID. New cart is created if not passed. |
| 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| Field | Type | Description |
|---|---|---|
ref |
string |
Required. Cart Reference ID |
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| Field | Type | Description |
|---|---|---|
ref |
string |
Required. Cart Reference ID |
Remove Item from Cart
Remove a Product ID from a cart referenced by
DELETE /removeitemfromcart| Field | Type | Description |
|---|---|---|
ref |
string |
Required. Cart Reference ID. |
| Field | Type | Description |
|---|---|---|
product_id |
int |
Required. Product ID |
quantity |
int |
Required. Quantity of the product to remove |
