Selaa lähdekoodia

Merge remote-tracking branch 'upstream/shadcn-ui' into file-shadcn

yourname 3 kuukautta sitten
vanhempi
sitoutus
043c515531
3 muutettua tiedostoa jossa 17 lisäystä ja 7 poistoa
  1. 1 1
      .roo/rules/10-entity.md
  2. 10 2
      .roo/rules/11-custom-crud.md
  3. 6 4
      .roo/rules/12-generic-crud.md

+ 1 - 1
.roo/rules/10-entity.md

@@ -28,7 +28,6 @@
 
 ```typescript
 import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm';
-import { z } from '@hono/zod-openapi';
 
 @Entity('table_name') // 使用小写下划线命名表名
 export class EntityName {
@@ -107,6 +106,7 @@ updatedAt!: Date;
 ### 7.1 基础类型规范
 
 ```typescript
+import { z } from '@hono/zod-openapi';
 export const EntitySchema = z.object({
   id: z.number().int().positive().openapi({ description: 'ID说明' }),
   // 字符串字段

+ 10 - 2
.roo/rules/11-custom-crud.md

@@ -12,11 +12,10 @@
 
 ### 1. **创建实体**
    - 位置: `src/server/modules/[模块名]/[实体名].entity.ts`
-   - 定义实体类和Zod Schema
+   - 定义实体类
    - 示例:
      ```typescript
      import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm';
-     import { z } from '@hono/zod-openapi';
      
      @Entity('your_entity')
      export class YourEntity {
@@ -28,6 +27,14 @@
        
        // 其他业务字段...
      }
+     ```
+
+
+   - 位置: `src/server/modules/[模块名]/[实体名].schema.ts`
+   - 定义实体Zod Schema
+   - 示例:
+     ```typescript
+     import { z } from '@hono/zod-openapi';
      
      // Zod Schema定义
      export const YourEntitySchema = z.object({
@@ -47,6 +54,7 @@
      });
      ```
 
+
 ### 2. **注册实体到数据源**
    - 在`src/server/data-source.ts`中添加实体导入和注册:
      ```typescript

+ 6 - 4
.roo/rules/12-generic-crud.md

@@ -63,7 +63,7 @@ constructor() {
 ```typescript
 import { createCrudRoutes } from '@/server/utils/generic-crud.routes';
 import { YourEntity } from '@/server/modules/your-module/your-entity.entity';
-import { YourEntitySchema, CreateYourEntityDto, UpdateYourEntityDto } from '@/server/modules/your-module/your-entity.entity';
+import { YourEntitySchema, CreateYourEntityDto, UpdateYourEntityDto } from '@/server/modules/your-module/your-entity.schema';
 import { authMiddleware } from '@/server/middleware/auth.middleware';
 
 const yourEntityRoutes = createCrudRoutes({
@@ -133,7 +133,6 @@ api.route('/api/v1/your-entities', yourEntityRoutes);
 ```typescript
 // your-entity.entity.ts
 import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, OneToMany } from 'typeorm';
-import { z } from '@hono/zod-openapi';
 import { RelatedEntity } from './related-entity.entity';
 
 @Entity('your_entity')
@@ -150,6 +149,8 @@ export class YourEntity {
   // 其他字段...
 }
 
+// your-entity.schema.ts
+import { z } from '@hono/zod-openapi';
 // Zod schemas
 export const YourEntitySchema = z.object({
   id: z.number().int().positive().openapi({ description: '实体ID' }),
@@ -179,7 +180,8 @@ export const UpdateYourEntityDto = z.object({
 
 ```typescript
 import { createCrudRoutes } from '@/server/utils/generic-crud.routes';
-import { PolicyNews, PolicyNewsSchema, CreatePolicyNewsDto, UpdatePolicyNewsDto } from '@/server/modules/silver-users/policy-news.entity';
+import { PolicyNews } from '@/server/modules/silver-users/policy-news.entity';
+import { PolicyNewsSchema, CreatePolicyNewsDto, UpdatePolicyNewsDto } from '@/server/modules/silver-users/policy-news.schema';
 import { File } from '@/server/modules/files/file.entity';
 import { authMiddleware } from '@/server/middleware/auth.middleware';
 
@@ -350,4 +352,4 @@ export class YourEntityService extends GenericCrudService<YourEntity> {
 5. **搜索优化**:合理设置`searchFields`,避免在大表的文本字段上进行模糊搜索
 6. **分页处理**:所有列表接口必须支持分页,避免返回大量数据
 7. **关联查询**:使用`relations`配置时,避免过度关联导致性能问题
-8. **事务管理**:复杂操作应使用事务确保数据一致性
+8. **事务管理**:复杂操作应使用事务确保数据一致性