---
tags: parlando, Lidemy, final project
---
Parlando API doc
===
### users
| Description | HTTP Method | Path | Query Parameter |
|:------------- |:-----------:|:------ |:---------------:|
| admin login | POST | /v1/admin | |
| user login | POST | /v1/login | |
| user register | POST | /v1/users | |
| get user | GET | /v1/users | |
| update user | PATCH | /v1/users | |
### products
| Description | HTTP Method | Path | Query Parameter |
|:--------------- |:-----------:|:------------- |:--------------------------------------------------------------------- |
| get products | GET | /v1/products | sort (price, createdAt), <br> type(1, 2, 3, 4), <br> order(DESC, ASC) |
| get one product | GET | /v1/products/:id | |
| add product | POST | /v1/products | |
| update product | PATCH | /v1/products/id | |
| delete product | DELETE | /v1/products/id | |
### models
| Description | HTTP Method | Path | Query Parameter |
|:------------- |:-----------:|:----------- |:--------------- |
| get one model | GET | /v1/models/:id | |
| add model | POST | /v1/models | |
| update model | PATCH | /v1/models/:id | |
| delete model | DELETE | /v1/models/:id | |
### photos
| Description | HTTP Method | Path | Query Parameter |
|:------------- |:-----------:|:------- |:---------------------- |
| get photos | GET | /v1/photos | unlinked (true, false) |
| add photos | POST | /v1/photos | |
| update photos | PATCH | /v1/photos | |
### images
| Description | HTTP Method | Path | Query Parameter |
|:----------- |:-----------:|:------- |:--------------- |
| add image | POST | /v1/images | |
### orders
| Description | HTTP Method | Path | Query Parameter |
|:------------- |:-----------:|:------------- |:---------------:|
| get orders | GET | /v1/orders | |
| get one order | GET | /v1/orders/:UUID | |
| add order | POST | /v1/orders | |
| update order | PATCH | /v1/orders/:UUID | |
| delete order | DELETE | /v1/orders/:UUID | |
### recipients
| Description | HTTP Method | Path | Query Parameter |
|:----------------- |:-----------:|:---------------------------- |:---------------:|
| add recipient | POST | /v1/recipients/:UUID | |
---
## Examples
- user register
- resquest example:
```javascript=
method: "POST",
headers: {
"Content-Type": "application/json;charset=utf-8",
}
data: {
"username": "User",
"password": "User",
"realName": "User",
"email": "email@mail.email.com",
"phone": "0987654321"
}
```
- response example
```javascript=
{
"success": true,
"data": {
"token": "..."
}
}
```
- user login
- resquest example:
```javascript=
method: "POST",
headers: {
"Content-Type": "application/json;charset=utf-8",
},
data: {
"username": "User",
"password": "User"
}
```
- response example
```javascript=
{
"success": true,
"data": {
"token": "..."
}
}
```
- admin login
- resquest example:
```javascript=
method: "POST",
headers: {
"Content-Type": "application/json;charset=utf-8",
},
data: {
"username": "admin",
"password": "admin"
}
```
- response example
```javascript=
{
"success": true,
"data": {
"token": "..."
}
}
```
- GET one user (admin / user)
- request example
```javascript=
method: "POST",
headers: {
"Authorization": "Bearer {{token}}"
},
```
- response example
```javascript=
{
"success": true,
"data": {
"user": {
"id": 7,
"username": "User",
"realName": "User",
"email": "email@mail.com",
"phone": "0987654321"
}
}
}
```
- update user (user)
- resquest example:
```javascript=
method: "PATCH",
headers: {
"Content-Type": "application/json;charset=utf-8",
"Authorization": "Bearer {{token}}"
}
data: {
"realName": "Another User",
"email": "hi@email.com",
"phone": "0912345678"
}
```
- response example
```javascript=
{
"success": true,
"data": {
"user": {
"id": 7,
"realName": "Another User",
"email": "hi@email.com",
"phone": "0912345678"
}
}
}
```
- get products (admin / no auth)
- response example
```javascript=
{
"success": true,
data: {
"products": [
{
"id": 2,
"productName": "Headphone-02",
"price": 4500,
"type": "耳罩式耳機",
"article": "JSON string",
"isShow": 1,
"isDELETEd": 0,
"createdAt": "2020-06-29T00:00:45.000Z",
"updatedAt": "2020-12-31T08:29:37.000Z",
"Product_models": [
{
"id": 3,
"modelName": "Headphone-02RR",
"colorChip": "dd2d4a",
"storage": "庫存充足",
"productId": 2
}
],
"Photos": [
{
"id": 10,
"url": "https://i.picsum.photos/id/450/600/600.jpg?hmac=iDiDfbco87zw-mFU4wsfXJ5AND0cyYdIfn0y4ZZ_nPk",
"createdAt": "2020-12-31T08:29:37.000Z",
"updatedAt": "2020-12-31T08:29:37.000Z",
"productId": 2
},
...
]
},
...
]
}
}
```
- get one product (admin / no auth)
- resquest example:
```javascript=
headers: {
"Authorization": "Bearer {{token}}"
}
```
- response example
```javascript=
{
"success": true,
"data": {
"product": {
"productName": "Earphone-01",
"price": 9999,
"type": "入耳式耳機",
"article": "article",
"createdAt": "2020-11-14T00:03:15.000Z",
"models": [
{
"colorChip": "133c55",
"storage": "庫存充足"
},
{
"colorChip": "880d1e",
"storage": "庫存充足"
},
{
"colorChip": "364156",
"storage": "庫存充足"
},
{
"colorChip": "d66853",
"storage": "庫存充足"
}
],
"photos": [
"https://i.picsum.photos/id/62/600/600.jpg?hmac=_LxgtunXBYXALY49_Bf4n0jSAV15MR-cilGNPDSqIII",
"https://i.picsum.photos/id/741/600/600.jpg?hmac=FYRuIvSQgBxp5ufoHYijqwyq-GRGjdQSv77hUCDzr7A",
]
}
}
}
```
- add product (admin)
- resquest example:
```javascript=
method: "POST",
headers: {
"Authorization": "Bearer {{token}}"
}
data: {
"productName": "Speaker-100",
"price": 9999,
"article": "article",
"type": "音響"
}
```
- response example:
```javascript=
{
"success": true,
"data": {
"product": {
"id": 10,
"productName": "Speaker-100",
"price": 9999,
"type": "音響",
"article": "article",
"isShow": 0,
"isDeleted": 0,
"updatedAt": "2021-01-04T11:51:05.867Z",
"createdAt": "2021-01-04T11:51:05.867Z"
}
}
}
```
- update product (admin)
- resquest example:
```javascript=
method: "PATCH",
headers: {
"Authorization": "Bearer {{token}}"
}
data: {
"productName": "Earphone-01",
"price": 500,
"type": 2,
"article": "JSON string",
"isShow": 1
}
```
- response example:
```javascript=
{
"success": true,
"data": {
"product": {
"id": 3,
"productName": "Earphone-01",
"price": 500,
"type": "入耳式耳機",
"article": "article",
"isShow": 1,
"isDeleted": 0,
"createdAt": "2020-11-14T00:03:15.000Z",
"updatedAt": "2021-01-04T11:56:16.498Z"
}
}
}
```
- delete product (admin)
- resquest example:
```javascript=
method: "DELETE",
headers: {
"Authorization": "Bearer {{token}}"
}
```
- response example:
```javascript=
{
"success": true
}
```
- get one model (admin)
- resquest example:
```javascript=
method: "GET",
headers: {
"Authorization": "Bearer {{token}}"
}
```
- response example:
```javascript=
{
"success": true,
"data": {
"model": {
"id": 1,
"modelName": "Headphone-01AP",
"colorChip": "f49cbb",
"storage": 70,
"sell": 30,
"isShow": 1,
"isDeleted": 0,
"createdAt": "2020-07-05T08:42:07.000Z",
"updatedAt": "2021-01-04T16:16:42.000Z",
"productId": 1
}
}
}
```
- add model (admin)
- resquest example:
```javascript=
method: "POST",
headers: {
"Authorization": "Bearer {{token}}"
},
data: {
"productId": 1,
"modelName": "SB",
"colorChip": "87ceeb",
"storage": 100
}
```
- response example:
```javascript=
{
"success": true,
"data": {
"model": {
"id": 20,
"productId": 1,
"modelName": "Headphone-01SB",
"colorChip": "87ceeb",
"storage": 100,
"sell": 0,
"isShow": 0,
"isDeleted": 0,
"updatedAt": "2021-01-05T09:55:49.691Z",
"createdAt": "2021-01-05T09:55:49.691Z"
}
}
}
```
- update model (admin)
- resquest example:
```javascript=
method: "PATCH",
headers: {
"Authorization": "Bearer {{token}}"
}
data: {
"modelName": "newModelName",
"colorChip": 111111,
"storage": 100,
"isShow": 0
}
```
- response example:
```javascript=
{
"success": true,
"data": {
"model": {
"id": 5,
"modelName": "newModelName",
"colorChip": 111111,
"storage": 100,
"sell": 20,
"isShow": 0,
"isDeleted": 0,
"createdAt": "2020-11-14T00:03:15.000Z",
"updatedAt": "2021-01-05T09:59:14.752Z",
"productId": 3,
"Product": {
"id": 3,
"productName": "Earphone-08",
"price": 500,
"type": 2,
"article": "JSON string",
"isShow": 1,
"isDeleted": 1,
"createdAt": "2020-11-14T00:03:15.000Z",
"updatedAt": "2021-01-04T11:59:35.000Z"
}
}
}
}
```
- delete model (admin)
- resquest example:
```javascript=
method: "DELETE",
headers: {
"Authorization": "Bearer {{token}}"
}
```
- response example:
```javascript=
{
"success": true
}
```
- get photos (admin)
- resquest example:
```javascript=
method: "GET",
headers: {
"Authorization": "Bearer {{token}}"
}
```
- response example:
```javascript=
{
"success": true,
"data": {
"photos": [
{
"id": 1,
"url": "url",
"createdAt": "2021-01-04T03:22:41.000Z",
"updatedAt": "2021-01-04T03:22:41.000Z",
"productId": 1
}
]
}
}
```
- add photos
- resquest example:
```javascript=
const input = document.querySelector('input[name=files]')
const files = input.files
const formData = new FromData()
formData.append("files", files)
method: "POST",
headers: {
"Authorization": "Bearer {{token}}",
},
data: formData
```
- response example:
```javascript=
{
"success": true,
"data": {
"photos": [
{
"id": 101,
"url": "https://i.imgur.com/AVQ6yby.png",
"createdAt": "2021-01-05T10:56:59.544Z",
"updatedAt": "2021-01-05T10:56:59.544Z"
}
]
}
}
```
- update photos (admin)
- resquest example:
```javascript=
method: "POST",
headers: {
"Authorization": "Bearer {{token}}",
},
data: {
{
"productId": 5,
"photos": [50, 51, 52, 53, 54]
}
}
```
- response example:
```javascript=
{
"success": true
}
```
- get orders (admin / user)
- resquest example:
```javascript=
method: "GET",
headers: {
"Authorization": "Bearer {{token}}",
},
```
- response example:
```javascript=
{
"success": true,
"data": {
"orders": [
{
"UUID": "fa77d960-9b57-4aa6-a59c-e474a06498d5",
"totalPrice": 10000,
"status": "未付款",
"createdAt": "2020-07-10T04:26:41.000Z",
"updatedAt": "2021-01-04T16:16:42.000Z",
"products": [
{
"productId": 5,
"modelId": 13,
"modelName": "Earphone-02TR",
"unitPrice": 2500,
"count": 3
},
{
"productId": 6,
"modelId": 17,
"modelName": "Earphone-03RBF",
"unitPrice": 2500,
"count": 1
}
]
}
]
}
}
```
- get one order (admin / user)
- resquest example:
```javascript=
method: "GET",
headers: {
"Authorization": "Bearer {{token}}",
},
```
- response example:
```javascript=
{
"success": true,
"data": {
"order": {
"totalPrice": 9000,
"status": "處理中",
"createdAt": "2020-01-03T03:52:38.000Z",
"updatedAt": "2021-01-05T07:38:09.000Z",
"products": [
{
"productId": 2,
"modelId": 4,
"modelName": "Headphone-02T",
"unitPrice": 3000,
"count": 1
},
{
"productId": 1,
"modelId": 2,
"modelName": "Headphone-01T",
"unitPrice": 3000,
"count": 2
}
],
"recipient": [
{
"id": 1,
"name": "vvv",
"phone": "0912345678",
"email": "123@mail.com",
"address": "天上路天下巷100號",
"createdAt": "2021-01-05T00:00:00.000Z",
"updatedAt": "2021-01-05T00:00:00.000Z",
"cityId": 1,
"districtId": 1,
"orderId": 1
}
]
}
}
}
```
- add order (user)
- resquest example:
```javascript=
method: "POST",
headers: {
"Authorization": "Bearer {{token}}",
},
data: {
{
"products": [
{
"modelId": 3,
"count": 5
},
{
"modelId": 4,
"count": 1
}
]
}
}
```
- response example:
```javascript=
{
"success": true
}
```
- update order (admin)
- resquest example:
```javascript=
method: "PATCH",
headers: {
"Authorization": "Bearer {{token}}",
}
```
- response example:
```javascript=
{
"success": true
}
```
- delete order
- resquest example:
```javascript=
method: "PATCH",
headers: {
"Authorization": "Bearer {{token}}",
}
```
- response example:
```javascript=
{
"success": true,
}
```
- add recipient
- resquest example:
```javascript=
method: "POST",
headers: {
"Authorization": "Bearer {{token}}",
},
data: {
"name": "Leo Wang",
"phone": "0945678912",
"email": "hello@email.com",
"address": "中正路 138 號",
"cityId": 8,
"districtId": 108
}
```
- response example:
```javascript=
{
"success": true,
"data": {
"recipient": {
"id": 2,
"orderId": 7,
"name": "Leo Wang",
"phone": "0945678912",
"email": "hello@email.com",
"address": "中正路 138 號",
"cityId": 8,
"districtId": 108,
"updatedAt": "2021-01-05T15:40:37.054Z",
"createdAt": "2021-01-05T15:40:37.054Z"
}
}
}
```