refactor: 移除审批和回写功能模块 移除了整个审批(approvals)和官方回写(writebacks)功能模块, 包括相关模型、路由、服务和配置项。更新了数据库迁移文件, 删除了相关的审批请求表和官方回写运行表。同时从API路由器中 移除了相应的路由,并调整了安全常量和字段验证器以匹配变更。 ```
56 lines
1.9 KiB
Python
56 lines
1.9 KiB
Python
from fastapi import APIRouter, Depends, HTTPException, Query
|
|
from fastapi import status as http_status
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.core.database import get_db
|
|
from app.core.masking import mask_configured
|
|
from app.core.security import require_api_key
|
|
from app.modules.business.constants import BusinessField, BusinessResponseKey
|
|
from app.modules.business.registry import supported_domain_values
|
|
from app.modules.business.schemas import DomainListRead
|
|
from app.modules.business.service import BusinessService
|
|
|
|
router = APIRouter(dependencies=[Depends(require_api_key)])
|
|
|
|
|
|
@router.get("/domains")
|
|
def list_domains() -> dict[str, list[str]]:
|
|
return {BusinessResponseKey.DOMAINS: supported_domain_values()}
|
|
|
|
|
|
@router.get("/{domain}", response_model=DomainListRead)
|
|
def list_records(
|
|
domain: str,
|
|
limit: int = Query(default=50, ge=1, le=500),
|
|
offset: int = Query(default=0, ge=0),
|
|
status_filter: str | None = Query(default=None, alias=BusinessField.STATUS),
|
|
db: Session = Depends(get_db),
|
|
) -> dict:
|
|
try:
|
|
total, items = BusinessService(db).list_records(domain, limit, offset, status_filter)
|
|
except KeyError as exc:
|
|
raise HTTPException(status_code=http_status.HTTP_404_NOT_FOUND, detail=str(exc)) from exc
|
|
return {
|
|
BusinessResponseKey.DOMAIN: domain,
|
|
BusinessResponseKey.TOTAL: total,
|
|
BusinessResponseKey.ITEMS: mask_configured(items, domain=domain),
|
|
}
|
|
|
|
|
|
@router.get("/{domain}/{record_id}")
|
|
def get_record(
|
|
domain: str,
|
|
record_id: int,
|
|
db: Session = Depends(get_db),
|
|
) -> dict:
|
|
try:
|
|
return {
|
|
BusinessResponseKey.DOMAIN: domain,
|
|
BusinessResponseKey.DATA: mask_configured(
|
|
BusinessService(db).get_record(domain, record_id),
|
|
domain=domain,
|
|
),
|
|
}
|
|
except KeyError as exc:
|
|
raise HTTPException(status_code=http_status.HTTP_404_NOT_FOUND, detail=str(exc)) from exc
|