Forráskód Böngészése

📝 docs(entity): 更新实体创建流程文档

- 添加"注册实体到数据源"步骤,明确在data-source.ts中注册新实体的要求
- 调整后续步骤编号,确保流程顺序正确
- 更新标准CRUD和自定义实体创建两种场景的步骤编号和内容对应关系
yourname 5 hónapja
szülő
commit
5297de0a8f
1 módosított fájl, 39 hozzáadás és 9 törlés
  1. 39 9
      .roo/rules/11-entity-creation.md

+ 39 - 9
.roo/rules/11-entity-creation.md

@@ -21,7 +21,22 @@
    - 参考已有实体文件如`user.entity.ts`
    - 注意: 必须包含Zod Schema定义
 
-### 2. **创建Service**
+### 2. **注册实体到数据源**
+   - 在`src/server/data-source.ts`中添加实体导入和注册:
+     ```typescript
+     // 实体类导入
+     import { YourEntity } from "./modules/[模块名]/[实体名].entity"
+     
+     export const AppDataSource = new DataSource({
+       // ...其他配置
+       entities: [
+         User, Role, YourEntity // 添加新实体到数组
+       ],
+       // ...其他配置
+     });
+     ```
+
+### 3. **创建Service**
    - 位置: `src/server/modules/[模块名]/[实体名].service.ts`
    - 继承`GenericCrudService`
    - 通过构造函数注入DataSource
@@ -37,7 +52,7 @@
    }
    ```
 
-### 3. **创建API路由**
+### 4. **创建API路由**
    - 使用`createCrudRoutes`快速生成CRUD路由:
      ```typescript
      import { createCrudRoutes } from '@/server/utils/generic-crud.routes';
@@ -58,7 +73,7 @@
      export default yourEntityRoutes;
      ```
 
-### 4. **注册路由**
+### 5. **注册路由**
    - 在`src/server/api.ts`中添加路由注册:
      ```typescript
      import yourEntityRoutes from '@/server/api/your-entity/index';
@@ -67,7 +82,7 @@
      api.route('/api/v1/your-entities', yourEntityRoutes);
      ```
 
-### 5. **创建客户端API**
+### 6. **创建客户端API**
    - 在`src/client/api.ts`中添加客户端定义:
      ```typescript
      import { hc } from 'hono/client';
@@ -129,7 +144,22 @@
      });
      ```
 
-### 2. **创建自定义Service**
+### 2. **注册实体到数据源**
+   - 在`src/server/data-source.ts`中添加实体导入和注册:
+     ```typescript
+     // 实体类导入
+     import { YourEntity } from "./modules/[模块名]/[实体名].entity"
+     
+     export const AppDataSource = new DataSource({
+       // ...其他配置
+       entities: [
+         User, Role, YourEntity // 添加新实体到数组
+       ],
+       // ...其他配置
+     });
+     ```
+
+### 3. **创建自定义Service**
    - 位置: `src/server/modules/[模块名]/[实体名].service.ts`
    - 实现自定义业务逻辑和数据访问
    - 示例:
@@ -231,7 +261,7 @@
      }
      ```
 
-### 3. **创建自定义API路由**
+### 4. **创建自定义API路由**
    - 目录结构:
      ```
      src/server/api/[实体名]/
@@ -406,7 +436,7 @@
      export default app;
      ```
 
-### 4. **注册路由**
+### 5. **注册路由**
    - 在`src/server/api.ts`中添加路由注册:
      ```typescript
      import yourEntityRoutes from '@/server/api/your-entity/index';
@@ -415,7 +445,7 @@
      api.route('/api/v1/your-entities', yourEntityRoutes);
      ```
 
-### 5. **创建客户端API**
+### 6. **创建客户端API**
    - 在`src/client/api.ts`中添加客户端定义:
      ```typescript
      import { hc } from 'hono/client';
@@ -451,7 +481,7 @@
      export type DeleteYourEntityResponse = InferResponseType<typeof yourEntityClient[':id']['$delete'], 200>;
      ```
 
-### 6. **前端调用示例**
+### 7. **前端调用示例**
    - 在页面组件中使用客户端API:
      ```typescript
      import { yourEntityClient, type YourEntityListResponse } from '@/client/api';