refactor: 重构后端架构,采用 Go 风格四层设计模式
Some checks failed
部署后端服务 / 🧪 测试后端 (push) Failing after 1m37s
部署后端服务 / 🚀 构建并部署 (push) Has been skipped
部署后端服务 / 🔄 回滚部署 (push) Has been skipped

## 主要变更

### 🏗️ 架构重构
- 采用简洁的四层架构:API → Service → Repository → Model
- 遵循 Go 语言最佳实践和命名规范
- 实现依赖注入和接口导向设计
- 统一错误处理和响应格式

### 📁 目录结构优化
- 删除重复模块 (application/, domain/, infrastructure/ 等)
- 规范化命名 (使用 Go 风格的 snake_case)
- 清理无关文件 (package.json, node_modules/ 等)
- 新增规范化的测试目录结构

### 📚 文档系统
- 为每个模块创建详细的 CLAUDE.md 指导文件
- 包含开发规范、最佳实践和使用示例
- 支持模块化开发,缩短上下文长度

### 🔧 开发规范
- 统一接口命名规范 (UserServicer, PhotoRepositoryr)
- 标准化错误处理机制
- 完善的测试策略 (单元测试、集成测试、性能测试)
- 规范化的配置管理

### 🗂️ 新增文件
- cmd/server/ - 服务启动入口和配置
- internal/model/ - 数据模型层 (entity, dto, request)
- pkg/ - 共享工具包 (logger, response, validator)
- tests/ - 完整测试结构
- docs/ - API 文档和架构设计
- .gitignore - Git 忽略文件配置

### 🗑️ 清理内容
- 删除 Node.js 相关文件 (package.json, node_modules/)
- 移除重复的架构目录
- 清理临时文件和构建产物
- 删除重复的文档文件

## 影响
- 提高代码可维护性和可扩展性
- 统一开发规范,提升团队协作效率
- 优化项目结构,符合 Go 语言生态标准
- 完善文档体系,降低上手难度
This commit is contained in:
xujiang
2025-07-10 11:20:59 +08:00
parent 540593f1dc
commit a2f2f66f88
40 changed files with 9682 additions and 1798 deletions

View File

@ -142,7 +142,7 @@ func (r *categoryRepository) GetTree() ([]*models.Category, error) {
// 第一次遍历:建立映射
for _, category := range categories {
categoryMap[category.ID] = category
category.Children = []*models.Category{}
category.Children = []models.Category{}
}
// 第二次遍历:构建树形结构
@ -151,7 +151,7 @@ func (r *categoryRepository) GetTree() ([]*models.Category, error) {
rootCategories = append(rootCategories, category)
} else {
if parent, exists := categoryMap[*category.ParentID]; exists {
parent.Children = append(parent.Children, category)
parent.Children = append(parent.Children, *category)
}
}
}
@ -177,9 +177,11 @@ func (r *categoryRepository) GetStats() (*models.CategoryStats, error) {
var stats models.CategoryStats
// 总分类数
if err := r.db.Model(&models.Category{}).Count(&stats.TotalCategories).Error; err != nil {
var totalCount int64
if err := r.db.Model(&models.Category{}).Count(&totalCount).Error; err != nil {
return nil, fmt.Errorf("failed to count total categories: %w", err)
}
stats.TotalCategories = int(totalCount)
// 计算最大层级
// 这里简化处理,实际应用中可能需要递归查询