Skip to content

rmt-06-florence-fox/ecommerce_server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ecommerce_server

weird admin cms

admin login
email : tio@mail.com
password : tiotio

env
SALT= 8
SECRET=grootnyasiapa

Restful endpoints

URL

Client URL : http://localhost:8080/ || https://cms-admin-tio.web.app/
Server URL : http://localhost:3000/ || https://cms-server-tio.herokuapp.com/
Customer URL : https://e-commerce-tio.web.app/

GET/login

login

Request Header

none

Request Body

email : tio@mail.com
password : tiotio

Response(200)

{
  access_token : "token string"
}

Response(404)

{
  message : 'email is not registered'
}

Response(400)

{
  message : "invalid"
}

Response(400)

{
  message : "field can not be empty"
}

Response(500)

{
  message : "internal server error"
}

POST /products

create product

Request Header

access_token : 'token string'

Request Body

{
  name : 'jam 2',
  "image_url": "https://www.jakartanotebook.com/images/products/72/63/22590/67/,
  price : 200000,
  stock : 10
}

Response(201)

{
  "id": 8,
  "name": "jam 2",
  "image_url": "https://www.jakartanotebook.com/images/products/72/63/22590/67/jam-dinding-bulat-european-style-34cm-colorful-vintage-multi-color-70.jpg",
  "price": 200000,
  "stock": 10
}

Response(404)

{
  message : 'email is not registered'
}

Response(400)

{
  message : "invalid"
}

Response(400)

{
  message : "field can not be empty"
}

Response(500)

{
  message : "internal server error"
}

GET /products

fetch all products

Request Header

access_token : 'token string'

Request Body

{
  none
}

Response(200)

{
  "products": [
        {
            "id": 3,
            "name": "groot",
            "image_url": "https://ae01.alicdn.com/kf/H21b16fc89a5b4e6c87e9d80ef495b4f1k/Lucu-Marvel-Avangers-Baby-Groot-Action-Figure-Mainan-PVC-Pahlawan-Model-Bayi-Manusia-Pohon-Lucu-Model.jpg",
            "price": 300000,
            "stock": 1,
            "createdAt": "2020-12-09T09:24:14.712Z",
            "updatedAt": "2020-12-09T12:35:27.052Z"
        },
        ...
    ]
}

Response(500)

{
  message : "internal server error"
}

GET /products/:id

find by id

Request Header

access_token : 'token string'

Request Body

{
  none
}

Request Params

{
  id : 3
}

Response(200)

{
  {
      "id": 3,
      "name": "groot",
      "image_url": "https://ae01.alicdn.com/kf/H21b16fc89a5b4e6c87e9d80ef495b4f1k/Lucu-Marvel-Avangers-Baby-Groot-Action-Figure-Mainan-PVC-Pahlawan-Model-Bayi-Manusia-Pohon-Lucu-Model.jpg",
      "price": 300000,
      "stock": 1,
      "createdAt": "2020-12-09T09:24:14.712Z",
      "updatedAt": "2020-12-09T12:35:27.052Z"
  },
}

Response(500)

{
  message : "internal server error"
}

put /products/:id

edit product

Request Header

access_token : 'token string'

Request Params

id : 3

Request Body

{
  name : 'groot2',
  image_url : 'https://ecs7.tokopedia.net/img/cache/900/product-1/2018/5/25/10897244/10897244_f9732383-bd09-4102-b740-75aab701b410_800_800.jpg',
  price : 20000,
  stock : 20
}

Response(200)

{ 
  id : 3
  name : 'groot2',
  image_url : 'https://ecs7.tokopedia.net/img/cache/900/product-1/2018/5/25/10897244/10897244_f9732383-bd09-4102-b740-75aab701b410_800_800.jpg',
  price : 20000,
  stock : 20
}

Response(404)

{ 
  "message": "product not found"
}

Response(401)

{ 
  "message": "please logoin first"
}

Response(401)

{ 
  "message": "you are not an admin"
}

Response(400)

{ 
  "message": [
    "stock can not lower than 0",
    "price can not lower than 0",
    "stock must be a number",
    "price must be a number"
  ]
}

delete /products/:id

delete product

Request Header

access_token : 'token string'

Request Params

id : 3

Request Body

{
  none
}

Response(200)

{ 
  "message": "succesfully delete a product"
}

Response(401)

{ 
  "message": "please logoin first"
}

Response(401)

{ 
  "message": "you are not an admin"
}

GET/register

register

Request Header

none

Request Body

email : tio@mail.com
password : tiotio

Response(200)

{
  {
    "id": 3,
    "email": "tio2@mail.com",
    "password": "$2a$08$OXugZS7CtcODtT5Nd8/lbe1e5dJbQr4aBkykkJ0JdCDbofyIym.Yi",
    "role": "user",
    "updatedAt": "2020-12-15T03:43:40.823Z",
    "createdAt": "2020-12-15T03:43:40.823Z"
    }
}

