Commit Graph

12 Commits

Author SHA1 Message Date
longgexx
c27d511736 test(billing): 更新测试用例以验证透支策略 2026-01-05 19:03:54 +08:00
longgexx
d6f8ac0226 fix(billing): 修复计费漏洞
- 允许余额透支策略

   ## 问题
   - 扣费失败时只记录日志,不阻止请求完成
   - 用户可以用极少余额无限次免费使用服务
   - 数据库层使用 BalanceGTE 条件防止余额变负,导致余额不足时扣费失败

   ## 修复
   - 移除 DeductBalance 方法中的 BalanceGTE 条件,允许余额变为负数
   - 修改错误返回:用户不存在时返回 ErrUserNotFound
   - 实现透支策略:余额不足时允许本次请求完成,余额变负后阻止后续请求

   ## 测试
   - 更新 TestDeductBalance_InsufficientFunds 测试,验证透支功能
   - 更新 TestDeductBalance_NotFound 测试,验证正确的错误类型
   - 新增 TestDeductBalance_AllowsOverdraft 测试,专门测试透支场景
   - 所有测试通过 
2026-01-05 18:48:49 +08:00
Edric Li
759291db02 fix: update integration tests for UserListFilters
Update user_repo_integration_test.go to use the new UserListFilters
struct instead of individual parameters for ListWithFilters calls.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 19:13:58 +08:00
Edric Li
404bf0f8d2 refactor: migrate wechat to user attributes and enhance users list
Migrate the hardcoded wechat field to the new extensible user
attributes system and improve the users management UI.

Migration:
- Add migration 019 to move wechat data to user_attribute_values
- Remove wechat field from User entity, DTOs, and API contracts
- Clean up wechat-related code from backend and frontend

UsersView enhancements:
- Add text labels to action buttons (Filter Settings, Column Settings,
  Attributes Config) for better UX
- Change status column to show colored dot + Chinese text instead of
  English text
- Add dynamic attribute columns support with batch loading
- Add column visibility settings with localStorage persistence
- Add filter settings modal for search and filter preferences
- Update i18n translations

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 18:59:38 +08:00
yangjianbo
679b21a86c Merge branch 'main' into test
冲突解决:
- wire_gen.go: 合并 antigravityGatewayService 和 ProvideConcurrencyCache
- user_repo_integration_test.go: 保留 NotFound 测试
- antigravity_gateway_service.go: 适配 httpUpstream.Do 新签名

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-31 14:17:18 +08:00
yangjianbo
5906f9ab98 fix(数据层): 修复数据完整性与仓储一致性问题
## 数据完整性修复 (fix-critical-data-integrity)
- 添加 error_translate.go 统一错误转换层
- 修复 nil 输入和 NotFound 错误处理
- 增强仓储层错误一致性

## 仓储一致性修复 (fix-high-repository-consistency)
- Group schema 添加 default_validity_days 字段
- Account schema 添加 proxy edge 关联
- 新增 UsageLog ent schema 定义
- 修复 UpdateBalance/UpdateConcurrency 受影响行数校验

## 数据卫生修复 (fix-medium-data-hygiene)
- UserSubscription 添加软删除支持 (SoftDeleteMixin)
- RedeemCode/Setting 添加硬删除策略文档
- account_groups/user_allowed_groups 的 created_at 声明 timestamptz
- 停止写入 legacy users.allowed_groups 列
- 新增迁移: 011-014 (索引优化、软删除、孤立数据审计、列清理)

## 测试补充
- 添加 UserSubscription 软删除测试
- 添加迁移回归测试
- 添加 NotFound 错误测试

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-31 14:11:57 +08:00
shaw
3d296d8898 style: 修复 gofmt 格式化问题
格式化以下测试文件以符合 Go 代码风格规范:
- fixtures_integration_test.go
- user_repo_integration_test.go
- api_key_service_delete_test.go
2025-12-30 17:08:36 +08:00
yangjianbo
ae191f72a4 fix(仓储): 修复软删除过滤与事务测试
修复软删除拦截器使用错误,确保默认查询过滤已删记录
仓储层改用 ent.Tx 与扫描辅助,避免 sql.Tx 断言问题
同步更新集成测试以覆盖事务与统计变动
2025-12-29 19:23:49 +08:00
yangjianbo
3d617de577 refactor(数据库): 迁移持久层到 Ent 并清理 GORM
将仓储层/基础设施改为 Ent + 原生 SQL 执行路径,并移除 AutoMigrate 与 GORM 依赖。
重构内容包括:
- 仓储层改用 Ent/SQL(含 usage_log/account 等复杂查询),统一错误映射
- 基础设施与 setup 初始化切换为 Ent + SQL migrations
- 集成测试与 fixtures 迁移到 Ent 事务模型
- 清理遗留 GORM 模型/依赖,补充迁移与文档说明
- 增加根目录 Makefile 便于前后端编译

测试:
- go test -tags unit ./...
- go test -tags integration ./...
2025-12-29 10:03:27 +08:00
Forest
e5a77853b0 refactor: 调整项目结构为单向依赖 2025-12-26 16:45:40 +08:00
Forest
eeaff85e47 refactor: 自定义业务错误 2025-12-25 21:06:40 +08:00
Forest
25a304c231 test: 增加 repository 测试 2025-12-25 16:01:17 +08:00