Skip to content

Latest commit

 

History

History
611 lines (491 loc) · 14.3 KB

Endpoints.md

File metadata and controls

611 lines (491 loc) · 14.3 KB

Products endpoints

Get all product [no auth required]

GET /api/product/all?limit=3&offset=0&sortBy=price&sort=ASC
  • take query parameters:

    query Type description optional
    limit integer limit the number of products returned true - default "50"
    offset integer the start index true - default "0"
    sortBy {name,id,price,rating,stock,created_at} sort by name, id (added date) , price , rating , stock or created_at (same output as id) true - default "id"
    sort {DESC or ASC} get from the end or from the start sorted by date of the add true - default "DESC"
  • returning "json"

    {
    "status": 200,
    "message": [
            {
                "id": 1,
                "name": "...",
                "rating": 4,
                "price": 7199,
                "description": "...",
                "images": [
                    "www.google.com/image.jpg","www.youtube.com/image.jpg"
                ],
                "stock": 5,
                "category_id": "1",
                "created_at": "2022-08-12T21:58:09.438Z"
            },
            /*....*/ 
            {
                "id": 3,
                "name": "...",
                "rating": 4.5,
                "price": 16000,
                "description": "...",
                "images": [
                    "www.google.com/image.jpg","www.youtube.com/image.jpg"
                ],
                "stock": 3,
                "category_id": "5",
                "created_at": "2022-08-12T22:16:44.616Z"
            }
        ]
    }
    

Get one product [no auth required]

GET /api/product?id=3
  • id query for the product

    query Type
    id number
  • returning "json"

    {
        "status": 200,
        "message": {
            "id": 3,
            "name": "...",
            "rating": 4.5,
            "price": 16000,
            "description": "...",
            "images": [
                "www.google.com/image.jpg","www.youtube.com/image.jpg"
            ],
            "stock": 3,
            "category_id": "5",
            "created_at": "2022-08-12T22:16:44.616Z"
        }
    }

Create product [admin token required]

POST /api/product/
  • headers for the request

    Header Type Description
    Authorization string need admin token
  • body "json" type needed

    body Type
    name string
    rating float
    price integer
    description string
    images array
    stock integer
    category_id integer
  • returning "json"

    {
        "status": 200,
    
    }

Update product [admin token required]

PATCH /api/product/
  • headers for the request

    Header Type Description
    Authorization string need admin token
  • body "json" type needed

    body Type optional
    id (id of product) number false
    name string true
    rating float true
    price integer true
    description string true
    images array true
    stock integer true
    category_id integer true
  • returning "json"

    {
        "status": 200,
    
    }

Delete product [admin token required]

DELETE /api/product/
  • headers for the request

    Header Type Description
    Authorization string need admin token
  • body "json" type needed

    body Type
    id integer
  • returning "json"

    {
        "status": 200,
    
    }

Category endpoints

Get all category [no auth required]

GET /api/category/all
  • returning "json"
    {
        "status": 200,
        "message": [
            {
                "id": 1,
                "name": "...",
                "created_at": "2022-08-12T21:58:09.438Z"
            },
            /*....*/ 
            {
                "id": 3,
                "name": "...",
                "created_at": "2022-08-12T22:16:44.616Z"
            }
        ]
    }

Get one category [no auth required]

GET /api/category?id=1
  • id query for the category

    query Type
    id number
  • returning "json"

    {
        "status": 200,
        "message": {
            "id": 1,
            "name": "...",
            "created_at": "2022-08-12T21:58:09.438Z"
        }
    }

Create category [admin token required]

POST /api/category/
  • headers for the request

    Header Type Description
    Authorization string need admin token
  • body "json" type needed

    body Type
    name string
  • returning "json"

    {
        "status": 200,
    
    }

Update category [admin token required]

PATCH /api/category/
  • headers for the request

    Header Type Description
    Authorization string need admin token
  • body "json" type needed

    body Type optional
    name string false
  • returning "json"

    {
        "status": 200,
    
    }

Delete category [admin token required]

DELETE /api/category/
  • headers for the request

    Header Type Description
    Authorization string need admin token
  • body "json" type needed

    body Type
    id integer
  • returning "json"

    {
        "status": 200,
    
    }

cart endpoints

Get all cart [admin token required]

