Skip to content
Gilles Kagarama edited this page Jun 20, 2020 · 15 revisions

API Documentation for shop microservice

πŸŽ’ 🎁 πŸ’» πŸ”Œ ⌚ πŸ“· πŸ‘” πŸ‘  πŸ‘˜ πŸ‘™ πŸ‘œ πŸ’… πŸ“± πŸ“Ί πŸ”ˆ πŸ“» πŸ‘ž πŸ‘— πŸ‘– πŸ‘’

🏦 Shops

Interface

export interface shops {
  id?: string,
  name: string
  description: string
  slug: string
  tin: number
  logo: string
  photos: Array<string>
  longitude: string
  latitude: string
  location: string
  status: boolean
  user_id: string
  createdAt?: Date,
  updatedAt?: Date,
}

βž• Create shop

Description: This endpoint allows a user to create a shop
Path: /shops
Method: POST
Status: 201

Request body

{
  "name": "Samsung Supermarket",
  "description": "description of the shop",
  "slug": "samsung-supermarket", // Unique identifier
  "tin" 123123,
  "photos": ["arrayOfPhotos"],
  "location": "province, district, sector",
  "longitude": "",
  "latitude": "",
  "user_id": 1,
}

Response

{
  "message": "You have created a shop successfully",
  "shop": {
    "id": 1,
    "name": "Samsung Supermarket",
    "slug": "samsung-supermarket",
    "description": "description of the shop",
    "tin" 123123,
    "photos": ["arrayOfPhotos"],
    "location": "province, district, sector",
    "longitude": "",
    "latitude": "",
    "user_id": 1,
    "status": "active", // [active or inactive] shops with inactive status will not appear on public[excepts when admins are listing shops], 
  },
  "status": 201
}

πŸ“ Edit shop

Description: This endpoint allows a user to update the information of a shop
Path: /shops/:slug
Method: PATCH // only updates the fields that were supplied
Status: 200

Request body

{
  "name": "Samsung Supermarket Ltd",
}

Response

{
  "message": "You have updated this shop successfully",  
  "shop": {
    "id": 1,
    "name": "Samsung Supermarket Ltd",
    "slug": "samsung-supermarket",
    "description": "description of the shop",
    "tin" 123123,
    "photos": ["arrayOfPhotos"],
    "location": "province, district, sector",
    "longitude": "",
    "latitude": "",
    "user_id": 1,
    "status" : "active"
  },
  "status": 200
}

❌ Delete shop

Description: This endpoint allows a user to delete a shop
Path: /shops/:slug
Method: DELETE
Status: 200

Response

{
  "message": "You have deleted the shop successfully",
  "status": 200
}

Node: Don't delete shop, just change status of the shop, from active to inactive

πŸ“š Get one shop

Description: This endpoint allows a user to get one shop
Path: /shops/:slug
Method: GET
Status: 200

Response

{
  "message": "The shop has been retrieved successfully",
  "shop": {
    "id": 1,
    "name": "Samsung Supermarket Ltd",
    "slug": "samsung-supermarket",
    "tin" 123123,
    "photos": ["arrayOfPhotos"],
    "location": "province, district, sector",
    "longitude": "",
    "latitude": "",
    "user_id": 1,
    "status" : "active"
  },
  "owner": {
    "id": 1,
    "names": "John Doe",
    "email": "[email protected]",
    "phone_number": "078------",
    "profile": "image",
    "username": "username",
    "bio": "bio"
  },
  "products": [
    {
      // list of first 32 products,
    }
  ]
  "status": 200
}

πŸ“š Get list of shops

Description: This endpoint allows users to get list of shops
Path: /shops
Method: GET
Status: 200

Response

{
  "message": "You have retrieved shops successfully",
  "shops": [
    {
      "id": 1,
      "name": "Samsung Supermarket Ltd",
      "slug": "samsung-supermarket",
      "tin" 123123,
      "photos": ["arrayOfPhotos"],
      "location": "province, district, sector",
      "longitude": "",
      "latitude": "",
      "user_id": 1,
      "status" : "active",
      "owner": {
        "id": 1,
        "names": "John Doe",
        "email": "[email protected]",
        "phone_number": "078------",
        "profile": "image",
        "username": "username",
        "bio": "bio"
      },
    }
  ],
  "status": 200
}

πŸ“‚ Category Types

Manage category types in firebase

Object interface of types

export interface types {
  id?: string,
  name: string
  slug: string
  avatar?: string
  cover?: string
  user_id: string
  createdAt?: Date,
  updatedAt?: Date,
}

πŸ“‚ Categories

