docs: 更新项目文档,完善需求和技术细节

This commit is contained in:
ylweng
2025-09-02 23:41:32 +08:00
parent 3023748e85
commit e90c183c90
9 changed files with 1865 additions and 168 deletions

View File

@@ -8,7 +8,74 @@ const { asyncHandler } = require('../middlewares/errorHandler');
const router = express.Router();
/**
* 获取用户列表(管理员权限)
* @swagger
* /api/v1/users:
* get:
* summary: 获取用户列表(管理员权限)
* description: 分页获取用户列表,支持按关键词和用户类型筛选
* tags:
* - 用户管理
* security:
* - bearerAuth: []
* parameters:
* - in: query
* name: page
* schema:
* type: integer
* default: 1
* description: 页码
* - in: query
* name: limit
* schema:
* type: integer
* default: 10
* description: 每页数量
* - in: query
* name: keyword
* schema:
* type: string
* description: 搜索关键词(用户名、手机号或邮箱)
* - in: query
* name: user_type
* schema:
* type: integer
* description: 用户类型
* responses:
* 200:
* description: 成功获取用户列表
* content:
* application/json:
* schema:
* type: object
* properties:
* code:
* type: integer
* example: 200
* message:
* type: string
* example: 获取成功
* data:
* type: object
* properties:
* users:
* type: array
* items:
* $ref: '#/components/schemas/User'
* pagination:
* $ref: '#/components/schemas/Pagination'
* 401:
* description: 未授权访问
* content:
* application/json:
* schema:
* type: object
* properties:
* code:
* type: integer
* example: 401
* message:
* type: string
* example: 未授权访问
*/
router.get('/', adminRequired, asyncHandler(async (req, res) => {
const { page = 1, limit = 10, keyword, user_type } = req.query;
@@ -57,7 +124,91 @@ router.get('/', adminRequired, asyncHandler(async (req, res) => {
}));
/**
* 创建用户(管理员权限)
* @swagger
* /api/v1/users:
* post:
* summary: 创建用户(管理员权限)
* description: 管理员创建新用户
* tags:
* - 用户管理
* security:
* - bearerAuth: []
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - username
* - phone
* - email
* - user_type
* - password
* properties:
* username:
* type: string
* example: "user123"
* phone:
* type: string
* example: "13800138000"
* email:
* type: string
* example: "user@example.com"
* user_type:
* type: integer
* example: 1
* password:
* type: string
* example: "password123"
* real_name:
* type: string
* example: "张三"
* avatar_url:
* type: string
* example: "https://example.com/avatar.jpg"
* responses:
* 201:
* description: 用户创建成功
* content:
* application/json:
* schema:
* type: object
* properties:
* code:
* type: integer
* example: 201
* message:
* type: string
* example: 用户创建成功
* data:
* $ref: '#/components/schemas/User'
* 400:
* description: 参数错误
* content:
* application/json:
* schema:
* type: object
* properties:
* code:
* type: integer
* example: 400
* message:
* type: string
* example: 参数错误
* 409:
* description: 用户名、邮箱或手机号已存在
* content:
* application/json:
* schema:
* type: object
* properties:
* code:
* type: integer
* example: 409
* message:
* type: string
* example: 用户名已存在
*/
router.post('/', adminRequired, asyncHandler(async (req, res) => {
const { username, phone, email, user_type, password, real_name, avatar_url } = req.body;