bmad 架构师工作

This commit is contained in:
2025-11-01 23:29:42 +08:00
parent 6f7e462589
commit 548d3eae00
4 changed files with 206 additions and 5 deletions

View File

@@ -0,0 +1,72 @@
# Story: 为删除操作添加使用状态检查
Status: Draft
## Story
As a 开发者,
I want 在删除设备、设备模板和区域主控时,系统能自动检查它们是否处于被使用状态,
so that 避免误删除正在使用的关键数据,确保系统数据完整性和稳定性.
## Acceptance Criteria
* **单元测试:**
* 针对 `device_service.go``device_template_service.go``region_service.go` 中的检查逻辑编写单元测试。
* 模拟有依赖和无依赖的场景,验证删除操作的行为。
* **集成测试:**
* 编写 API 集成测试,模拟删除设备、设备模板和区域主控的请求。
* 测试在有依赖和无依赖情况下的 API 响应HTTP 状态码和错误信息)。
* 同时,验证数据库中的数据状态是否符合预期(例如,被依赖的实体未被删除)。
* **手动测试:**
* 在开发环境中,手动创建依赖关系,然后尝试删除被使用的实体,验证系统行为。
* 手动创建无依赖的实体,验证可以正常删除。
## Tasks / Subtasks
* 定位删除逻辑:找到 `device_service.go``device_template_service.go``region_service.go` 中对应的删除方法。
* 添加依赖检查函数:在每个删除方法内部或其调用的辅助函数中,实现检查逻辑。
* 集成错误处理:在检查失败时,返回自定义错误或使用现有错误处理机制。
* 编写单元测试:为新的检查逻辑编写单元测试,覆盖删除成功和删除失败(因被使用)的场景。
* 编写集成测试:编写集成测试,模拟删除操作,验证端到端的行为。
## Dev Notes
### Technical Summary
在删除设备、设备模板和区域主控的 API 接口和业务逻辑层中,引入使用状态检查。
识别依赖关系,实现检查逻辑,返回明确的错误信息,阻止删除操作。
确保检查和删除操作的原子性。
使用 Echo 框架和 PostgreSQL with TimescaleDB。
### Project Structure Notes
- Files to modify: internal/app/controller/device_controller.go, internal/app/controller/device_template_controller.go, internal/app/controller/region_controller.go, internal/app/service/device_service.go, internal/app/service/device_template_service.go, internal/app/service/region_service.go, internal/infra/repository/device_repository.go, internal/infra/repository/device_template_repository.go, internal/infra/repository/region_repository.go
- Expected test locations: internal/app/service/device_service_test.go (假设), internal/app/service/device_template_service_test.go (假设), internal/app/service/region_service_test.go (假设), API 集成测试文件 (假设)
- Estimated effort: 2 story points (2 天)
### References
- **Tech Spec:** See tech-spec.md for detailed implementation
- **Architecture:** tech-spec.md
## Dev Agent Record
### Context Reference
<!-- Path(s) to story context XML will be added here by context workflow -->
### Agent Model Used
<!-- Will be populated during dev-story execution -->
### Debug Log References
<!-- Will be populated during dev-story execution -->
### Completion Notes List
<!-- Will be populated during dev-story execution -->
### File List
<!-- Will be populated during dev-story execution -->