export interface categories {
  id?: string,
  name: string
  description: string
  slug: string
  avatar?: string
  user_id: string
  type_id: string
  createdAt?: Date,
  updatedAt?: Date,
}

βž• Create a category

Description: This endpoint allows a admin to create a category Path: /categories
Method: POST
Status: 201

Request body

{
  "name": "Electronics",
  "description": "description of the category",
  "avatar": "avatar",
  "user_id": 1,
}

Response

{
  "message": "You have created a category successfully",
  "category": {
    "id": 1,
    "name": "Electronics",
    "slug": "electronics", // Human-friendly unique identifier, it must be in lowercase, and separated by hyphen(-) sign if it composed by more than one words
    "description": "description of the category",
    "avatar": "avatar.png",
    "user_id": 1,
  },
  "status": 201
}

βž• Create a sub category

Description: This endpoint allows a admin to create a sub category Path: /categories/:slug
Method: POST
Status: 201

Request body

{
  "name": "Phones",
  "description": "description of a sub category",
  "slug": "electronics", // Human-friendly unique identifier, it must be in lowercase, and separated by hyphen(-) sign if it composed by more than one words
  "avatar": "avatar",
  "user_id": 1,
}

Response

{
  "message":"You have created a sub category successfully",
  "category": {
    "id": 2,
    "name": "Electronics",
    "description": "description of the category",
    "slug": "electronics",
    "avatar": "avatar.png",
    "user_id": 1,
  },
  "status": 201
}

πŸ“ Edit a category

Description: This endpoint allows a admin to edit a category
Path: /categories/:id
Method: PATCH // only updates the fields that were supplied
Status: 200

Request body

{
  "name": "Electronics Updated",
  "description": "description of the category",
  "avatar": "avatar"
}

Response

{
  "message": "You have edited a category successfully",
  "category": {
    "id": 1,
    "name": "Electronics Updated",
    "description": "description of the category",
    "avatar": "avatar.png",
    "user_id": 1,
  },
  "status": 200
}

❌ Delete a category

Description: This endpoint allows a admin to delete a category
Path: /categories/:id
Method: DELETE
Status: 200

Response

{
  "message": "You have deleted a category successfully",
  "status": 200
}

Note: Don't allow to delete a category when it has products

πŸ“š Get details of a specific category

Description: This endpoint allows a user to get details of a specific category Path: /categories/:slug
Method: GET
Status: 200

Response

{
  "message": "Details of a category has been retrieved successfully",
  "category": {
    "id": 1,
    "name": "Electronics",
    "slug": "electronics",
    "description": "Description of the category",
    "avatar": "avatar",
    "user_id": 1,
  },
  "subCategories": [
    {
      "id": 1,
      "name": "Electronics",
      "slug": "electronics",
      "description": "Description of the category",
      "avatar": "avatar",
      "user_id": 1,
    },
    {
      "id": 1,
      "name": "Fashion",
      "slug": "fashion",
      "description": "Description of the category",
      "avatar": "avatar",
      "user_id": 1,
    },
  ]
  "status": 200
}

πŸ’Ή Products

Manage products

Interface

export interface products {
  id?: string
  slug: string
  name: string
  description: string
  price: number
  avatar?: string
  photos?: Array<string>
  shop_id: string
  category_id: string
  brand_id?: string
  rating?: number
  allow_discount?: boolean
  discounted_percent?: number
  quantity?: number
  createdAt?: Date,
  updatedAt?: Date,
}

βž• Create a product

Description: This endpoint allows a user to create a product
Path: /products
Method: POST
Status: 201

Request body

{
  "name": "Samsung Galaxy S2",
  "description": "description of the product", // don't limit number of characters
  "price" 400,
  "user_id": 10f68143-9c36-4755-9bc2-52fffc651a08,
  "category_id": 2
}

Response

{
  "message": "You have created a product successfully",
  "product": {
    "id": "samsung-galaxy-s2-uuid", // Build slug-based unique identifier from the product name plus a 6 chars uuid
    "name": "Samsung Galaxy S2",
    "description": "description of the product",
    "avatar": "avatar.png",
    "photos": ["arrayOfPhotos"],
    "allow_discount": true,
    "discounted_percent": 00.0,
    "products_available": 23 // available products in the store
    "status": "draft", // [draft, published, deleted], default value is "draft"
    "shop_id": 1,
    "shop": {
      "id": 1,
      "name": "Samsung Supermarket Ltd",
      "slug": "samsung-supermarket",
      "tin" 123123,
      "photos": ["arrayOfPhotos"],
      "location": "province, district, sector",
      "longitude": "",
      "latitude": "",
      "user_id": 1,
      "status" : "active"
    },
    "category_id": 1,
    "category": {
      "id": 2,
      "name": "Mobile Phones",
      "description": "description of the category",
      "avatar": "avatar.png",
      "user_id": 2,
    }
  },
  "status": 201
}