GET /api/cart/all
  • headers for the request

    Header Type Description
    Authorization string need admin token
  • returning "json"

    {
    "status": 200,
    "message": [
    {
      "cart": [
        {
          "id": 1,
          "name": "...",
          "price": 15.5,
          "stock": 50,
          "images": [
            "dawd",
            "awdad"
          ],
          "rating": 4.6,
          "quantity": 1,
          "category_id": 1,
          "description": "adwadaw"
        },
        {
          "id": 2,
          "name": "...",
          "price": 15.5,
          "stock": 50,
          "images": [
            "dawd",
            "awdad"
          ],
          "rating": 4.6,
          "quantity": 3,
          "category_id": 2,
          "description": "adwadaw"
        }
      ],
      "user_id": "ahmed",
    },{
        "cart": [
        {
          "id": 6,
          "name": "...",
          "price": 15.5,
          "stock": 50,
          "images": [
            "ggrrg",
            "awrgrgrgdad"
          ],
          "rating": 4.6,
          "quantity": 1,
          "category_id": 1,
          "description": "adwadaw"
        },
        {
          "id": 9,
          "name": "...",
          "price": 15.5,
          "stock": 50,
          "images": [
            "wad",
            "awd"
          ],
          "rating": 4.6,
          "quantity": 3,
          "category_id": 2,
          "description": "adwadaw"
        }
      ],
      "user_id": "ahmed"
    }
    ]
    }

Get one cart [USER token required]

GET /api/cart?id="ahmed"
  • headers for the request

    Header Type Description
    Authorization string need USER token
  • id query for the cart

    query Type details
    user_id string id of the user created the cart not id of the cart
  • returning "json"

    {
        "status": 200,
        "message":  [
                {
                    "id": 1,
                    "name": "...",
                    "price": 15.5,
                    "stock": 50,
                    "images": [
                        "dawd",
                        "awdad"
                    ],
                    "rating": 4.6,
                    "quantity": 1,
                    "category_id": 1,
                    "description": "adwadaw"
                },
                {
                    "id": 2,
                    "name": "...",
                    "price": 15.5,
                    "stock": 50,
                    "images": [
                        "dawd",
                        "awdad"
                    ],
                    "rating": 4.6,
                    "quantity": 3,
                    "category_id": 2,
                    "description": "adwadaw"
                }
            ]
    }

Create cart [USER token required]

POST /api/cart/
  • headers for the request

    Header Type Description
    Authorization string need USER token
  • body "json" type needed

    body Type Description
    user_id string user id
  • returning "json"

    {
        "status": 200,
    
    }

Update cart [USER token required]

PATCH /api/cart/
  • headers for the request

    Header Type Description
    Authorization string need USER token
  • body "json" type needed

    body Type optional Description
    user_id string false id of the user created the cart not id of the cart
    item_id integer false id of the item you want to update in the cart
    action add,remove,delete false add product (quantity if exist) or remove product (remove it if quantity 0) or delete the product from the cart
    quantity integer true quantity of the item you want to update in the cart (on add or remove) default is 1
  • returning "json"

    {
        "status": 200,
    
    }

Delete cart [USER token required]

DELETE /api/cart/
  • headers for the request

    Header Type Description
    Authorization string need USER token
  • body "json" type needed

    body Type Description
    user_id string id of the user created the cart not id of the cart
  • returning "json"

    {
        "status": 200,
    
    }

note: this endpoint will delete only all the items in the cart and not the cart itself


Checkout

Checkout [USER token required]

POST /api/checkout/
  • headers for the request

    Header Type Description
    Authorization string need USER token
  • body "json" type needed

    body Type Description
    user_id string id of the user to checkout
  • returning "json"

    {
        "status": 200,
        "message": "Checkout Successful"
    }

Data Shapes

Product

  • id (integer)
  • name (string)
  • rating (float)
  • price (integer)
  • description (string)
  • images (array)
  • stock (integer)
  • category_id (integer)
  • created_at (string)

Category

  • id (integer)
  • name (string)
  • created_at (string)

Cart

  • id (integer)
  • user_id (integer)
  • created_at (string)

Cart_Product

  • cart_id (integer)
  • product_id (integer)
  • quantity (integer)
  • hashed_cart_id (string) -- note: to make the user can't create more than 1 order of the same product but this doesn't include quantity
  • created_at (string)

admin

  • id (integer)
  • uuid (string)
  • created_at (string)

Database schema

Database schema