Story 005.006: Advertisements Module
Status
Draft
Story
As a 小程序开发者,
I want 将广告管理模块从 packages/server/src 拆分到主项目的 packages 目录下作为独立 package,
so that 项目可以按需引入广告管理功能,保持模块独立性和向后兼容性
Acceptance Criteria
- 创建
@d8d/advertisements-module package,包含完整的广告类型和广告管理功能
- 从 packages/server/src/modules/advertisements 迁移广告服务代码
- 实现广告类型和广告实体的完整CRUD功能
- 提供完整的 TypeScript 类型定义和 API 文档
- 集成到现有的文件管理系统(图片文件关联)
- 保持与现有认证系统的兼容性
- 提供单元测试和集成测试,覆盖率满足要求
- 更新 server package 依赖关系,支持按需引入
Tasks / Subtasks
[ ] Task 1: 创建 advertisements-module package 基础结构 (AC: 1, 2)
[ ] Task 2: 迁移广告实体和服务代码 (AC: 2, 3)
[ ] Task 3: 创建广告 API 路由 (AC: 3, 4)
[ ] Task 4: 集成文件管理系统 (AC: 5)
[ ] Task 5: 迁移和实现测试套件 (AC: 7)
[ ] Task 6: 更新 server package 依赖 (AC: 8)
Dev Notes
技术栈信息
- 后端框架: Hono 4.8.5 [Source: architecture/tech-stack.md#现有技术栈维护]
- 数据库: PostgreSQL 17 + TypeORM 0.3.25 [Source: architecture/tech-stack.md#现有技术栈维护]
- 认证: JWT Bearer Token [Source: architecture/api-design-integration.md#API集成策略]
- 文件存储: MinIO + file-module [Source: architecture/source-tree.md#实际项目结构]
项目结构
- 包位置:
packages/advertisements-module/ [Source: architecture/source-tree.md#实际项目结构]
- 代码结构: 遵循现有模块化包模式 [Source: architecture/source-tree.md#包架构层次]
- 依赖层次: advertisements-module → file-module → auth-module → user-module → shared-crud → shared-utils → shared-types [Source: docs/prd/epic-005-mini-auth-modules-integration.md#依赖层次]
广告功能详情
- 广告实体: Advertisement 实体包含标题、类型、调用别名、URL、图片文件、排序、状态等字段 [Source: packages/server/src/modules/advertisements/advertisement.entity.ts:1-125]
- 广告类型实体: AdvertisementType 实体包含类型名称、调用别名、备注、状态等字段 [Source: packages/server/src/modules/advertisements/advertisement-type.entity.ts:1-72]
- 服务层: 使用 GenericCrudService 提供标准CRUD操作 [Source: packages/server/src/modules/advertisements/advertisement.service.ts:1-9]
- API路由: 使用通用CRUD路由生成器创建标准API [Source: packages/server/src/api/advertisements/index.ts:1-21]
实体设计
Advertisement 实体字段:
id: 主键ID
title: 广告标题 (varchar(30))
typeId: 广告类型ID
code: 调用别名 (varchar(20))
url: 跳转URL (varchar(255))
imageFileId: 图片文件ID
sort: 排序字段
status: 状态字段
actionType: 跳转类型 (0不跳转, 1webview, 2小程序页面)
createdBy, updatedBy: 用户跟踪字段
AdvertisementType 实体字段:
id: 主键ID
name: 类型名称 (varchar(50))
code: 调用别名 (varchar(20))
remark: 备注 (varchar(100))
status: 状态 (0禁用, 1启用)
createdBy, updatedBy: 用户跟踪字段
集成点
- 认证集成: 使用 auth-module 的认证中间件 [Source: packages/auth-module/src/middleware/auth.middleware.ts:1]
- 文件集成: 依赖 file-module 获取图片文件信息 [Source: packages/server/src/modules/advertisements/advertisement.entity.ts:2]
- 数据库: 使用现有 TypeORM 数据源 [Source: architecture/source-tree.md:74]
- API 设计: 遵循现有 RESTful API 模式 [Source: architecture/api-design-integration.md#API集成策略]
环境配置要求
- 数据库表: 需要 ad 和 ad_type 表 [Source: packages/server/src/modules/advertisements/advertisement.entity.ts:5]
- 文件存储: 需要配置 MinIO 存储桶 [Source: architecture/source-tree.md:248]
Testing
测试标准
- 测试框架: Vitest 3.2.4 [Source: architecture/testing-strategy.md#工具版本]
- 测试位置:
packages/advertisements-module/tests/ [Source: architecture/testing-strategy.md#包测试架构]
- 测试类型: 单元测试 + 集成测试 [Source: architecture/testing-strategy.md#包测试架构]
- 覆盖率要求: 单元测试 ≥ 80%,集成测试 ≥ 60% [Source: architecture/testing-strategy.md#各层覆盖率要求]
测试模式
- 集成测试: 测试广告路由与认证集成 [Source: architecture/testing-strategy.md#集成测试]
- 测试工具: 使用 shared-test-util 基础设施 [Source: architecture/testing-strategy.md#包测试架构]
测试套件用法(参考 auth-module 模式)
- 测试框架: Vitest + Hono Testing Client [Source: packages/auth-module/tests/integration/phone-decrypt.integration.test.ts:1-2]
- 数据库钩子: 使用
setupIntegrationDatabaseHooksWithEntities [Source: packages/auth-module/tests/integration/phone-decrypt.integration.test.ts:31]
- 测试客户端: 使用
testClient 创建路由测试客户端 [Source: packages/auth-module/tests/integration/phone-decrypt.integration.test.ts:41]
- 数据源获取: 使用
IntegrationTestDatabase.getDataSource() [Source: packages/auth-module/tests/integration/phone-decrypt.integration.test.ts:44]
关键测试场景
- 广告创建和更新参数验证
- 广告类型管理功能测试
- 图片文件关联测试
- 认证和权限验证测试
- 错误处理和异常场景测试
Change Log
| Date |
Version |
Description |
Author |
| 2025-11-11 |
1.0 |
创建广告管理模块故事文档 |
Bob (Scrum Master) |
Dev Agent Record
Agent Model Used
- This section will be populated by the development agent
Debug Log References
- This section will be populated by the development agent
Completion Notes List
- This section will be populated by the development agent
File List
- This section will be populated by the development agent
QA Results
Results from QA Agent QA review of the completed story implementation