πŸ“ Edit a product

Description: This endpoint allows a user to edit a product
Path: /products/:id
Method: PATCH // only updates the fields that were supplied
Status: 201

Request body

{
  "name": "Samsung Galaxy S2",
  "description": "description of the product", // don't limit number of characters
  "price" 400,
  "user_id": 1,
  "category_id": 2,
  "status": "published"
}

Response

{
  "message": "You have created a product successfully",
  "product": {
    "id": "samsung-galaxy-s2-uuid",
    "name": "Samsung Galaxy S2: Edited",
    "description": "description of the product",
    "avatar": "avatar.png",
    "photos": ["arrayOfPhotos"],
    "allow_discount": true,
    "star": NULL,
    "discounted_percent": 00.0,
    "status": "draft", // [draft, published, deleted], default value is "draft"
    "shop_id": 1,
    "shop": {
      "id": 1,
      "name": "Samsung Supermarket Ltd",
      "slug": "samsung-supermarket",
      "tin" 123123,
      "photos": ["arrayOfPhotos"],
      "location": "province, district, sector",
      "longitude": "",
      "latitude": "",
      "user_id": 1,
      "status" : "active"
    },
    "category_id": 1,
    "category": {
      "id": 2,
      "name": "Mobile Phones",
      "description": "description of the category",
      "avatar": "avatar.png",
      "user_id": 2,
    }
  },
  "status": 201
}

Get one product

Description: This endpoint allows a user to get a specific product
Path: /products/:id
Method: GET
Status: 200

Response

{
  "message": "You have retrieved a product successfully",
  "product": {
    "id": "samsung-galaxy-s2-uuid",
    "name": "Samsung Galaxy S2",
    "description": "description of the product",
    "avatar": "avatar.png",
    "photos": ["arrayOfPhotos"],
    "allow_discount": true,
    "discounted_percent": 00.0,
    "star": NULL,
    "quantity": 90, // available quality in stock, NULL is not provided
    "status": "draft", // [draft, published, deleted], default value is "draft"
    "shop_id": 1,
    "shop": {
      "id": 1,
      "names": "John Doe",
      "username": "john-1836",
      "email": "[email protected]",
      "phone_number": "078------",
      "profile": "image",
      "username": "username",
      "bio": "bio"
    },
    "category_id": 1,
    "category": {
      "id": 2,
      "name": "Mobile Phones",
      "description": "description of the category",
      "avatar": "avatar.png",
      "user_id": 2,
    },
    "brand_id": 1,
    "brand": {
      "id": 1,
      "name": "Samsung",
      "description": "description of the brand",
      "logo": "logo.png",
    },
    "tags": [
      {
        "id": 1,
        "name": "Something",
        "description": "description of the tag",
        "avatar": "avatar.png",
        "user_id": 1,
      },
      {
        "id": 1,
        "name": "Something1",
        "description": "description of the tag",
        "avatar": "avatar.png",
        "user_id": 1,
      },
    ]
    "product_variations": [
      {
        "id": 1,
        "name": "size",
        "value": ["M", "L"]
        "product_id": 1,
        "variation_id": 1,
      },
    ],
    "specs": [
      {
        "id": 1,
        "name": "OS",
        "value": "Android",
        "user_id": 1,
      },
      {
        "id": 1,
        "name": "Model",
        "value": "XGODY P30",
        "user_id": 1,
      },
      {
        "id": 1,
        "name": "Battery",
        "value": "2800mAh",
        "user_id": 1,
      }
    ],
    "additionalSpecs": [
      {
        "id": 1,
        "name": "OS",
        "value": "Android",
      },
      {
        "id": 1,
        "name": "Model",
        "value": "XGODY P30",
      }
    ],
  },
  "status": 200
}

Note: Difference between variations and specs: Variations are set of possible options a user can choose when they are buying an item: e.g.: a user choose to buy a black or gray material color for a given iPhone model but they don't have option to choose different size of the screen. So specs are additional specification of an item a user need to know

Get list of products

Description: This endpoint allows a user to fetch a list of products Path: /products?limit=32&offset=0
Method: GET
Status: 200

Response