Response(400)

{
  {
    "messages": [
        "email must be unique",
        "must be between 6 to 20 characters"
    ]
  }
}

GET/logincustomer

login for customer

Request Header

none

Request Body

email : tio2@mail.com
password : tiotio

Response(200)

{
  access_token : "token string"
}

Response(404)

{
  message : 'email is not registered'
}

Response(400)

{
  message : "invalid"
}

Response(400)

{
  message : "field can not be empty"
}

Response(500)

{
  message : "internal server error"
}

POST/carts

creat or edit a cart for customer

Request Header

access_token: 'string'

Request Body

productId: number

Response(201)

{
  {
    "id": 28,
    "UserId": 3,
    "ProductId": 3,
    "quantity": 1,
    "status": false,
    "updatedAt": "2020-12-16T14:14:42.460Z",
    "createdAt": "2020-12-16T14:14:42.460Z"
  }
}

Response(200)

[
    1,
    [
        {
            "id": 28,
            "UserId": 3,
            "ProductId": 3,
            "status": false,
            "quantity": 2,
            "createdAt": "2020-12-16T14:14:42.460Z",
            "updatedAt": "2020-12-16T14:15:25.494Z"
        }
    ]
]

or

{
  message: 'successfully delete a cart'
}

Response(401)

{
  message: 'out of stock'
}

Response(500)

{
  message: 'internal server error'
}

GET/carts

fetch all unpaid carts for customer

Request Header

access_token: 'string'

Request Body

none

Response(200)

{
    "totalPrice": 600000,
    "carts": [
        {
            "id": 28,
            "UserId": 3,
            "ProductId": 3,
            "status": false,
            "quantity": 2,
            "createdAt": "2020-12-16T14:14:42.460Z",
            "updatedAt": "2020-12-16T14:15:25.494Z",
            "Product": {
                "id": 3,
                "name": "groot2",
                "image_url": "https://ae01.alicdn.com/kf/H21b16fc89a5b4e6c87e9d80ef495b4f1k/Lucu-Marvel-Avangers-Baby-Groot-Action-Figure-Mainan-PVC-Pahlawan-Model-Bayi-Manusia-Pohon-Lucu-Model.jpg",
                "price": 300000,
                "stock": 9,
                "createdAt": "2020-12-09T09:24:14.712Z",
                "updatedAt": "2020-12-16T13:22:40.078Z"
            }
        }
    ]
}

Response(500)

{
  message: 'internal server error'
}

GET/carts/histories

fetch histories for customer

Request Header

access_token: 'string'

Request Body

none

Response(200)

"carts": [
        {
            "id": 28,
            "UserId": 3,
            "ProductId": 3,
            "status": true,
            "quantity": 2,
            "createdAt": "2020-12-16T14:14:42.460Z",
            "updatedAt": "2020-12-16T14:15:25.494Z",
            "Product": {
                "id": 3,
                "name": "groot2",
                "image_url": "https://ae01.alicdn.com/kf/H21b16fc89a5b4e6c87e9d80ef495b4f1k/Lucu-Marvel-Avangers-Baby-Groot-Action-Figure-Mainan-PVC-Pahlawan-Model-Bayi-Manusia-Pohon-Lucu-Model.jpg",
                "price": 300000,
                "stock": 9,
                "createdAt": "2020-12-09T09:24:14.712Z",
                "updatedAt": "2020-12-16T13:22:40.078Z"
            }
        }
    ]

Response(500)

{
  message: 'internal server error'
}

DELETE/carts/

delete a cart for customer

Request Header

access_token: 'string'

Request Body

cartId

Response(200)

{
  message: 'succesfully deleted an item'
}

Response(500)

{
  message: 'internal server error'
}

DELETE/carts/

checkout all active cart for customer

Request Header

access_token: 'string'

Request Body

none

Response(200)

{
  {
    "success": [
        [
            1,
            [
                {
                    "id": 3,
                    "name": "groot2",
                    "image_url": "https://ae01.alicdn.com/kf/H21b16fc89a5b4e6c87e9d80ef495b4f1k/Lucu-Marvel-Avangers-Baby-Groot-Action-Figure-Mainan-PVC-Pahlawan-Model-Bayi-Manusia-Pohon-Lucu-Model.jpg",
                    "price": 300000,
                    "stock": 7,
                    "createdAt": "2020-12-09T09:24:14.712Z",
                    "updatedAt": "2020-12-16T14:26:22.830Z"
                }
            ]
        ],
        [
            1,
            [
                {
                    "id": 28,
                    "UserId": 3,
                    "ProductId": 3,
                    "status": true,
                    "quantity": 2,
                    "createdAt": "2020-12-16T14:14:42.460Z",
                    "updatedAt": "2020-12-16T14:26:22.830Z"
                }
            ]
        ]
    ]
}
}

Response(400)

  {
    message: [
      'failed to buy {product-name}',
      ...
  { ]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published