Skip to content

User Module

Faisol Chehumar edited this page Feb 27, 2022 · 25 revisions

Tables

users

Field Constraints Type Description
username NN, U VARCHAR(12)
password NN VARCHAR(255) Password must hash before save into persistence.

user_baskets

Field Constraints Type Description
user_id NN UUID

user_basket_items

Field Constraints Type Description
user_basket_id NN, FK UUID
product_sku_id NN, FK UUID
quantity NN INTEGER Quantity of product in basket.

user_addresses

Field Constraints Type Description
user_id NN, FK UUID
firstname VARCHAR(255)
lastname VARCHAR(255)
mobile NN VARCHAR(255)
email NN, U VARCHAR(255)
address VARCHAR(255)
province NN VARCHAR(255)
district NN VARCHAR(255)
zip_code NN VARCHAR(255)

user_orders

Field Constraints Type Description
user_id UUID VARCHAR(255)
shipping_address_id UUID VARCHAR(255)
invoice_no UUID VARCHAR(255)
shipping_method VARCHAR(255) EMS
payment_channel VARCHAR(255) CREDIT_CARD
total_items INTEGER
sub_total FLOAT
discount INTEGER
vat FLOAT
shipping_fee INTEGER
net_total FLOAT
remark FLOAT
status FLOAT PENDING

user_order_items

Field Constraints Type Description
user_order_id UUID VARCHAR(255)
product_sku_id UUID VARCHAR(255)
quantity INT

user_orders_transaction

Field Constraints Type Description
ref_number UUID VARCHAR(255)
user_id UUID VARCHAR(255)
user_order_id UUID VARCHAR(255)
status NN VARCHAR(255) PENDING
expired_date NN VARCHAR(255)

Commands

Login

POST /user/login

  • ใช้สำหรับให้ User login

Request body

Name Type Required Value Rule Description
username String Y user01
password String Y pass

Response Example

{
  "success": true,
  "data": {
    "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6IlVzZXIwMSJ9.saNh8MedJAAeSWE06XH5M-2EcWny0ZFfvIS-qJjFfWk",
  }
}

Exception

Error Code Error Message Description
AUTHENTICATION_FAIL Username or password incorrect.

Error Example

{
  "success": false,
  "error": "Username or password incorrect.",
}

Get item list in basket

GET /user/basket

  • ใช้สำหรับขอข้อมูลสินค้าที่อยู่ในตะกร้า

Request body

Name Type Required Value Rule Description
userId string Y pass

Response Example

{
  "success": true,
  "data": {
    "sub_total": 500,
    "items": [
      {
        "product_sku_id": "db1b53cd-1e8a-4bed-bc64-dd3279e7e37c",
        "sku": "NMD-BL-XL",
        "quantity": 5,
        "regular_price": 999,
        "sale_price": 500,
        "percent_discount": 15,
        "attributes": [
          { 
            "name": "size",
            "value": ["sm", "md", "xl"]
          },
          { 
            "name": "color",
            "value": ["black", "red"]
          }
        ],
        "attribute_index": [2, 1],
        "image": "https://cdn.foodddthailand.com/vender/Deli-veggies/products/xmKk71WGULRiP1zEb8FuUsaYMozijcRrRNs3.png"
      }
    ]
  }
}

Exception

Error Code Error Message Description
UNAUTHORIZATION Invalid access token.

Error Example

{
  "success": false,
  "error": "Username or password incorrect.",
}

Add product item to Basket

POST /user/basket/{product_sku_id}

  • ใช้สำหรับเพิ่มสินค้าลงในตะกร้า

Request body

Name Type Required Value Rule Description
quantity integer Y pass

Response Example

{
  "success": true,
  "data": null
}

Exception

Error Code Error Message Description
UNAUTHORIZATION Invalid access token.
NOT_ENOUGH_PRODUCT Not enough product.
NOT_FOUND_PRODUCT Not found product.

Error Example

{
  "success": false,
  "error": "Username or password incorrect.",
}

Get user addresses

POST /user/addresses

  • ใช้สำหรับขอข้อมูลที่อยู่ลูกค้า

Request body

Name Type Required Value Rule Description
user_id string Y

Response Example

{
  "success": true,
  "data": [
    {
       "id": "db1b53cd-1e8a-4bed-bc64-dd3279e7e37c",
       "address": "sdfdsf",
       "district": "กรุงเทพ",
       "province": "ล่ดพร้าว",
       "zip_code": "10722",
    }
  ]
}

Exception

Error Code Error Message Description
UNAUTHORIZATION Invalid access token.

Error Example

{
  "success": false,
  "error": "Username or password incorrect.",
}

Payment with credit card

POST /payment/charge/credit-card

  • ใช้จ่ายเงินซื้อสินค้า

Request body

Name Type Required Value Rule Description
user_id string Y
card_name string Y
card_number string Y
card_cvv string Y
coupon_code string Y

Response Example

{
  "success": true,
  "data": {
    order_id: "sadsdasdsadsad"
  }
}

Exception

Error Code Error Message Description
UNAUTHORIZATION Invalid access token.

Error Example

{
  "success": false,
  "error": "Username or password incorrect.",
}