Shopping Cart for a fictional e-commerce site.

Shopping Cart

A shopping cart for a fictional e-commerce site. Main objective is to create REST APIs for some specific request/endpoints.

I am using Go as the programming language. For database, I am using MongoDB (MongoDB Atlas).

Models used in app:

//Product for holding a single product details
type Product struct {
	ID          string   `bson:"_id,omitempty"`
	Code        string   `bson:"code"`
	Name        string   `bson:"name"`
	Description string   `bson:"description"`
	Price       float64  `bson:"price"`
	Count       int      `bson:"count"`
	Discount    float64  `bson:"discount"`
	Colors      []string `bson:"colors"`
	Sizes       []string `bson:"sizes"`
}

//Item for holding a single item details
type Item struct {
	ID    primitive.ObjectID `json:"id,omitempty" bson:"_id,omitempty"`
	Code  string             `json:"code" bson:"code"`
	Unit  int                `json:"unit" bson:"unit"`
	Price float64            `json:"price" bson:"price"`
	Total float64            `json:"total" bson:"total"`
}

//Order for holding a single order details
type Order struct {
	ID    primitive.ObjectID `json:"id,omitempty" bson:"_id,omitempty"`
	Items []Item             `json:"items" bson:"items"`
	Total float64            `json:"total" bson:"total"`
}

//ResponseData for holding a api response details
type ResponseData struct {
	Status  string `json:"status"`
	ID      string `json:"id,omitempty"`
	Message string `json:"message"`
}

Build & Run

  1. Clone the repository (inside the src directory of your GOPATH) using following command:
git clone https://github.com/nahidhasan98/anexa_test.git
  1. Go inside the project directory:
cd anexa_test
  1. Build the project. This will create an executable file named app.exe inside the current directory.
go build -o app.exe
  1. And finally run the executable file.
app.exe [for cmd]
./app.exe [for Windows PowerShell]

Usage

1. Add an item to cart

To add an item to the cart, an HTTP POST request should be made at /api/cart this endpoint. And a json data (showing below) should be included with the request body.

{
	"code": "BDS03101",
	"unit": 2,
	"price": 202.8
}

Total price for this item in the cart will be calculated (total = price * unit) in backend thus no need to to provide total as json field.

This api call returns a json data as response in the following format for a new item addition:

If the item already exist in the cart then response is like:

{
    "status": "success",
    "message": "Existing item. Item successfully updated in the cart."
}

2. Delete an item from cart

To delete an item from the cart, an HTTP DELETE request should be made at /api/cart/{id} this endpoint where id should be an item id in the cart. The reason for providing an item id is to identify which item should be deleted from the cart.

This api call returns a json data as response in the following format:

{
    "status": "success",
    "id": "6101c76e63bba269e95e1c5c",
    "message": "Item successfully deleted from cart. Total item deleted: 1"
}

If the specific item is not found in the cart that is requested to be deleted then the response is like:

{
    "status": "error",
    "message": "No product found with ID: 6101c76e63bba269e95e1c5c"
}

3. Get cart info (All item(s) of the cart and total price)

To get cart information, an HTTP GET request should be made at /api/cart this endpoint.

This api call returns a json data as response in the following format:

{
    "items": [
        {
            "id": "6101c76e63bba269e95e1c5c",
            "code": "CAF05179",
            "unit": 2,
            "price": 115.8,
            "total": 231.6
        },
        {
            "id": "6101c833277da1da855d4c76",
            "code": "BDS03101",
            "unit": 1,
            "price": 202,
            "total": 202
        }
    ],
    "total": 433.6
}

If the cart is empty then the response is like:

{
    "items": null,
    "total": 0
}

4. Reset cart (Delete all item(s) from the cart)

To reset all item(s) from the cart, an HTTP DELETE request should be made at /api/cart this endpoint.

This api call returns a json data as response in the following format:

{
    "status": "success",
    "message": "All item(s) successfully deleted from cart. Total item(s) deleted: 2"
}

