feat(api): standardize REST contracts and auth

This commit is contained in:
2026-07-30 20:38:51 +08:00
parent ae1a657554
commit ba947b616b
86 changed files with 54193 additions and 990 deletions
+17 -27
View File
@@ -23,7 +23,7 @@ from app.services.tjnetwork import (
router = APIRouter()
@router.get("/getcurrentoperationid/", summary="获取当前操作ID", description="获取网络当前的操作ID")
@router.get("/current-operation-ids", summary="获取当前操作ID", description="获取网络当前的操作ID")
async def get_current_operation_id_endpoint(network: str = Query(..., description="管网名称(或数据库名称)")) -> int:
"""
获取当前操作ID
@@ -32,7 +32,7 @@ async def get_current_operation_id_endpoint(network: str = Query(..., descriptio
"""
return get_current_operation(network)
@router.post("/undo/", summary="撤销操作", description="撤销网络上最后的一个操作")
@router.post("/undos", summary="撤销操作", description="撤销网络上最后的一个操作")
async def undo_endpoint(network: str = Query(..., description="管网名称(或数据库名称)")):
"""
撤销操作
@@ -41,7 +41,7 @@ async def undo_endpoint(network: str = Query(..., description="管网名称(
"""
return execute_undo(network)
@router.post("/redo/", summary="重做操作", description="重做网络上被撤销的操作")
@router.post("/redos", summary="重做操作", description="重做网络上被撤销的操作")
async def redo_endpoint(network: str = Query(..., description="管网名称(或数据库名称)")):
"""
重做操作
@@ -50,7 +50,7 @@ async def redo_endpoint(network: str = Query(..., description="管网名称(
"""
return execute_redo(network)
@router.get("/getsnapshots/", summary="获取快照列表", description="获取网络中的所有快照")
@router.get("/snapshots", summary="获取快照列表", description="获取网络中的所有快照")
async def list_snapshot_endpoint(network: str = Query(..., description="管网名称(或数据库名称)")) -> list[tuple[int, str]]:
"""
获取快照列表
@@ -59,7 +59,7 @@ async def list_snapshot_endpoint(network: str = Query(..., description="管网
"""
return list_snapshot(network)
@router.get("/havesnapshot/", summary="检查快照是否存在", description="检查指定标签的快照是否存在")
@router.get("/snapshots/existence", summary="检查快照是否存在", description="检查指定标签的快照是否存在")
async def have_snapshot_endpoint(network: str = Query(..., description="管网名称(或数据库名称)"), tag: str = Query(..., description="快照标签")) -> bool:
"""
检查快照是否存在
@@ -68,7 +68,7 @@ async def have_snapshot_endpoint(network: str = Query(..., description="管网
"""
return have_snapshot(network, tag)
@router.get("/havesnapshotforoperation/", summary="检查操作快照是否存在", description="检查指定操作ID的快照是否存在")
@router.get("/snapshot-for-operations", summary="检查操作快照是否存在", description="检查指定操作ID的快照是否存在")
async def have_snapshot_for_operation_endpoint(network: str = Query(..., description="管网名称(或数据库名称)"), operation: int = Query(..., description="操作ID")) -> bool:
"""
检查操作快照是否存在
@@ -77,7 +77,7 @@ async def have_snapshot_for_operation_endpoint(network: str = Query(..., descrip
"""
return have_snapshot_for_operation(network, operation)
@router.get("/havesnapshotforcurrentoperation/", summary="检查当前操作快照是否存在", description="检查当前操作的快照是否存在")
@router.get("/snapshot-for-current-operations", summary="检查当前操作快照是否存在", description="检查当前操作的快照是否存在")
async def have_snapshot_for_current_operation_endpoint(network: str = Query(..., description="管网名称(或数据库名称)")) -> bool:
"""
检查当前操作快照是否存在
@@ -86,7 +86,7 @@ async def have_snapshot_for_current_operation_endpoint(network: str = Query(...,
"""
return have_snapshot_for_current_operation(network)
@router.post("/takesnapshotforoperation/", summary="为操作创建快照", description="为指定的操作创建快照")
@router.post("/snapshot-for-operations", summary="为操作创建快照", description="为指定的操作创建快照")
async def take_snapshot_for_operation_endpoint(
network: str = Query(..., description="管网名称(或数据库名称)"),
operation: int = Query(..., description="操作ID"),
@@ -99,7 +99,7 @@ async def take_snapshot_for_operation_endpoint(
"""
return take_snapshot_for_operation(network, operation, tag)
@router.post("/takesnapshotforcurrentoperation", summary="为当前操作创建快照", description="为当前操作创建快照")
@router.post("/snapshot-for-current-operations", summary="为当前操作创建快照", description="为当前操作创建快照")
async def take_snapshot_for_current_operation_endpoint(network: str = Query(..., description="管网名称(或数据库名称)"), tag: str = Query(..., description="快照标签")) -> None:
"""
为当前操作创建快照
@@ -108,17 +108,7 @@ async def take_snapshot_for_current_operation_endpoint(network: str = Query(...,
"""
return take_snapshot_for_current_operation(network, tag)
# 兼容旧拼写: takenapshotforcurrentoperation
@router.post("/takenapshotforcurrentoperation", summary="为当前操作创建快照(兼容模式)", description="为当前操作创建快照(兼容旧的API路径)")
async def take_snapshot_for_current_operation_legacy_endpoint(network: str = Query(..., description="管网名称(或数据库名称)"), tag: str = Query(..., description="快照标签")) -> None:
"""
为当前操作创建快照(兼容模式)
兼容旧的API路径,为网络当前操作创建一个快照
"""
return take_snapshot_for_current_operation(network, tag)
@router.post("/takesnapshot/", summary="创建快照", description="为网络创建一个快照")
@router.post("/snapshots", summary="创建快照", description="为网络创建一个快照")
async def take_snapshot_endpoint(network: str = Query(..., description="管网名称(或数据库名称)"), tag: str = Query(..., description="快照标签")) -> None:
"""
创建快照
@@ -127,7 +117,7 @@ async def take_snapshot_endpoint(network: str = Query(..., description="管网
"""
return take_snapshot(network, tag)
@router.post("/picksnapshot/", summary="选择快照", description="选择并恢复到指定的快照", response_model=None)
@router.patch("/snapshots", summary="选择快照", description="选择并恢复到指定的快照", response_model=None)
async def pick_snapshot_endpoint(network: str = Query(..., description="管网名称(或数据库名称)"), tag: str = Query(..., description="快照标签"), discard: bool = Query(False, description="是否丢弃当前更改")) -> ChangeSet:
"""
选择快照
@@ -136,7 +126,7 @@ async def pick_snapshot_endpoint(network: str = Query(..., description="管网
"""
return pick_snapshot(network, tag, discard)
@router.post("/pickoperation/", summary="选择操作", description="选择并恢复到指定的操作", response_model=None)
@router.patch("/operations", summary="选择操作", description="选择并恢复到指定的操作", response_model=None)
async def pick_operation_endpoint(
network: str = Query(..., description="管网名称(或数据库名称)"),
operation: int = Query(..., description="操作ID"),
@@ -149,7 +139,7 @@ async def pick_operation_endpoint(
"""
return pick_operation(network, operation, discard)
@router.get("/syncwithserver/", summary="与服务器同步", description="将网络与服务器同步到指定操作", response_model=None)
@router.post("/with-servers", summary="与服务器同步", description="将网络与服务器同步到指定操作", response_model=None)
async def sync_with_server_endpoint(
network: str = Query(..., description="管网名称(或数据库名称)"),
operation: int = Query(..., description="目标操作ID"),
@@ -162,7 +152,7 @@ async def sync_with_server_endpoint(
"""
return sync_with_server(network, operation)
@router.post("/batch/", summary="执行批量命令", description="执行多个网络操作命令", response_model=None)
@router.post("/network-command-batches", summary="执行批量命令", description="执行多个网络操作命令", response_model=None)
async def execute_batch_commands_endpoint(network: str = Query(..., description="管网名称(或数据库名称)"), req: Request = None) -> ChangeSet:
"""
执行批量命令
@@ -175,7 +165,7 @@ async def execute_batch_commands_endpoint(network: str = Query(..., description=
rcs = execute_batch_commands(network, cs)
return rcs
@router.post("/compressedbatch/", summary="执行压缩批量命令", description="执行压缩的批量命令", response_model=None)
@router.post("/network-command-batches/compressed", summary="执行压缩批量命令", description="执行压缩的批量命令", response_model=None)
async def execute_compressed_batch_commands_endpoint(
network: str = Query(..., description="管网名称(或数据库名称)"),
req: Request = None
@@ -190,7 +180,7 @@ async def execute_compressed_batch_commands_endpoint(
cs.operations = jo_root["operations"]
return execute_batch_command(network, cs)
@router.get("/getrestoreoperation/", summary="获取恢复操作ID", description="获取网络的恢复操作ID")
@router.get("/restore-operations", summary="获取恢复操作ID", description="获取网络的恢复操作ID")
async def get_restore_operation_endpoint(network: str = Query(..., description="管网名称(或数据库名称)")) -> int:
"""
获取恢复操作ID
@@ -199,7 +189,7 @@ async def get_restore_operation_endpoint(network: str = Query(..., description="
"""
return get_restore_operation(network)
@router.post("/setrestoreoperation/", summary="设置恢复操作ID", description="设置网络的恢复操作ID")
@router.patch("/restore-operations", summary="设置恢复操作ID", description="设置网络的恢复操作ID")
async def set_restore_operation_endpoint(network: str = Query(..., description="管网名称(或数据库名称)"), operation: int = Query(..., description="操作ID")) -> None:
"""
设置恢复操作ID