docs: 更新项目文档,完善需求和技术细节
This commit is contained in:
@@ -8,6 +8,106 @@ const router = express.Router();
|
||||
const JWT_SECRET = process.env.JWT_SECRET || 'your-secret-key';
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/v1/auth/register:
|
||||
* post:
|
||||
* summary: 用户注册
|
||||
* description: 创建一个新的用户账户
|
||||
* tags:
|
||||
* - 认证管理
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - username
|
||||
* - password
|
||||
* - phone
|
||||
* properties:
|
||||
* username:
|
||||
* type: string
|
||||
* example: "user123"
|
||||
* description: 用户名
|
||||
* password:
|
||||
* type: string
|
||||
* example: "password123"
|
||||
* description: 密码(至少6位)
|
||||
* phone:
|
||||
* type: string
|
||||
* example: "13800138000"
|
||||
* description: 手机号
|
||||
* email:
|
||||
* type: string
|
||||
* example: "user@example.com"
|
||||
* description: 邮箱地址
|
||||
* user_type:
|
||||
* type: string
|
||||
* example: "farmer"
|
||||
* description: 用户类型
|
||||
* responses:
|
||||
* 201:
|
||||
* description: 注册成功
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* code:
|
||||
* type: integer
|
||||
* example: 201
|
||||
* message:
|
||||
* type: string
|
||||
* example: 注册成功
|
||||
* data:
|
||||
* type: object
|
||||
* properties:
|
||||
* user_id:
|
||||
* type: integer
|
||||
* example: 1
|
||||
* username:
|
||||
* type: string
|
||||
* example: "user123"
|
||||
* phone:
|
||||
* type: string
|
||||
* example: "13800138000"
|
||||
* email:
|
||||
* type: string
|
||||
* example: "user@example.com"
|
||||
* user_type:
|
||||
* type: string
|
||||
* example: "farmer"
|
||||
* token:
|
||||
* type: string
|
||||
* example: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
|
||||
* 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('/register', async (req, res, next) => {
|
||||
@@ -96,6 +196,87 @@ router.post('/register', async (req, res, next) => {
|
||||
});
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/v1/auth/login:
|
||||
* post:
|
||||
* summary: 用户登录
|
||||
* description: 使用用户名和密码进行身份验证并获取访问令牌
|
||||
* tags:
|
||||
* - 认证管理
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - username
|
||||
* - password
|
||||
* properties:
|
||||
* username:
|
||||
* type: string
|
||||
* example: "user123"
|
||||
* description: 用户名
|
||||
* password:
|
||||
* type: string
|
||||
* example: "password123"
|
||||
* description: 密码
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 登录成功
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* code:
|
||||
* type: integer
|
||||
* example: 200
|
||||
* message:
|
||||
* type: string
|
||||
* example: 登录成功
|
||||
* data:
|
||||
* type: object
|
||||
* properties:
|
||||
* user_id:
|
||||
* type: integer
|
||||
* example: 1
|
||||
* username:
|
||||
* type: string
|
||||
* example: "user123"
|
||||
* user_type:
|
||||
* type: string
|
||||
* example: "farmer"
|
||||
* token:
|
||||
* type: string
|
||||
* example: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
|
||||
* 400:
|
||||
* description: 请求参数错误
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* code:
|
||||
* type: integer
|
||||
* example: 400
|
||||
* message:
|
||||
* type: string
|
||||
* example: 用户名和密码为必填项
|
||||
* 401:
|
||||
* description: 用户名或密码错误
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* code:
|
||||
* type: integer
|
||||
* example: 401
|
||||
* message:
|
||||
* type: string
|
||||
* example: 用户名或密码错误
|
||||
*
|
||||
* 用户登录
|
||||
*/
|
||||
router.post('/login', async (req, res, next) => {
|
||||
|
||||
Reference in New Issue
Block a user