If the cart is empty then the response is like:

{
    "status": "error",
    "message": "No product found. Cart is already empty."
}

5. Place an order

To make and order, an HTTP POST request should be made at /api/order this endpoint. The item(s) for the order is retrieved from the cart and total price is also calculated.

This api call returns a json data as response in the following format:

{
    "status": "success",
    "id": "6101de8414805648138fce47",
    "message": "Order successfully placed. Order id: 6101de8414805648138fce47"
}

If the cart is empty then the response is like:

{
    "status": "error",
    "message": "No product found in the cart. Cart is empty."
}
Owner
Nahid Hasan
Wanna learn...
Nahid Hasan
Similar Resources

Cross commerce challenge - Cross Commerce Store Challenge With Golang

Cross commerce challenge - Cross Commerce Store Challenge With Golang

Cross Commerce Store Desafio Simples Aplicação ETL Todo o código fonte está cont

Feb 13, 2022

Cyber Stasis is an economic simulator in the form of a fictional game based on global real-time demand and supply.

Cyber Stasis is an economic simulator in the form of a fictional game based on global real-time demand and supply.

Cyber Stasis Cyber Stasis is an economic simulator in the form of a fictional game based on global real-time demand and supply. How to Play The game r

Dec 31, 2022

This is a shopping basket workshop that shows how to use KrakenD API Gateway.

This is a shopping basket workshop that shows how to use KrakenD API Gateway.

Go Restful Microservices and KrakenD API Gateway Workshop This is a shopping basket workshop that shows how to use KrakenD API Gateway. Consist of 5 m

Jan 3, 2023

Shopping List webapp with Prometheus metrics endpoint

shopping-list Shopping List webapp with Prometheus metrics endpoint This is an example app with prometheus metrics integrated. This app runs on port 5

Nov 4, 2021

MealPlanr is an application dedicated to the trivial and boring task of meal planning 📅 and generating a shopping list 🛒 .

MealPlanr is an application dedicated to the trivial and boring task of meal planning 📅 and generating a shopping list 🛒 .

MealPlanr is an application dedicated to the trivial and boring task of meal planning 📅 and generating a shopping list 🛒 .

Mar 1, 2022

QOR is a set of libraries written in Go that abstracts common features needed for business applications, CMSs, and E-commerce systems.

QOR English Chat Room: 中文聊天室: For security issues, please send us an email to [email protected] and give us time to respond BEFORE posting as an iss

Jan 2, 2023

Make e-commerce API using Golang

E-Commerce API i make this api using golang with gin How to use this Please create database go-ecommerce, or if u not it will error. For table, it wil

Oct 2, 2022

Project E-Commerce Alta Store Program Immersive Back End Batch 4

Project E-Commerce Alta Store Program Immersive Back End Batch 4

Project E-Commerce Project E-Commerce Alta Store Program Immersive Back End Batch 4 Explore the docs » Daftar Isi About The Project Built With ERD Con

Dec 30, 2021

Beatstore-backend-go - Backend implementation for a social media app / e-commerce store for instrumental music,built with Golang

BeatStore-Backend-Go Backend implementation for a social media app / e-commerce

Oct 7, 2022

Ecommerce-api - Rest api of e-commerce web application

Ecommerce-api - Rest api of e-commerce web application

E-commerce Rest API Swagger documentation to test api Domain diagram

Jan 2, 2023

Ecom-Golang-Fiber-Nextjs - E Commerce web app built in go with Fiber as backend, NextJS As frontend and PostgreSQL as database

Ecom-Golang-Fiber-Nextjs Setup Follow bellow steps to run the app in Dev & Prod

Nov 15, 2022

Bigfile -- a file transfer system that supports http, rpc and ftp protocol https://bigfile.site

Bigfile -- a file transfer system that supports http, rpc and ftp protocol   https://bigfile.site

Bigfile ———— a file transfer system that supports http, rpc and ftp protocol 简体中文 ∙ English Bigfile is a file transfer system, supports http, ftp and

