Skip to content

refactor(api/v1): DRY/SOLID 违约技术债务清理#270

Merged
hrygo merged 8 commits into
mainfrom
refactor/issue-268-api-v1-solid
Feb 20, 2026
Merged

refactor(api/v1): DRY/SOLID 违约技术债务清理#270
hrygo merged 8 commits into
mainfrom
refactor/issue-268-api-v1-solid

Conversation

@hrygo

@hrygo hrygo commented Feb 20, 2026

Copy link
Copy Markdown
Owner

Summary

server/router/api/v1 包进行 DRY/SOLID 原则重构,清理技术债务。

Resolves #268

Changes

Phase 1: SRP 违约修复

  • 拆分 user_service.go:1444 行巨文件拆分为 6 个独立文件

    • user_service_crud.go - 用户 CRUD 操作
    • user_service_settings.go - 用户设置
    • user_service_tokens.go - Token 管理
    • user_service_webhooks.go - Webhook 管理
    • user_service_notifications.go - 通知设置
    • user_service_converter.go - 数据转换器
  • 解耦 APIV1Service God Struct:拆分为独立领域服务

    • user_access.go - 用户访问控制
    • ai_access.go - AI 服务访问检查
    • resource_name.go - 资源名称解析器

Phase 2: DRY 违约清理

  • 提取 requireUserAccessrequireAI:消除 10+ 处重复代码
  • 创建资源名称解析器:统一 resource_name.go 解析逻辑
  • 应用 Field Mapper 模式:重构 ScheduleService.UpdateSchedule 解决 OCP 违约

Phase 3: 测试验证

  • 添加 CC CLI 多路复用验证脚本test_cc_cli_multiplex.py

Test plan

  • go build ./... 编译通过
  • go test ./... 测试通过
  • make check-all 检查通过
  • CC CLI 多路复用功能验证通过

…ervice god struct

Extract authentication utilities into standalone package-level functions
that accept *store.Store as parameter. This is the prerequisite for
extracting individual domain services from the god struct.

Also fixes recursive call bug in requireAI method.
…actors

Replace all hardcoded strings.Split(name, "/") patterns with standardized
resource name extractors. Added compound extractors:
- ExtractUserAndShortcutIDFromName
- ExtractUserAndWebhookIDFromName
- ExtractUserAndSettingKeyFromName
- ExtractUserAndPATIDFromName
- ExtractWebhookIDFromResourceName
…t domain services

1. Extracted 9 dedicated domain struct receivers (UserService, MemoService, etc.)
2. Migrated all pseudo-stub methods (UnimplementedXxx) out of APIV1Service.
3. Repurposed APIV1Service as a pure Gateway and Dependency Injector.
4. Rewired all gRPC Gateway interceptors and Connect service delegators to target domain receivers seamlessly.
5. Standardized common dependencies and decoupled generic filter validator.
6. Cleaned up remaining backward compatibility wrapper functions and staticcheck warnings.
@hrygo hrygo changed the title test: add comprehensive cc cli multiplexing verification script refactor(api/v1): DRY/SOLID 违约技术债务清理 Feb 20, 2026
@hrygo hrygo merged commit 999255e into main Feb 20, 2026
15 of 16 checks passed
@hrygo hrygo deleted the refactor/issue-268-api-v1-solid branch February 20, 2026 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[refactor] server/router/api/v1 包 DRY/SOLID 违约技术债务清理

2 participants