Update API DOC
parent
7b2a5122c6
commit
ee16b4e57e
359
API-DOC.md
359
API-DOC.md
|
|
@ -1,6 +1,301 @@
|
|||
# Products API
|
||||
|
||||
## 1. Create Product
|
||||
## 1. Get Product List (Paginated)
|
||||
|
||||
**Endpoint:**
|
||||
`GET /products`
|
||||
|
||||
**Description:**
|
||||
Lấy danh sách sản phẩm có phân trang.
|
||||
|
||||
**Query Parameters (Pagination):**
|
||||
|
||||
| Parameter | Type | Required | Description | Example |
|
||||
|-----------|--------|----------|--------------------------------------|---------|
|
||||
| page | number | No | Trang hiện tại (mặc định 1) | 1 |
|
||||
| limit | number | No | Số bản ghi mỗi trang (mặc định 10) | 20 |
|
||||
| search | string | No | Từ khóa tìm kiếm (tùy chọn) | "áo thun" |
|
||||
| sortBy | string | No | Sắp xếp theo field | "price" |
|
||||
| order | string | No | Thứ tự sắp xếp (`ASC` hoặc `DESC`) | "DESC" |
|
||||
|
||||
**Example Request:**
|
||||
|
||||
```
|
||||
GET /products?page=1&limit=20&search=áo thun&sortBy=price&order=DESC
|
||||
```
|
||||
|
||||
**Response (200 OK):**
|
||||
|
||||
```json
|
||||
{
|
||||
"message": "Success!",
|
||||
"status_code": 200,
|
||||
"data": [
|
||||
{
|
||||
"created_at": "2025-08-11T21:09:14.453Z",
|
||||
"updated_at": "2025-08-11T21:09:14.453Z",
|
||||
"id": 14,
|
||||
"images": [
|
||||
"https://example.com/images/product1.jpg",
|
||||
"https://example.com/images/product2.jpg"
|
||||
],
|
||||
"title": "MacBook Pro 14-inch 2023",
|
||||
"price": "2499.99",
|
||||
"category": "Laptops",
|
||||
"condition": "New",
|
||||
"brand": "Apple",
|
||||
"description": "MacBook Pro 14-inch với chip M2 Pro, 16GB RAM, 512GB SSD. Bảo hành chính hãng 12 tháng.",
|
||||
"tags": [
|
||||
"macbook",
|
||||
"laptop",
|
||||
"apple"
|
||||
],
|
||||
"sku": "MBP14-2023-512GBs",
|
||||
"location": "Hanoi, Vietnam",
|
||||
"histories": []
|
||||
},
|
||||
{
|
||||
"created_at": "2025-08-11T18:26:23.580Z",
|
||||
"updated_at": "2025-08-11T18:26:23.580Z",
|
||||
"id": 11,
|
||||
"images": [
|
||||
"http://localhost:4000/api/v1/medias/products/Tesstsees/http://localhost:4000/api/v1/medias/products/Tesstsees/product-1754961983572.png",
|
||||
"http://localhost:4000/api/v1/medias/products/Tesstsees/http://localhost:4000/api/v1/medias/products/Tesstsees/product-1754961983579.png"
|
||||
],
|
||||
"title": "Tesstsees",
|
||||
"price": "12",
|
||||
"category": "tools",
|
||||
"condition": "New",
|
||||
"brand": "cisco",
|
||||
"description": "gwegewgewgewgwegewgewgwegewgwegwegw",
|
||||
"tags": [
|
||||
"cisco",
|
||||
"abc",
|
||||
"cs",
|
||||
"css"
|
||||
],
|
||||
"sku": "cisco102290",
|
||||
"location": "",
|
||||
"histories": [
|
||||
{
|
||||
"created_at": "2025-08-11T20:23:25.681Z",
|
||||
"updated_at": "2025-08-11T20:23:25.681Z",
|
||||
"id": 59,
|
||||
"error": null,
|
||||
"published": true
|
||||
},
|
||||
{
|
||||
"created_at": "2025-08-11T20:21:28.036Z",
|
||||
"updated_at": "2025-08-11T20:21:28.036Z",
|
||||
"id": 58,
|
||||
"error": null,
|
||||
"published": true
|
||||
},
|
||||
{
|
||||
"created_at": "2025-08-11T20:20:56.385Z",
|
||||
"updated_at": "2025-08-11T20:20:56.385Z",
|
||||
"id": 57,
|
||||
"error": null,
|
||||
"published": true
|
||||
},
|
||||
{
|
||||
"created_at": "2025-08-11T20:11:32.193Z",
|
||||
"updated_at": "2025-08-11T20:11:32.193Z",
|
||||
"id": 51,
|
||||
"error": null,
|
||||
"published": true
|
||||
},
|
||||
{
|
||||
"created_at": "2025-08-11T20:09:49.754Z",
|
||||
"updated_at": "2025-08-11T20:09:49.754Z",
|
||||
"id": 50,
|
||||
"error": null,
|
||||
"published": true
|
||||
},
|
||||
{
|
||||
"created_at": "2025-08-11T20:06:54.170Z",
|
||||
"updated_at": "2025-08-11T20:06:54.170Z",
|
||||
"id": 49,
|
||||
"error": null,
|
||||
"published": true
|
||||
},
|
||||
{
|
||||
"created_at": "2025-08-11T20:01:53.407Z",
|
||||
"updated_at": "2025-08-11T20:01:53.407Z",
|
||||
"id": 40,
|
||||
"error": null,
|
||||
"published": true
|
||||
},
|
||||
{
|
||||
"created_at": "2025-08-11T20:01:08.031Z",
|
||||
"updated_at": "2025-08-11T20:01:08.031Z",
|
||||
"id": 39,
|
||||
"error": null,
|
||||
"published": true
|
||||
},
|
||||
{
|
||||
"created_at": "2025-08-11T20:00:22.331Z",
|
||||
"updated_at": "2025-08-11T20:00:22.331Z",
|
||||
"id": 36,
|
||||
"error": null,
|
||||
"published": true
|
||||
},
|
||||
{
|
||||
"created_at": "2025-08-11T19:59:35.199Z",
|
||||
"updated_at": "2025-08-11T19:59:35.199Z",
|
||||
"id": 35,
|
||||
"error": null,
|
||||
"published": true
|
||||
},
|
||||
{
|
||||
"created_at": "2025-08-11T20:42:03.159Z",
|
||||
"updated_at": "2025-08-11T20:42:03.159Z",
|
||||
"id": 60,
|
||||
"error": null,
|
||||
"published": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"created_at": "2025-08-11T02:06:31.109Z",
|
||||
"updated_at": "2025-08-11T02:06:31.109Z",
|
||||
"id": 10,
|
||||
"images": [
|
||||
"https://thegioimang.vn/data/upload/C1161-8P.jpg"
|
||||
],
|
||||
"title": "qwfqwfqwfqw",
|
||||
"price": "12",
|
||||
"category": "tools",
|
||||
"condition": "new",
|
||||
"brand": "cisco",
|
||||
"description": "qwfqwfqwfqwfwqfwqqwfwqfwqfwqfwqwfwqqw",
|
||||
"tags": [
|
||||
"qwfqwfq"
|
||||
],
|
||||
"sku": "qwfwq23",
|
||||
"location": "Hanoi, Vietnam",
|
||||
"histories": [
|
||||
{
|
||||
"created_at": "2025-08-11T20:17:24.290Z",
|
||||
"updated_at": "2025-08-11T20:17:24.290Z",
|
||||
"id": 55,
|
||||
"error": "Xpath is not found",
|
||||
"published": false
|
||||
},
|
||||
{
|
||||
"created_at": "2025-08-11T20:16:58.180Z",
|
||||
"updated_at": "2025-08-11T20:16:58.180Z",
|
||||
"id": 54,
|
||||
"error": null,
|
||||
"published": true
|
||||
},
|
||||
{
|
||||
"created_at": "2025-08-11T20:16:58.146Z",
|
||||
"updated_at": "2025-08-11T20:16:58.146Z",
|
||||
"id": 53,
|
||||
"error": "Xpath is not found",
|
||||
"published": false
|
||||
},
|
||||
{
|
||||
"created_at": "2025-08-11T20:15:34.493Z",
|
||||
"updated_at": "2025-08-11T20:15:34.493Z",
|
||||
"id": 52,
|
||||
"error": null,
|
||||
"published": true
|
||||
},
|
||||
{
|
||||
"created_at": "2025-08-11T20:05:54.056Z",
|
||||
"updated_at": "2025-08-11T20:05:54.056Z",
|
||||
"id": 48,
|
||||
"error": null,
|
||||
"published": true
|
||||
},
|
||||
{
|
||||
"created_at": "2025-08-11T20:05:54.045Z",
|
||||
"updated_at": "2025-08-11T20:05:54.045Z",
|
||||
"id": 47,
|
||||
"error": "Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.",
|
||||
"published": false
|
||||
},
|
||||
{
|
||||
"created_at": "2025-08-11T20:05:34.995Z",
|
||||
"updated_at": "2025-08-11T20:05:34.995Z",
|
||||
"id": 46,
|
||||
"error": null,
|
||||
"published": true
|
||||
},
|
||||
{
|
||||
"created_at": "2025-08-11T20:05:34.976Z",
|
||||
"updated_at": "2025-08-11T20:05:34.976Z",
|
||||
"id": 45,
|
||||
"error": "Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.",
|
||||
"published": false
|
||||
},
|
||||
{
|
||||
"created_at": "2025-08-11T20:05:03.656Z",
|
||||
"updated_at": "2025-08-11T20:05:03.656Z",
|
||||
"id": 44,
|
||||
"error": null,
|
||||
"published": true
|
||||
},
|
||||
{
|
||||
"created_at": "2025-08-11T20:05:03.642Z",
|
||||
"updated_at": "2025-08-11T20:05:03.642Z",
|
||||
"id": 43,
|
||||
"error": "Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.",
|
||||
"published": false
|
||||
},
|
||||
{
|
||||
"created_at": "2025-08-11T20:04:40.813Z",
|
||||
"updated_at": "2025-08-11T20:04:40.813Z",
|
||||
"id": 42,
|
||||
"error": null,
|
||||
"published": true
|
||||
},
|
||||
{
|
||||
"created_at": "2025-08-11T20:04:40.794Z",
|
||||
"updated_at": "2025-08-11T20:04:40.794Z",
|
||||
"id": 41,
|
||||
"error": "Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.",
|
||||
"published": false
|
||||
},
|
||||
{
|
||||
"created_at": "2025-08-11T20:00:40.786Z",
|
||||
"updated_at": "2025-08-11T20:00:40.786Z",
|
||||
"id": 38,
|
||||
"error": null,
|
||||
"published": true
|
||||
},
|
||||
{
|
||||
"created_at": "2025-08-11T20:00:40.762Z",
|
||||
"updated_at": "2025-08-11T20:00:40.762Z",
|
||||
"id": 37,
|
||||
"error": "Xpath is not found",
|
||||
"published": false
|
||||
},
|
||||
{
|
||||
"created_at": "2025-08-11T20:17:24.313Z",
|
||||
"updated_at": "2025-08-11T20:17:24.313Z",
|
||||
"id": 56,
|
||||
"error": null,
|
||||
"published": true
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"timestamp": "2025-08-12T04:21:50.385Z",
|
||||
"current_page": 1,
|
||||
"from": 1,
|
||||
"to": 3,
|
||||
"last_page": 1,
|
||||
"per_page": 10,
|
||||
"total": 3
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 2. Create Product
|
||||
|
||||
**Endpoint:**
|
||||
`POST /products`
|
||||
|
|
@ -27,17 +322,21 @@ Tạo mới một sản phẩm với đầy đủ thông tin chi tiết.
|
|||
|
||||
```json
|
||||
{
|
||||
"images": ["https://example.com/img1.jpg"],
|
||||
"title": "Áo thun nam",
|
||||
"price": 199000,
|
||||
"category": "Clothes",
|
||||
"condition": "new",
|
||||
"brand": "Nike",
|
||||
"description": "Áo thun nam thể thao",
|
||||
"tags": ["thể thao", "hàng mới"],
|
||||
"sku": "SKU001",
|
||||
"location": "Hà Nội"
|
||||
"images": [
|
||||
"https://example.com/images/product1.jpg",
|
||||
"https://example.com/images/product2.jpg"
|
||||
],
|
||||
"title": "MacBook Pro 14-inch 2023",
|
||||
"price": 2499.99,
|
||||
"category": "Laptops",
|
||||
"condition": "New",
|
||||
"brand": "Apple",
|
||||
"description": "MacBook Pro 14-inch với chip M2 Pro, 16GB RAM, 512GB SSD. Bảo hành chính hãng 12 tháng.",
|
||||
"tags": ["macbook", "laptop", "apple"],
|
||||
"sku": "MBP14-2023-512GBs",
|
||||
"location": "Hanoi, Vietnam"
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
**Response (201 Created):**
|
||||
|
|
@ -74,7 +373,7 @@ Tạo mới một sản phẩm với đầy đủ thông tin chi tiết.
|
|||
|
||||
---
|
||||
|
||||
## 2. Publish Product
|
||||
## 3. Publish Product
|
||||
|
||||
**Endpoint:**
|
||||
`POST /products/publist/:id`
|
||||
|
|
@ -129,4 +428,40 @@ POST /products/publist/1
|
|||
|
||||
---
|
||||
|
||||
## 4. Delete Product
|
||||
|
||||
**Endpoint:**
|
||||
`DELETE /products/:id`
|
||||
|
||||
**Description:**
|
||||
Xóa một sản phẩm dựa trên **ID**.
|
||||
|
||||
**Path Parameters:**
|
||||
|
||||
| Parameter | Type | Required | Description | Example |
|
||||
|-----------|--------|----------|------------------------------|---------|
|
||||
| id | number | Yes | ID của sản phẩm cần xóa | 1 |
|
||||
|
||||
**Example Request:**
|
||||
|
||||
```
|
||||
DELETE /products/1
|
||||
```
|
||||
|
||||
**Response (200 OK):**
|
||||
|
||||
```json
|
||||
{
|
||||
"message": "Delete success!",
|
||||
"status_code": 200,
|
||||
"data": true,
|
||||
"timestamp": "2025-08-12T04:23:57.382Z"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Notes
|
||||
- `sku` trong **Create Product** phải là duy nhất trong cơ sở dữ liệu.
|
||||
- Giá (`price`) được giới hạn 2 chữ số thập phân.
|
||||
- API `publist` chỉ thay đổi trạng thái sản phẩm, không chỉnh sửa dữ liệu khác.
|
||||
|
|
|
|||
Loading…
Reference in New Issue