Files
portal-api/rules.md
T

235 lines
8.3 KiB
Markdown

# REST API Rules Documentation
## Overview
Chuyển đổi từ Laravel Views sang REST API sử dụng JWT Authentication.
## Base URL
```
/api/v1
```
## Authentication
- **Admin API**: Sử dụng guard `admins-api` với JWT
- **Client API**: Sử dụng guard `client` với JWT (đã có sẵn)
## Headers
```
Authorization: Bearer <token>
Accept: application/json
Content-Type: application/json
```
## Response Format
### Success
```json
{
"error": false,
"data": { ... }
}
```
### Error
```json
{
"error": true,
"message": "Error message"
}
```
---
## API Endpoints
### 1. Authentication (Admin)
| Method | Endpoint | Description |
|--------|----------|-------------|
| POST | `/administrator/login` | Đăng nhập admin |
| POST | `/administrator/logout` | Đăng xuất |
| POST | `/administrator/refresh` | Refresh token |
| GET | `/administrator/me` | Lấy thông tin admin hiện tại |
### 2. Customers
| Method | Endpoint | Description |
|--------|----------|-------------|
| GET | `/administrator/customers` | Danh sách khách hàng |
| POST | `/administrator/customers` | Tạo khách hàng mới |
| GET | `/administrator/customers/{id}` | Chi tiết khách hàng |
| PUT | `/administrator/customers/{id}` | Cập nhật khách hàng |
| DELETE | `/administrator/customers/{id}` | Xóa khách hàng |
| POST | `/administrator/customers/{id}/reset-password` | Reset password |
| POST | `/administrator/customers/{id}/add-credit` | Nạp tiền |
| GET | `/administrator/customers/{id}/products` | Danh sách sản phẩm |
| GET | `/administrator/customers/{id}/invoices` | Danh sách hóa đơn |
| GET | `/administrator/customers/{id}/transactions` | Danh sách giao dịch |
| GET | `/administrator/customers/{id}/services` | Danh sách dịch vụ (VPS/Hosting) |
| GET | `/administrator/customers/trash` | Danh sách đã xóa |
| POST | `/administrator/customers/{id}/restore` | Khôi phục |
| DELETE | `/administrator/customers/{id}/force` | Xóa vĩnh viễn |
### 3. Orders
| Method | Endpoint | Description |
|--------|----------|-------------|
| GET | `/administrator/orders` | Danh sách đơn hàng |
| POST | `/administrator/orders` | Tạo đơn hàng mới |
| GET | `/administrator/orders/{id}` | Chi tiết đơn hàng |
| PUT | `/administrator/orders/{id}` | Cập nhật đơn hàng |
| DELETE | `/administrator/orders/{id}` | Xóa đơn hàng |
| POST | `/administrator/orders/{id}/accept` | Chấp nhận đơn hàng |
| POST | `/administrator/orders/{id}/cancel` | Hủy đơn hàng |
### 4. Invoices
| Method | Endpoint | Description |
|--------|----------|-------------|
| GET | `/administrator/invoices` | Danh sách hóa đơn |
| POST | `/administrator/invoices` | Tạo hóa đơn mới |
| GET | `/administrator/invoices/{id}` | Chi tiết hóa đơn |
| PUT | `/administrator/invoices/{id}` | Cập nhật hóa đơn |
| DELETE | `/administrator/invoices/{id}` | Xóa hóa đơn |
| POST | `/administrator/invoices/{id}/paid` | Đánh dấu đã thanh toán |
| POST | `/administrator/invoices/{id}/cancel` | Hủy hóa đơn |
### 5. Products
| Method | Endpoint | Description |
|--------|----------|-------------|
| GET | `/administrator/products` | Danh sách sản phẩm |
| POST | `/administrator/products` | Tạo sản phẩm mới |
| GET | `/administrator/products/{id}` | Chi tiết sản phẩm |
| PUT | `/administrator/products/{id}` | Cập nhật sản phẩm |
| DELETE | `/administrator/products/{id}` | Xóa sản phẩm |
| POST | `/administrator/products/{id}/duplicate` | Nhân bản sản phẩm |
| POST | `/administrator/products/import` | Import sản phẩm từ Excel |
| GET | `/administrator/products/export` | Export sản phẩm ra Excel |
### 6. Product Categories
| Method | Endpoint | Description |
|--------|----------|-------------|
| GET | `/administrator/product-categories` | Danh sách danh mục |
| POST | `/administrator/product-categories` | Tạo danh mục mới |
| GET | `/administrator/product-categories/{id}` | Chi tiết danh mục |
| PUT | `/administrator/product-categories/{id}` | Cập nhật danh mục |
| DELETE | `/administrator/product-categories/{id}` | Xóa danh mục |
### 7. Payments
| Method | Endpoint | Description |
|--------|----------|-------------|
| GET | `/administrator/payments` | Danh sách phương thức thanh toán |
| POST | `/administrator/payments` | Tạo phương thức thanh toán |
| GET | `/administrator/payments/{id}` | Chi tiết phương thức thanh toán |
| PUT | `/administrator/payments/{id}` | Cập nhật phương thức thanh toán |
| DELETE | `/administrator/payments/{id}` | Xóa phương thức thanh toán |
### 8. Modules - VPS/VMware
| Method | Endpoint | Description |
|--------|----------|-------------|
| GET | `/administrator/vps` | Danh sách VPS |
| GET | `/administrator/vps/{id}` | Chi tiết VPS |
| PUT | `/administrator/vps/{id}` | Cập nhật VPS |
| POST | `/administrator/vps/{id}/power-on` | Bật VPS |
| POST | `/administrator/vps/{id}/power-off` | Tắt VPS |
| POST | `/administrator/vps/{id}/restart` | Restart VPS |
| POST | `/administrator/vps/{id}/reinstall` | Cài lại VPS |
### 9. Modules - Hosting
| Method | Endpoint | Description |
|--------|----------|-------------|
| GET | `/administrator/hosting` | Danh sách Hosting |
| GET | `/administrator/hosting/{id}` | Chi tiết Hosting |
| PUT | `/administrator/hosting/{id}` | Cập nhật Hosting |
| POST | `/administrator/hosting` | Tạo Hosting mới |
| DELETE | `/administrator/hosting/{id}` | Xóa Hosting |
### 10. Modules - Domain
| Method | Endpoint | Description |
|--------|----------|-------------|
| GET | `/administrator/domains` | Danh sách Domain |
| GET | `/administrator/domains/{id}` | Chi tiết Domain |
| PUT | `/administrator/domains/{id}` | Cập nhật Domain |
### 11. Modules - DNS
| Method | Endpoint | Description |
|--------|----------|-------------|
| GET | `/administrator/dns` | Danh sách DNS |
| GET | `/administrator/dns/{id}` | Chi tiết DNS |
| PUT | `/administrator/dns/{id}` | Cập nhật DNS |
| POST | `/administrator/dns` | Tạo DNS mới |
| DELETE | `/administrator/dns/{id}` | Xóa DNS |
### 12. Modules - IP Pool
| Method | Endpoint | Description |
|--------|----------|-------------|
| GET | `/administrator/ip-pools` | Danh sách IP Pool |
| GET | `/administrator/ip-pools/{id}` | Chi tiết IP Pool |
| PUT | `/administrator/ip-pools/{id}` | Cập nhật IP Pool |
| POST | `/administrator/ip-pools` | Tạo IP Pool mới |
| DELETE | `/administrator/ip-pools/{id}` | Xóa IP Pool |
### 13. vCenter Management
| Method | Endpoint | Description |
|--------|----------|-------------|
| GET | `/administrator/vcenter` | Danh sách vCenter |
| POST | `/administrator/vcenter` | Tạo vCenter mới |
| GET | `/administrator/vcenter/{id}` | Chi tiết vCenter |
| PUT | `/administrator/vcenter/{id}` | Cập nhật vCenter |
| DELETE | `/administrator/vcenter/{id}` | Xóa vCenter |
| POST | `/administrator/vcenter/sync` | Đồng bộ vCenter |
| GET | `/administrator/vcenter/tree` | Lấy cây thư mục |
### 14. Settings
| Method | Endpoint | Description |
|--------|----------|-------------|
| GET | `/administrator/settings` | Danh sách cài đặt |
| PUT | `/administrator/settings` | Cập nhật cài đặt |
### 15. Reports/Logs
| Method | Endpoint | Description |
|--------|----------|-------------|
| GET | `/administrator/logs` | Danh sách logs |
| GET | `/administrator/logs/customer/{id}` | Logs của khách hàng |
### 16. Media
| Method | Endpoint | Description |
|--------|----------|-------------|
| GET | `/administrator/media` | Danh sách media |
| POST | `/administrator/media` | Upload media |
| DELETE | `/administrator/media/{id}` | Xóa media |
---
## DataTable Support
Các endpoint danh sách hỗ trợ tham số DataTable:
- `draw`: Draw counter
- `start`: Paging start
- `length`: Page length
- `search[value]`: Search value
- `order[0][column]`: Sort column
- `order[0][dir]`: Sort direction
Response DataTable:
```json
{
"draw": 1,
"recordsTotal": 100,
"recordsFiltered": 100,
"data": [...]
}
```
---
## Pagination
Các endpoint danh sách hỗ trợ phân trang:
- `page`: Số trang (mặc định: 1)
- `limit`: Số item trên trang (mặc định: 15)
---
## Error Codes
| Code | Description |
|------|-------------|
| 400 | Bad Request |
| 401 | Unauthorized |
| 403 | Forbidden |
| 404 | Not Found |
| 422 | Validation Error |
| 500 | Server Error |