This project is to create an API which would ease the process of shopping cart service using CRUD operations. The API would return the cart details of a customer based on a reference ID which is generated using google uuid package which will be used to view items present inside the cart.
- Go 1.19.3 (should still be backwards compatible with earlier versions)
- Postman-The collections will need an environment setup with
scheme
,port
andhost
variables setup with values ofhttp
,8080
andlocalhost
respectively. - PostgreSql database
Command to start working with postgresql
sudo service postgresql-9.3 initdb (Initialize the server by running the command)
sudo service postgresql-9.3 start (Start the server by running the command)
Command to run golang code
go run main.go (Run the code using the following command)
Commands to upload code to github
git init -b main (Initialize the local directory as a Git repository)
git add . && git commit -m "initial commit"(Stage and commit all the files in your project)
product_id
(int): ID of the specific product.name
(string): The name of the product.specification
(JSON): The Specifications of the product.sku
(string): Stock Keeping Unit number of the product.category_id
(int): The product's category ID which needs to be present in the Category Table.price
(float): The price of the product.
POST /addproduct
GET /getproducts/{id:[0-9]+}
Parameter | Type | Description |
---|---|---|
id |
int |
Required. Id of item to fetch |
GET /getproducts/{page_num:[0-9]+}
Parameter | Type | Description |
---|---|---|
id |
int |
Required. Id of item to fetch |
PUT /updateproduct
Delete /deleteproduct/{id:[0-9]+}
Parameter | Type | Description |
---|---|---|
id |
int |
Required. Id of item to fetch |
category_id
(int): category ID of the specific product.category_name
(string): Category name of the corresponding product
POST /addcategory
GET /getcategory/{id:[0-9]+}
Parameter | Type | Description |
---|---|---|
id |
int |
Required. Id of item to fetch |
PUT /updatecategory
Delete /deletecategory/{id:[0-9]+}
Parameter | Type | Description |
---|---|---|
id |
int |
Required. Id of item to fetch |
product_id
(int): Id of specific product.quantity
(int): Quantity of the specific product present inside the inventory.
POST /addinventory
GET /inventorydetail/{id:[0-9]+}
Parameter | Type | Description |
---|---|---|
id |
int |
Required. Id of item to fetch |
PUT /updateinventory
Delete /deleteinventory/{id:[0-9]+}
Parameter | Type | Description |
---|---|---|
id |
int |
Required. Id of item to fetch |
GET /cart/get (To retrieve the items present in the cart using the generated reference id)
Parameter | Type | Description |
---|---|---|
ref |
string |
ReferenceId used to retrieve data of a specific cart |
POST /cart/createreference (To produce a unique reference id for each customer)
POST /addtocart (To add required products to cart)
Parameter | Type | Description |
---|---|---|
ref |
string |
ReferenceId used to retrieve data of a specific cart |
product_id |
int |
Id required to insert the specific product into cart |
quantity |
int |
Quantity of the required |
DELETE /deleteitemfromcart (Delete specific product using its product_id)
Parameter | Type | Description |
---|---|---|
ref |
string |
ReferenceId used to retrieve data of a specific cart |
product_id |
int |
Id required to delete the specific product from the cart |
- google/uuid -The uuid package generates and inspects UUIDs based on RFC 4122 and DCE 1.1: Authentication and Security Services.
- encoding/json -Package json implements encoding and decoding of JSON as defined in RFC 7159.
- fmt-Package fmt implements formatted I/O with functions analogous to C's printf and scanf.
- io/ioutil-Package ioutil implements some I/O utility functions.
- net/http-Package http provides HTTP client and server implementations.
- gorilla mux implements a request router and dispatcher for matching incoming requests to their respective handler.