refactor(backend): 迁移基础设施,core,拆分models

This commit is contained in:
sophie committed 2026-06-25 14:01:52 +08:00
1 parent b89d93d738
commit 053ea392f2
61 files changed
+3329 -3268

No files matched your search

+11 -3
View File
@@ -1,5 +1,10 @@
#!/usr/bin/env python3
"""Codemod: jsonify({'error': ...}) -> raise AppError subclasses."""
"""
backend/scripts/migrate_jsonify_errors.py
用途:将 API 层 return jsonify({'error': ...}), 4xx 批量改写为 raise AppError 子类。
逻辑:AST 扫描 api/**/*.py;注入 from app.core.errors import ...;运行后需人工检查 _require_user 等 helper。
"""
from __future__ import annotations
@@ -8,10 +13,13 @@ import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1] / "app"
TARGETS = [ROOT / "decorators.py", *sorted((ROOT / "api").glob("*.py"))]
TARGETS = [
ROOT / "decorators.py",
*sorted(ROOT.glob("api/**/*.py")),
]
IMPORT_LINE = (
"from app.errors import AppError, ValidationError, UnauthorizedError, "
"from app.core.errors import AppError, ValidationError, UnauthorizedError, "
"ForbiddenError, NotFoundError, ConflictError, ServiceUnavailableError, raise_for_status"
)