{
  "message": "You have retrieved products successfully",
  "products": [
    {
      "id": "samsung-galaxy-s2-uuid",
      "name": "Samsung Galaxy S2",
      "description": "description of the product",
      "avatar": "avatar.png",
      "allow_discount": true,
      "discounted_percent": 00.0,
      "rating": 3.2, // this value is updated when a user creates a review
      "quantity": 90, // available quality in stock, NULL is not provided
      "status": "published", // if not authenticated or : retrieve only published ones, if authenticated and he is admin: list all(drafts, published, and deleted), if authenticated and he is admin: list all(drafts, published, and deleted), 
      "shop_id": 1,
      "shop": {
        "id": 1,
        "name": "Samsung Supermarket Ltd",
        "slug": "samsung-supermarket",
        "tin" 123123,
        "photos": ["arrayOfPhotos"],
        "location": "province, district, sector",
        "longitude": "",
        "latitude": "",
        "user_id": 1,
        "status" : "active"
      },
      "category_id": 1,
      "category": {
        "id": 2,
        "name": "Mobile Phones",
      },
      "product_variations": [
        {
          "id": 1,
          "name": "size",
          "value": ["M", "L"]
          "product_id": 1,
          "variation_id": 1,
        },
      ],
      "brand_id": 1,
      "brand": {
        "id": 1,
        "name": "Samsung",
        "logo": "logo.png",
      },
    }
  ],
  "count": 37, // number of available products
  "status": 200
}
Note: Building query to retrieve products

Path: /products?category=fashion&tag=women&limit=32&offset=0

  1. If the url is /products, retrieve first 32 products by recent added
  2. If category is provided in the query, e.g.: /products?category=shirt, retrieve first 32 products in the given path and apply filter by recent added
  3. If tag is provided in the query, e.g.: /products?tag=women, retrieve first 32 products in the given path and apply filter by recent added
  4. If limit and offset are provided, like: &limit=32&offset=0, retrieve products applying those parameters

Get list of products: Only when you are authenticated

