Introduction

What is it?

Thing of SHOPFAST as an API for an Marketplace. It can have many shop, customers, staffs etc

Motivation

The Motivation behind the service was to make project on ecommerce backed by an API that follows a microservice based design pattern

Requirements

JAVA
Version 15
MYSQL
MONGODB

CONNECTING THE DATABASES

DATABASE COUNT

DATABASE NAME
COUNT
MYSQL
1
MONGODB
6

MYSQL

We have only 1 mysql database. Here we have to create a database named "userserviceDB"

Please note MYSQL database URL is usually : jdbc:mysql://localhost:3306/DATABASE NAME

MONGODB

MONGODB IMAGE
These are the list of databases and the collections you have to create.

Setting up Geo

To setup the GEO location we have to download the file from github repo and import it in the GEO collection

The API Diagram

This is the API Diagram for User Service

Getting Started with the API

Launch APIs in Order

The Config Server

The config server is the server where configurations for your API resides. For Setting up this server it is there are some changes in the properties that are essential.

For the config server I'm using visit the github link

If you use your own version of config server you have make some changes under "ShopFastConfig/sec/main/resources/application.properties"

Implementation Ideas

The config server can be used to -

  1. set server ports
  2. Decide the admin username
  3. Controlling roles
Doing all this requires good understanding of the code

It is suggested you only edit the username of the admin if you must and dont touch anything else if you dont want to understand it.

The Eureka Server

The Eureka server usually runs at port 8761. Keep the port address free.

Eureka Server images

The Services

User Service

Default Port: 8081

Documentations: localhost:8081/swagger-ui.html

Description: Here user related informations and address related informations can be found.

The models of the service are pretty intuitive.

Its important to understand the only difference between a staff and customer is the customer wont be assigned to any shop.

Here is sample

Please note we are supposed use the shopCode for employees only

This is a sample for service user model. The given person is a customer

                        
                           {
                              "username" : "testuser1",
                              "shopCode" : "",
                              "password" : "1234",
                              "phoneNumber" : "012321312312",
                              "email" : "testuser1@gmail.com",
                              "gender" : "female"
                            }
                        
                     
What is address type?

Answer: An address can be a billing address or shipping address. They are often same. But if someone decides to send a gift they might be different

Its important that you dont provide any null values. If you dont want wanna use a property just use a default value.

Here is sample
                        
                           {
                              "firstName" : "test",
                              "lastName" : "user1",
                              "address" : "ggwwwppp",
                              "area" : "",
                              "city" : "Dhaka",
                              "district" : "",
                              "country" : "BD",
                              "addressType" : ""
                            }
                        
                     

Shop Service

Default Port: 8084

Documentations: localhost:8084/swagger-ui.html

Description: Here shop related informations can be found.

There are services for product related info
Discussing the Idea

The idea behind the shop is intuitive. But the question stands how a user is connected to shop. For instance, you can ask who is the admin of the given shop.

To answer the question we have to understand that in our system a user can be associated with only one shop.

The person who create the shop should have the role shop admin and he should the shopcode set to him.

  1. Create a Shop
  2. Assign the role of shop admin who created the shop
  3. Assign the shopCode to the user

Product Service

Default Port: 8082

Documentations: localhost:8082/swagger-ui.html

Description: Here product related informations(EXCEPT INVENTORY) can be found.

There are services for inventory related info
How to use the Product Model
  1. ShopCode is unique for a shop
  2. Product code is unique for product under any shop
  3. (ShopCode + Product code) is unique for an item
  4. A product has a custom properties. Example usecase -
    • you can save discounts
    • you can save fabric details for t-shirt
  5. A product can have variants like size, color but it's implemented in the inventory service

Dont worry about variants here

Inventory Service

Default Port: 8085

Documentations: localhost:8085/swagger-ui.html

Description: Here inventory related informations can be found.

Explanation behind the inventory model :
Properties
Explanation
shopCode
The product must belong to a shop
productCode

A unique code under a shop

variants

A product may come in many variants. Every variant consists a name and value

For instance, name = color, value = red

A group of variants might represents one product inventory

