Move error responses to API routers.

This commit is contained in:
grossmj committed 2021-04-13 16:19:56 +09:30
1 parent 6b0d0de1bc
commit a9eb035b7d
18 files changed
+263 -487

No files matched your search

+6 -10
View File
@@ -30,12 +30,12 @@ from gns3server.controller.project import Project
from gns3server import schemas
from gns3server.controller import Controller
router = APIRouter()
responses = {
404: {"model": schemas.ErrorMessage, "description": "Could not find project or snapshot"}
}
router = APIRouter(responses=responses)
def dep_project(project_id: UUID):
"""
@@ -48,8 +48,7 @@ def dep_project(project_id: UUID):
@router.post("",
status_code=status.HTTP_201_CREATED,
response_model=schemas.Snapshot,
responses=responses)
response_model=schemas.Snapshot)
async def create_snapshot(snapshot_data: schemas.SnapshotCreate, project: Project = Depends(dep_project)):
"""
Create a new snapshot of a project.
@@ -61,8 +60,7 @@ async def create_snapshot(snapshot_data: schemas.SnapshotCreate, project: Projec
@router.get("",
response_model=List[schemas.Snapshot],
response_model_exclude_unset=True,
responses=responses)
response_model_exclude_unset=True)
def get_snapshots(project: Project = Depends(dep_project)):
"""
Return all snapshots belonging to a given project.
@@ -73,8 +71,7 @@ def get_snapshots(project: Project = Depends(dep_project)):
@router.delete("/{snapshot_id}",
status_code=status.HTTP_204_NO_CONTENT,
responses=responses)
status_code=status.HTTP_204_NO_CONTENT)
async def delete_snapshot(snapshot_id: UUID, project: Project = Depends(dep_project)):
"""
Delete a snapshot.
@@ -85,8 +82,7 @@ async def delete_snapshot(snapshot_id: UUID, project: Project = Depends(dep_proj
@router.post("/{snapshot_id}/restore",
status_code=status.HTTP_201_CREATED,
response_model=schemas.Project,
responses=responses)
response_model=schemas.Project)
async def restore_snapshot(snapshot_id: UUID, project: Project = Depends(dep_project)):
"""
Restore a snapshot.