Dec 31, 2022

gorilla/csrf provides Cross Site Request Forgery (CSRF) prevention middleware for Go web applications & services 🔒

gorilla/csrf gorilla/csrf is a HTTP middleware library that provides cross-site request forgery (CSRF) protection. It includes: The csrf.Protect middl

Dec 26, 2022

A small site builder for the Gemini protocol

🐟 Flounder A lightweight platform to help users build simple Gemini sites over http(s) and serve those sites over http(s) and Gemini Flounder is in A

Dec 7, 2021

gorilla/csrf provides Cross Site Request Forgery (CSRF) prevention middleware for Go web applications & services 🔒

gorilla/csrf gorilla/csrf is a HTTP middleware library that provides cross-site request forgery (CSRF) protection. It includes: The csrf.Protect middl

Jan 9, 2023

Plenti Static Site Generator with Go backend and Svelte frontend

Plenti Static Site Generator with Go backend and Svelte frontend

Plenti Static Site Generator with Go backend and Svelte frontend Website: https://plenti.co Requirements ❗ You must have NodeJS version 13 or newer As

Jan 2, 2023

verless is a Static Site Generator designed for Markdown-based content

verless is a Static Site Generator designed for Markdown-based content

verless (pronounced like serverless) is a Static Site Generator designed for Markdown-based content with a focus on simplicity and performance. It reads your Markdown files, applies your HTML templates and renders them as a website.

Dec 14, 2022

Golang based web site opengraph data scraper with caching

Golang based web site opengraph data scraper with caching

Snapper A Web microservice for capturing a website's OpenGraph data built in Golang Building Snapper building the binary git clone https://github.com/

Oct 5, 2022

Messing around with Go lang making a real estate site :)

Real Estate Used as a playground to learn Go lang. Setup is heavily inspired by an article by Michael Okoko. Requirements Migrate must be installed on

Nov 28, 2021
QuickAbeHiroshi - The golang program to open a web site which is the fastest in the world
QuickAbeHiroshi - The golang program to open a web site which is the fastest in the world

The golang program to open a web site which is the fastest in the world.

Jan 2, 2022
Giraffe - An opinionated static site generator written in Go

Giraffe: An opinionated static site generator I want to start 2022 by writing a

Nov 18, 2022
The noblest static site generator 🥬
The noblest static site generator 🥬

I love Darkness ?? Also posted here This is no life It doesn't feel right anymore. I feel that every time I write something for my website, I have to

Dec 19, 2022
Kuncie Cart - An implementation of Kuncie cart in Golang projects

Kuncie Cart - An implementation of Kuncie cart in Golang projects

Jan 21, 2022
Shopping-list - Shopping List as part of the training

ShoppingList Shopping List as part of the training Requirements User should be a

Jan 11, 2022
A simple shopping list that keeps track of a users shopping list using charm.sh tools

Terminal Shopping List This repo is a practise project for learning practical Go. I have chosen to use a toolset called Charm as it provides a rich se

Jan 13, 2022
Flexible E-Commerce Framework on top of Flamingo. Used to build E-Commerce "Portals" and connect it with the help of individual Adapters to other services.

Flamingo Commerce With "Flamingo Commerce" you get your toolkit for building fast and flexible commerce experience applications. A demoshop using the

Dec 31, 2022
Api-e-commerce - Golang fiber e commerce template

Golang fiber e commerce template Stack Golang v1.17 Fiber v2.24.0 Validation v10

May 7, 2022
E-commerce-project - RESTFUL API for TakTuku an E-Commerce App created for the purpose of study

About The Project RESTFUL API for TakTuku an E-Commerce App created for the purp

Jul 23, 2022
E-Commerce-Project - E-commerce adalah aplikasi untuk dapat melakukan jual-beli secara online

E-COMMERCE PROJECT E-commerce adalah aplikasi untuk dapat melakukan jual-beli se

May 23, 2022