a t-shirt[Product] is of M size[variant 1] and color blue[variant 2] has 50 stocks. Here 2 group of variants must were used.

sku

There's an enpoint to get the sku of a product given the inventory informations

Most of the thing will be done using the product Inventory model. Please see the api documentations.

The warehouse is an experimental feature. Please put the warehouse name as "unknown" for now. Sample is given below. Please check how to create a product inventory in the working examples.

The Shipping Service(under developement)

Defining models

Geo

The model geo consists 2 attributes name(as name of the city), country

GeoCharge

The charge of delivering to a certain city of certain country(certain geo)

consists of two attributes. Geo and charge

ShippingCharge

A shopCode that is unique and says to which shop the shipping charge belongs

A shop must have global delivery charge

And a list of specific geo charge

Only the geo services are used by user service to internally

Working Example

Creating a user
Request type: POST
Endpoint: /user/add
Request Body:
                        
                           {
                              "username" : "testuser1",
                              "shopCode" : "",
                              "password" : "1234",
                              "phoneNumber" : "012321312312",
                              "email" : "testuser1@gmail.com",
                              "gender" : "female"
                            }
                        
                     

inlcude headers as requested above

Creating a Address
Request type: POST
Endpoint: /user/address/new/username=testuser1
Request Body:
                        
                           {
                              "firstName" : "test",
                              "lastName" : "user1",
                              "address" : "x road y block",
                              "area" : "",
                              "city" : "Dhaka",
                              "district" : "",
                              "country" : "BD",
                              "addressType" : "billing"
                            }
                            
                        
                     

inlcude headers as requested above

Creating a Shop
Request type: POST
Endpoint: /shop/new
Request Body:
                        
                           {
                              "shopCode" : "gp",
                              "shopName" : "GRAMMENPHONE",
                              "shopAddress" : "123142214 street",
                              "shopWebsite" : "",
                              "shopType" : "communication",
                              "phoneNumber" : [ "13212312312" ],
                              "email" : [ "gp@gmail.com" ]
                            }
                        
                     

inlcude headers as requested above

Updating a User
Request type: POST
Endpoint: /user/update
Request Body:
                        
                           {
                              "username" : "testuser1",
                              "shopCode" : "gp",
                              "password" : "1234",
                              "phoneNumber" : "012321312312",
                              "email" : "testuser1@gmail.com",
                              "gender" : "female"
                            }
                        
                     
Expected Response 200

inlcude headers as requested above

Creating a Product
Request type: POST
Endpoint: /product/new
Request Body:
                        
                           {
                              "productCode": "gp-200",
                              "shopCode": "gp",
                              "price": 233,
                              "category": "prepaid",
                              "tags": [
                                  "4G",
                                  "prepaid",
                                  "nano"
                              ],
                              "properties": {
                                  "name": "prepaid sim",
                                  "AppliedDiscount": "20%",
                                  "Material": "silicon"
                                 }
                          }
                        
                     

inlcude headers as requested above

Creating Inventory
Request type: POST
Endpoint: /inventory/add
Request Body:
                        
                           {
                              "shopCode": "gp",
                              "productsPerWareHouse": {
                                  "unknown": "100"
                              },
                              "productCode": "gp-200",
                              "variants": [
                                  {
                                      "name": "COLOR",
                                      "value": "RED"
                                  },
                                  {
                                      "name": "SIZE",
                                      "value": "M"
                                  }
                              ]
                          }
                        
                     

inlcude headers as requested above

Creating Order
Request type: POST
Endpoint: /orders/new
Request Body:
                        
                           {
                              "orders": [
                                {
                                  "shopCode": "gp",
                                  "productCode": "gp-200",
                                  "quantity": 5,
                                  "pricePerUnit" : 232,
                                  "variants": [
                                    {
                                      "name": "COLOR",
                                      "value": "RED"
                                    },
                            
                                    {
                                      "name": "SIZE",
                                      "value": "M"
                                    }
                            
                                  ]
                                }
                              ],
                              "billingId": 29,
                              "shippingId": 29,
                              "userName": "testuser1"
                            }
                        
                     

inlcude headers as requested above