|
1 | | -from fastapi import APIRouter, Depends, status |
| 1 | +from fastapi import APIRouter, Depends, HTTPException, status |
2 | 2 | from sqlalchemy.ext.asyncio import AsyncSession |
3 | 3 |
|
4 | 4 | from api.core.database import get_session |
|
7 | 7 | from api.src.workspaces.repository import WorkspaceRepository |
8 | 8 | from api.src.workspaces.schemas import ( |
9 | 9 | WorkspaceCreate, |
| 10 | + WorkspaceLongQuestBase, |
10 | 11 | WorkspaceResponse, |
11 | 12 | WorkspaceUpdate, |
12 | 13 | ) |
@@ -98,3 +99,64 @@ async def delete_workspace( |
98 | 99 | except Exception as e: |
99 | 100 | logger.error(f"Failed to delete workspace {workspace_id}: {str(e)}") |
100 | 101 | raise |
| 102 | + |
| 103 | + |
| 104 | +@router.get("/{workspace_id}/quests/long", response_model=WorkspaceResponse) |
| 105 | +async def get_long_quest( |
| 106 | + workspace_id: int, |
| 107 | + service: WorkspaceService = Depends(get_workspace_service), |
| 108 | + current_user: UserInfo = Depends(validate_token), |
| 109 | +) -> WorkspaceLongQuestBase | None: |
| 110 | + try: |
| 111 | + workspace = await service.get_workspace( |
| 112 | + current_user.projectGroups, workspace_id |
| 113 | + ) |
| 114 | + return workspace.longFormQuestDef |
| 115 | + except Exception as e: |
| 116 | + logger.error(f"Failed to fetch workspace {workspace_id}: {str(e)}") |
| 117 | + raise |
| 118 | + |
| 119 | + |
| 120 | +@router.get("/{workspace_id}/quests/long/settings", response_model=WorkspaceLongQuestBase) |
| 121 | +async def get_long_quest_settings( |
| 122 | + workspace_id: int, |
| 123 | + service: WorkspaceService = Depends(get_workspace_service), |
| 124 | + current_user: UserInfo = Depends(validate_token), |
| 125 | +) -> WorkspaceLongQuestBase | None: |
| 126 | + try: |
| 127 | + workspace = await service.get_workspace( |
| 128 | + current_user.projectGroups, workspace_id |
| 129 | + ) |
| 130 | + |
| 131 | + if(workspace.longFormQuestDef is None): |
| 132 | + raise HTTPException( |
| 133 | + status_code=status.HTTP_204_NO_CONTENT, |
| 134 | + detail="No Content", |
| 135 | + ) |
| 136 | + |
| 137 | + return workspace.longFormQuestDef |
| 138 | + except Exception as e: |
| 139 | + logger.error(f"Failed to fetch workspace {workspace_id}: {str(e)}") |
| 140 | + raise |
| 141 | + |
| 142 | +@router.patch("/{workspace_id}/quests/long/settings", response_model=WorkspaceLongQuestBase) |
| 143 | +async def update_long_quest_settings( |
| 144 | + workspace_id: int, |
| 145 | + workspace_data: WorkspaceUpdate, |
| 146 | + service: WorkspaceService = Depends(get_workspace_service), |
| 147 | + current_user: UserInfo = Depends(validate_token), |
| 148 | +) -> WorkspaceLongQuestBase | None: |
| 149 | + try: |
| 150 | + workspace:WorkspaceUpdate = await service.get_workspace( |
| 151 | + current_user.projectGroups, workspace_id |
| 152 | + ) # type: ignore |
| 153 | + |
| 154 | +# workspace.longFormQuestDef = longform_quest_data |
| 155 | + |
| 156 | + updatedWorkspace = await service.update_workspace( |
| 157 | + current_user.projectGroups, workspace_id, workspace |
| 158 | + ) |
| 159 | + return updatedWorkspace.longFormQuestDef |
| 160 | + except Exception as e: |
| 161 | + logger.error(f"Failed to update workspace {workspace_id}: {str(e)}") |
| 162 | + raise |
0 commit comments