Quellcode durchsuchen

📝 docs(commands): update generic-crud documentation

- add instructions for schema creation: only create entity, create and update request schemas
- remove requirement for list response schema and type exports

✨ feat(template): add template schema definitions

- create TemplateSchema with complete entity fields including id, title, description, file relations
- implement CreateTemplateDto with validation rules for template creation
- add UpdateTemplateDto supporting partial updates with optional fields
- include validation rules for all fields with appropriate error messages and examples
yourname vor 3 Monaten
Ursprung
Commit
ab78e0a479

+ 4 - 1
.roo/commands/generic-crud-创建实体验证规则.md

@@ -59,4 +59,7 @@ description: "创建已有实体的schema指令"
         }),
 
     })
-    ```
+    ```
+
+5. your-entity.schema.ts中, 只创建 模板实体完整Schema,创建模板请求Schema,更新模板请求Schema 这三样就可以了, 
+   不需要创建 模板列表响应Schema 和 schema相应的类型导出

+ 106 - 0
src/server/modules/templates/template.schema.ts

@@ -0,0 +1,106 @@
+import { z } from '@hono/zod-openapi';
+import { FileSchema } from '@/server/modules/files/file.schema';
+import { DeleteStatus, DisabledStatus } from '@/share/types';
+
+// 模板实体完整Schema
+export const TemplateSchema = z.object({
+  id: z.number().int('必须是整数').positive('必须是正整数').openapi({
+    description: '模板ID',
+    example: 1
+  }),
+  title: z.string().min(1, '模板标题不能为空').max(255, '模板标题最多255个字符').openapi({
+    description: '模板标题',
+    example: '项目计划书模板'
+  }),
+  description: z.string().nullable().openapi({
+    description: '模板描述',
+    example: '适用于各类项目管理的标准计划书模板'
+  }),
+  fileId: z.number().int('必须是整数').positive('必须是正整数').openapi({
+    description: '关联文件ID',
+    example: 1
+  }),
+  file: FileSchema.openapi({
+    description: '关联文件信息'
+  }),
+  category: z.string().min(1, '模板分类不能为空').max(100, '模板分类最多100个字符').openapi({
+    description: '模板分类',
+    example: '项目管理'
+  }),
+  isFree: z.number().int('必须是整数').min(0, '状态值只能是0或1').max(1, '状态值只能是0或1').openapi({
+    description: '是否免费:0-收费,1-免费',
+    example: 0
+  }),
+  downloadCount: z.number().int('必须是整数').min(0, '下载次数不能为负数').openapi({
+    description: '下载次数',
+    example: 100
+  }),
+  isDisabled: z.number().int('必须是整数').min(0, '状态值只能是0或1').max(1, '状态值只能是0或1').default(DisabledStatus.ENABLED).openapi({
+    description: '是否禁用:0-启用,1-禁用',
+    example: DisabledStatus.ENABLED
+  }),
+  isDeleted: z.number().int('必须是整数').min(0, '状态值只能是0或1').max(1, '状态值只能是0或1').default(DeleteStatus.NOT_DELETED).openapi({
+    description: '是否删除:0-未删除,1-已删除',
+    example: DeleteStatus.NOT_DELETED
+  }),
+  createdAt: z.coerce.date('创建时间格式不正确').openapi({
+    description: '创建时间',
+    example: '2024-01-15T10:30:00Z'
+  }),
+  updatedAt: z.coerce.date('更新时间格式不正确').openapi({
+    description: '更新时间',
+    example: '2024-01-16T14:20:00Z'
+  })
+});
+
+// 创建模板请求Schema
+export const CreateTemplateDto = z.object({
+  title: z.string().min(1, '模板标题不能为空').max(255, '模板标题最多255个字符').openapi({
+    description: '模板标题',
+    example: '项目计划书模板'
+  }),
+  description: z.string().nullable().optional().openapi({
+    description: '模板描述',
+    example: '适用于各类项目管理的标准计划书模板'
+  }),
+  fileId: z.coerce.number().int('必须是整数').positive('必须是正整数').openapi({
+    description: '关联文件ID',
+    example: 1
+  }),
+  category: z.string().min(1, '模板分类不能为空').max(100, '模板分类最多100个字符').openapi({
+    description: '模板分类',
+    example: '项目管理'
+  }),
+  isFree: z.coerce.number().int('必须是整数').min(0, '状态值只能是0或1').max(1, '状态值只能是0或1').default(0).openapi({
+    description: '是否免费:0-收费,1-免费',
+    example: 0
+  })
+});
+
+// 更新模板请求Schema
+export const UpdateTemplateDto = z.object({
+  title: z.string().min(1, '模板标题不能为空').max(255, '模板标题最多255个字符').optional().openapi({
+    description: '模板标题',
+    example: '项目计划书模板(更新版)'
+  }),
+  description: z.string().nullable().optional().openapi({
+    description: '模板描述',
+    example: '适用于各类项目管理的标准计划书模板(修订版)'
+  }),
+  fileId: z.coerce.number().int('必须是整数').positive('必须是正整数').optional().openapi({
+    description: '关联文件ID',
+    example: 2
+  }),
+  category: z.string().min(1, '模板分类不能为空').max(100, '模板分类最多100个字符').optional().openapi({
+    description: '模板分类',
+    example: '项目管理'
+  }),
+  isFree: z.coerce.number().int('必须是整数').min(0, '状态值只能是0或1').max(1, '状态值只能是0或1').optional().openapi({
+    description: '是否免费:0-收费,1-免费',
+    example: 1
+  }),
+  isDisabled: z.coerce.number().int('必须是整数').min(0, '状态值只能是0或1').max(1, '状态值只能是0或1').optional().openapi({
+    description: '是否禁用:0-启用,1-禁用',
+    example: DisabledStatus.ENABLED
+  })
+});