- 新增Redis插件,支持分布式锁及缓存功能 - 引入雪花ID生成器,用于生成唯一用户ID - 实现集群模式,支持多线程运行 - 优化用户注册逻辑,增加分布式锁机制 - 更新配置文件,添加Redis及雪花ID相关配置 - 修复部分代码格式及数据库字段类型
105 lines
3.5 KiB
JavaScript
105 lines
3.5 KiB
JavaScript
import { email, username, password } from '#schema/atomSchema';
|
|
// 默认schema
|
|
export const userDefaultSchema = {};
|
|
|
|
// 新用户注册
|
|
export const userRegisterSchema = {
|
|
tags: ['用户体系'],
|
|
summary: '新用户注册',
|
|
description: '创建新用户账号(需验证手机/邮箱)',
|
|
body: {
|
|
type: 'object',
|
|
required: ['username', 'email', 'password'],
|
|
errorMessage: {
|
|
required: {
|
|
username: '缺少用户名',
|
|
email: '缺少邮箱',
|
|
password: '缺少密码',
|
|
},
|
|
},
|
|
properties: {
|
|
username,
|
|
email,
|
|
password,
|
|
},
|
|
},
|
|
response: {
|
|
201: {
|
|
type: 'object',
|
|
properties: {
|
|
code: { type: 'number' },
|
|
data: {
|
|
type: 'object',
|
|
properties: {
|
|
username: { type: 'string' },
|
|
email: { type: 'string' },
|
|
userId: {
|
|
type: 'string',
|
|
examples: ["692397256422330400"]
|
|
},
|
|
pid: {
|
|
type: 'string',
|
|
enum: [0] // 固定值
|
|
},
|
|
phone: {
|
|
type: ['string', 'null'],
|
|
default: null
|
|
},
|
|
avatarUrl: {
|
|
type: ['string', 'null'],
|
|
default: null
|
|
},
|
|
userType: {
|
|
type: ['number', 'null'],
|
|
default: null
|
|
},
|
|
status: {
|
|
type: 'number',
|
|
enum: [0, 1] // 假设 0-正常 1-禁用
|
|
},
|
|
createdBy: {
|
|
type: 'number',
|
|
enum: [0] // 个人注册固定值
|
|
},
|
|
updatedBy: {
|
|
type: ['number', 'null'],
|
|
default: null
|
|
},
|
|
createdAt: {
|
|
type: 'string',
|
|
format: 'date-time'
|
|
},
|
|
updatedAt: {
|
|
type: 'string',
|
|
format: 'date-time'
|
|
}
|
|
},
|
|
required: [
|
|
'username', 'email', 'userId', 'pid',
|
|
'status', 'createdBy', 'createdAt', 'updatedAt'
|
|
],
|
|
additionalProperties: false // 严格模式
|
|
},
|
|
message: { type: 'string' }
|
|
}
|
|
},
|
|
400: {
|
|
description: '请求参数错误',
|
|
type: 'object',
|
|
properties: {
|
|
code: { type: 'number', enum: [400] },
|
|
error: { type: 'string' },
|
|
},
|
|
},
|
|
409: {
|
|
description: '用户名/邮箱已存在',
|
|
type: 'object',
|
|
properties: {
|
|
code: { type: 'number', enum: [409] },
|
|
error: { type: 'string' },
|
|
},
|
|
},
|
|
},
|
|
security: [{}], // 不需要认证
|
|
};
|