Description: This endpoint allows authenticated user to fetch a list of products Path: /products/:username/all?limit=32&offset=0 `
Method: GET
Status: 200

Response

{
  "message": "You have retrieved products successfully",
  "products": [
    {
      "id": "samsung-galaxy-s2-uuid",
      "name": "Samsung Galaxy S2",
      "description": "description of the product",
      "avatar": "avatar.png",
      "allow_discount": true,
      "discounted_percent": 00.0,
      "star": 3.2, // this value is updated when a user creates a review
      "quantity": 90, // available quality in stock, NULL is not provided
      "status": "published", // if authenticated and admin: list all(drafts, published, and deleted) products, if authenticated and a seller: list all my(drafts, published) products ==> deleted ones are removed, 
      "shop_id": 1,
      "shop": {
        "id": 1,
        "name": "Samsung Supermarket Ltd",
        "slug": "samsung-supermarket",
        "tin" 123123,
        "photos": ["arrayOfPhotos"],
        "location": "province, district, sector",
        "longitude": "",
        "latitude": "",
        "user_id": 1,
        "status" : "active"
      },
      "category_id": 1,
      "category": {
        "id": 2,
        "name": "Mobile Phones",
      },
      "product_variations": [
        {
          "id": 1,
          "name": "size",
          "value": ["M", "L"]
          "product_id": 1,
          "variation_id": 1,
        },
      ],
      "brand_id": 1,
      "brand": {
        "id": 1,
        "name": "Samsung",
        "logo": "logo.png",
      },
    }
  ]
  "status": 200
}

Get list of products by shop

Description: This endpoint allows a user to fetch a list of products Path: /shops/:shop_slug/products?limit=32&offset=0
Method: GET
Status: 200

Response

{
  "message": "You have retrieved products successfully",
  "products": [
    {
      "id": "samsung-galaxy-s2-uuid",
      "name": "Samsung Galaxy S2",
      "description": "description of the product",
      "avatar": "avatar.png",
      "allow_discount": true,
      "discounted_percent": 00.0,
      "star": 3.2, // this value is updated when a user creates a review
      "quantity": 90, // available quality in stock, NULL is not provided
      "status": "published", // if not authenticated or : retrieve only published ones, if authenticated and he is admin: list all(drafts, published, and deleted), if authenticated and he is admin: list all(drafts, published, and deleted),
      "shop_id": 1,
      "shop": {
        "id": 1,
        "name": "Samsung Supermarket Ltd",
        "slug": "samsung-supermarket",
        "tin" 123123,
        "photos": ["arrayOfPhotos"],
        "location": "province, district, sector",
        "longitude": "",
        "latitude": "",
        "user_id": 1,
        "status" : "active"
      },
      "category_id": 1,
      "category": {
        "id": 2,
        "name": "Mobile Phones",
      },
      "product_variations": [
        {
          "id": 1,
          "name": "size",
          "value": ["M", "L"]
          "product_id": 1,
          "variation_id": 1,
        },
      ],
      "brand_id": 1,
      "brand": {
        "id": 1,
        "name": "Samsung",
        "logo": "logo.png",
      },
    }
  ],
  "count": 65, // number of available products
  "status": 200
}

❌ Delete a product

Description: This endpoint allows a user to delete a product
Path: /products/:id
Method: DELETE
Status: 200

Response

{
  "message": "You have deleted the product successfully",
  "status": 200
}

Note: We never delete a record in database, we change its status. Here, make it inactive, and make sure it is not listed on public and in customers account. Unless you are the admin

πŸ’« Product variations

Variations assigned to a product

Interface

export interface variations {
  id?: string
  name: string
  values: Array<string>
  description: string
  user_id: string
  category_id: string
  createdAt?: Date,
  updatedAt?: Date,
}

βž• Create a sub category variation

Description: This endpoint allows admin to create a sub category variation Path: /variations
Method: POST
Status: 201

Request body

{
  "name": "Size",
  "value": ["S", "M", "L"],
  "description": "description of variation",
  "user_id": 1,
}

Response

{
  "message": "You have created a sub category variation successfully",
  "variations": {
    "id": 1,
    "name": "Size",
    "value": ["S", "M", "L"],
    "description": "description of variation",
    "user_id": 1,
    "category_id": 1,
  },
  "status": 201
}

βž• Add a value to a variation

Description: This endpoint allows admin to add value to a set of variations
Path: /variations/
Method: PATCH // only updates the fields that were supplied
Status: 200

Request body

{
  "value": ["S", "M", "L", "XL"], //adding extra large size to the set
}

Response

{
  "message": "You have created a sub category variation successfully",
  "brand": {
    "id": 1,
    "name": "Size",
    "value": ["S", "M", "L", "XL"]
    "description": "description of variation",
    "user_id": 1,
    "category_id": 1,
  },
  "status": 200
}

Get variations of a specific subcategory

Description: This endpoint allows a user to get variations of a give subcategory
Path: /variations/:category_id
Method: GET
Status: 200

Response

{
  "message": "The variations of this category have been retrieved successfully", 
  "variations": [
    "color": ["White", "Black", "Gray", "Green"],
    "size": ["S", "M", "L", "XL"],
  ],
  "status": 200
}

❌ Remove value from a set of variations

Description: This endpoint allows admin to delete a variation Path: /variations/:id
Method: DELETE Status: 200

Request body

{
  "value": "S",
}

Response

{
  "message": "You have successfully removed a value in a set of  sub category variations",
  "variation": {
    "id": 1,
    "name": "Size",
    "value": ["M", "L", "XL"]
    "description": "description of variation",
    "user_id": 1,
    "category_id": 1,
  },
  "status": 200
}

Assign variations to a given product

This will take available variations for a given category and assign it to a product

Interface

export interface productVariations {
  id?: string
  name: string
  values: Array<string>
  description: string
  user_id: string
  category_id: string
  createdAt?: Date,
  updatedAt?: Date,
}

Description: This endpoint allows a sellers to assign variations to a product Path: /product-variations/assign/:product_id/:variation_id
Method: POST
Status: 201

Response

{
  "message": "Variation has been assigned to the product successfully",
  "product_variation": {
    "id": 1,
    "name": "Size",
    "value": ["M", "L"]
    "product_id": 1,
    "variation_id": 1,
  },
  "status": 201
}

Delete variations to a given product

Description: This endpoint allows a sellers to assign variations to a product Path: /product-variations/delete/:productVariation_id
Method: DELETE
Status: 200

Response

{
  "message": "You have deleted product variations to this product",
  "status": 200
}

πŸ“Œ Brands

Managing product brands

Interface

export interface brands {
  id?: string
  name: string
  description: string
  logo?: string
  user_id: string
  createdAt?: Date,
  updatedAt?: Date,
}

βž• Create a brand

Description: This endpoint allows a user to create a brand Path: /brands
Method: POST
Status: 201

Request body

{
  "name": "Samsung",
  "description": "description of the brand",
  "logo": "logo.png",
  "user_id": 1,
}

Response

{
  "message": "You have created a brand successfully",
  "brand": {
    "id": 1,
    "name": "Samsung",
    "description": "description of the brand",
    "logo": "logo.png",
    "user_id": 1,
  },
  "status": 201
}

πŸ“ Edit a brand

Description: This endpoint allows a user to update the information of a brand
Path: /brands/:id
Method: PATCH // only updates the fields that were supplied
Status: 200

Request body

{
  "name": "Huawei Industries",
  "description": "description of the brand",
  "logo": "logo.png"
}

Response

{
  "message": "You have updated this brand successfully",
  "brand": {
    "id": 1,
    "name": "Huawei Industries",
    "description": "description of the brand: Updated",
    "logo": "logo.png"
    "user_id": 1,
  },
  "status": 200
}

❌ Delete a brand

Description: This endpoint allows a user to delete a brand
Path: /brands/:id
Method: DELETE
Status: 200

Response

{
  "message": "You have deleted the brand successfully",
  "status": 200
}

Get one brand

Description: This endpoint allows a user to get one brand
Path: /brands/:id
Method: GET
Status: 200

Response

{
  "message": "The brand has been retrieved successfully",
  "brand": {
    "id": 1,
    "name": "Huawei Industries",
    "description": "description of the brand",
    "logo": "logo.png"
    "user_id": 1,
  },
  "owner": {
    "id": 1,
    "names": "John Doe",
    "email": "[email protected]",
    "phone_number": "078------",
    "profile": "image",
    "username": "john-1836",
    "bio": "bio"
  },
  "products": [
    {
      // list of first 32 products,
    }
  ]
  "status": 200
}

🎯 Tags

Tags will be used as a way of extending product categories

Interface

export interface tags {
  id?: string
  name: string
  description: string
  avatar?: string
  user_id: string
  createdAt?: Date,
  updatedAt?: Date,
}

βž• Create a tag

Description: This endpoint allows a user to create a tag Path: /tags
Method: POST
Status: 201

Request body

{
  "name": "Woman",
  "description": "description of the tag",
  "avatar": "avatar",
  "user_id": 1,
}

Response

{
  "message": "You have created a tag successfully",
  "tag": {
    "id": 1,
    "name": "Woman",
    "description": "description of the tag",
    "avatar": "avatar.png",
    "user_id": 1,
  },
  "status": 201
}

πŸ“ Edit a tag

Description: This endpoint allows a user to update the information of a tag
Path: /tags/:id
Method: PATCH // only updates the fields that were supplied
Status: 200

Request body

{
  "name": "Woman",
  "description": "description of the tag",
  "avatar": "avatar.png"
}

Response

{
  "message": "You have updated this tag successfully",
  "tag": {
    "id": 1,
    "name": "Women",
    "description": "description of the tag: Updated",
    "avatar": "avatar.png"
    "user_id": 1,
  },
  "status": 200
}

❌ Delete a tag

Description: This endpoint allows a user to delete a tag
Path: /tags/:id
Method: DELETE
Status: 200

Response

{
  "message": "You have deleted the tag successfully",
  "status": 200
}

Get one tag

Description: This endpoint allows a user to get one tag
Path: /tags/:id
Method: GET
Status: 200

Response

{
  "message": "A tag has been retrieved successfully",
  "tag": {
    "id": 1,
    "name": "Women",
    "description": "description of the tag",
    "avatar": "avatar.png"
    "user_id": 1,
  },
  "owner": {
    "id": 1,
    "names": "John Doe",
    "email": "[email protected]",
    "phone_number": "078------",
    "profile": "image",
    "username": "username",
    "bio": "bio"
  },
  "products": [
    {
      // list of first 32 products,
    }
  ]
  "status": 200
}

Assign a tag to a product

Description: This endpoint allows a user to create a tag Path: /tags/assign/:product_id/:tagId
Method: POST
Status: 201

Response

{
  "message": "This tag has been assigned to the product successfully",
  "product": {
    // check product object
  },
  "status": 201
}

Remove a tag from a product

Description: This endpoint allows a user to create a tag Path: /tags/remove/:product_id/:tagId
Method: POST
Status: 200

Response

{
  "message": "This tag has been removed from the product successfully",
  "product": {
    // check product object
  },
  "status": 200
}

πŸ‘” Category specifications and manage specifications of a given product

As admin, manage possible specifications to a given scategory. This will help sellers to set values of those specs

Interface

export interface specifications {
  id?: string
  name: string
  description: string
  category_id: string
  user_id: string
  createdAt?: Date,
  updatedAt?: Date,
}

βž• Create a spec

Description: This endpoint allows a user to create a spec of category
Path: /specs
Method: POST
Status: 201

Request body

{
  "name": "CPU",
  "description": "Description of the spec",
  "category_id": 1,
  "user_id": 1,
}

Response

{
  "message": "You have successfully created a spec to this category",
  "spec": {
    "id": 1,
    "name": "CPU",
    "description": "Description of the spec",
    "category_id": 1,
    "user_id": 1,
  },
  "status": 201
}

πŸ“ Edit a spec

Description: This endpoint allows a user to create a spec of sub category
Path: /specs/:specification_id
Method: PATCH
Status: 200

Request body

{
  "name": "CPU: Updated",
  "description": "Description of the spec: Updated",
  "avatar": "avatar.png"
}

Response

{
  "message": "You have successfully updated this specification",
  "spec": {
    "id": 1,
    "name": "CPU: Updated",
    "description": "Description of the spec: Updated",
    "avatar": "avatar.png"
    "category_id": 1,
    "user_id": 1,
  },
  "status": 200
}

❌ Delete a spec

Description: This endpoint allows a user to create a spec of sub category
Path: /specs/:specification_id
Method: DELETE
Status: 200

Response

{
  "message": "You have successfully deleted a spec",
  "status": 200
}

Get all specifications of a given category

Description: This endpoint allows a user to fetch all possible specifications of a give sub category Path: /specs/:category_id
Method: GET
Status: 200

Response

{
  "message": "You have successfully retrieved category specifications",
  "specs": [
    {
      "id": 1,
      "name": "CPU",
      "description": "Description of the spec",
      "avatar": "avatar.png"
      "category_id": 1,
      "user_id": 1,
    },
    {
      "id": 1,
      "name": "Rear Camera",
      "description": "Description of the spec",
      "avatar": "avatar.png"
      "category_id": 1,
      "user_id": 1,
    },
  ],
  "status": 200
}

Assign a specification to a given product

Interface

export interface productSpecifications {
  id?: string
  specification_id: string
  value: string,
  product_id: string
  createdAt?: Date,
  updatedAt?: Date,
}

Description: This endpoint allows a user to assign a specification to a given product Path: /specs/assign/:product_id/:specification_id
Method: POST
Status: 200

Response

{
  "message": "The specification has been successfully assigned to the product",
  "product": {
    // product object goes here, check the format on the endpoint of getting a specific product
  },
  "status": 200
}

Unassign a specification to a given product

Description: This endpoint allows a user to assign a specification to a given product Path: /specs/unassign/:product_id/:specification_id
Method: POST
Status: 200

Response

{
  "message": "You have successfully removed a specification to the product",
  "product": {
    // product object goes here, check the format on the endpoint of getting a specific product
  },
  "status": 200
}

πŸ‘” Additional specifications of the product

All products in a given subcategory will not have the same default set of specifications. Additional specs will allow sellers to more details on the product

Interface

export interface additionalSpecifications {
  id?: string
  name: string
  value: string
  product_id: string
  user_id: string
  createdAt?: Date,
  updatedAt?: Date,
}

βž• Create additional specifications

Description: This endpoint allows a user to create additional specs on a specific product Path: /additionalspecs/:product_id
Method: POST
Status: 201

Request body

{
  "name": "Weight",
  "value": "1.4Kg",
  "product_id": 1,
  "user_id": 1,
}

Response

{
  "message": "You have successfully added an additional specification to this product",
  "additionalspec": {
    "id": 1,
    "name": "Weight",
    "value": "1.4Kg",
    "product_id": 1,
    "user_id": 1,
  },
  "status": 201
}

❌ Remove an additional specification from a product

Description: This endpoint allows a user to remove an additional specs on a specific product Path: /additionalspecs/:product_id/:id
Method: DELETE
Status: 200

Response

{
  "message": "You have successfully removed an additional specification to this product",
  "additionalSpecs":[
    {
      "id": 1,
      "name": "Weight",
      "value": "1.4Kg",
      "product_id": 1,
      "user_id": 1,
    },
    {
      "id": 1,
      "name": "Something",
      "value": "Value of something",
      "product_id": 1,
      "user_id": 1,
    }
  ],
  "status": 200
}

πŸ‘” Product Reviews

Customer reviews on products

Interface

export interface reviews {
  id?: string
  rating?: 1 | 2 | 3 | 4 | 5,
  review: string
  user_id: string
  product_id: string
  createdAt?: Date,
  updatedAt?: Date,
}

βž• Create a review

Description: This endpoint allows a user to create a product review
Path: /review
Method: POST
Status: 201

Request body

{
  "rating": 4, // Position star option: 1, 2, 3, 4, 5
  "review": "Best value for money phone I have seen. I am an iPhone user and bought these as throw away phones but they are that good I am now going to give them away as Christmas Gifts. Highly recommended",
  "product_id": 1,
  "user_id": 1,
}

Response

{
  "message": "Thank you for reviewing this product.",
  "review": {
    "id": 1,
    "star": 4, // Position star option: 1, 2, 3, 4, 5
    "review": "Best value for money phone I have seen. I am an iPhone user and bought these as throw away phones but they are that good I am now going to give them away as Christmas Gifts. Highly recommended",
    "product_id": 1,
    "user_id": 1,
  },
  "status": 201
}

🚨🚨 Notes 🚨🚨

Every time a user creates a review, calculate a summary of all available reviews for that product and update the product record with that value

Formula: star = sum(reviews)/n where n is a number of reviews available

Example of star in product table: "star": 3.2

πŸ“ Edit a review

Description: This endpoint allows a user to edit a product review
Path: /review/:reviewId
Method: PATCH // only updates the fields that were supplied Status: 200

Request body

{
  "star": 4, // Position star option: 1, 2, 3, 4, 5
  "review": "Best value for money phone I have seen. I am an iPhone user and bought these as throw away phones but they are that good I am now going to give them away as Christmas Gifts. Highly recommended",
  "product_id": 1,
  "user_id": 1,
}

Response

{
  "message": "Thank you for reviewing this product.",
  "review": {
    "id": 1,
    "star": 3, // Position star option: 1, 2, 3, 4, 5
    "review": "Best value for money phone I have seen. I am an iPhone user and bought these as throw away phones but they are that good I am now going to give them away as Christmas Gifts. Highly recommended",
    "product_id": 1,
    "user_id": 1,
  },
  "status": 200
}

Get a list of review by product

Description: This endpoint allows a user to retrieve product reviews Path: /review
Method: GET Status: 200

Response

{
  "message": "Reviews have been retrieved successfully",
  "reviews": [
    {
      "id": 1,
      "star": 3,
      "review": "Best value for money phone I have seen. I am an iPhone user and bought these as throw away phones but they are that good I am now going to give them away as Christmas Gifts. Highly recommended",
      "product_id": 1,
      "user_id": 1,
    },
    {
      "id": 2,
      "star": 5,
      "review": "The headset, extra ear bud cushions, a cheezy manual, and the AC charging cable",
      "product_id": 1,
      "user_id": 1,
    },
  ],
  "status": 200
}

❌ Delete a review

Description: This endpoint allows a user to delete a review Path: /review/:reviewId
Method: DELETE
Status: 200

Response

{
  "message": "You have successfully deleted the review",
  "status": 200
}

πŸ’₯ πŸ’₯ πŸ’₯ πŸ’₯ πŸ’₯ πŸ’₯ πŸ’₯ πŸ’₯ πŸ’₯ πŸ’₯ πŸ’₯ πŸ’₯ πŸ’₯ πŸ’₯ πŸ’₯ πŸ’₯ πŸ’₯ πŸ’₯

πŸ‘” Search Product

Advanced products search

Description: This endpoint allows a user to delete a review
Path: /search?key=kitenge&rating=2-5&sort_price=upward
Method: GET
Status: 200

Response

Response object must be the same as fetching all products: Check /GET with path /products

πŸ‘” Building search parameters

Returns most recent products globally by default(i.e.: if no parameter provided), provide search key and sorting params to filter results

Apply only provided parameters: This /search?search=kitenge should work and also, /search?search=kitenge&price=low_to_high&rating=3-5

Query Parameters:

Search key:

?key=Ibitenge bishya // allow empty space

Filter by category:

?category=shirt

Filter by brand:

?brand=moshions

Filter by tag:

?tag=women

Filter by variations:

all variations variable must start by variant_. Example: variant_color=black or variant_size=L

?variant_color=gray

Filter by new added:

?sort=newest

Filter by lowest price:

?price=low_to_high

Filter by hight price:

?price=high_to_low

Filter by rating:

?rating=3-5

Possible star rating: 1-5, 2-5, 3-5, 4-5

Limit number of products (default is 32):

?limit=32

Offset/skip number of products (default is 0):

?offset=0

πŸ’₯ πŸ’₯ πŸ’₯ πŸ’₯ πŸ’₯ πŸ’₯ πŸ’₯ πŸ’₯ πŸ’₯ πŸ’₯ πŸ’₯ πŸ’₯ πŸ’₯ πŸ’₯ πŸ’₯ πŸ’₯ πŸ’₯ πŸ’₯

Clone this wiki locally