Skip to content

Commit

Permalink
feat: Filter pending tasks by state in function
Browse files Browse the repository at this point in the history
  • Loading branch information
Pradip-p committed Jul 25, 2024
1 parent aaec573 commit 11db42b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/backend/app/projects/project_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async def create_project_with_project_info(
"status": ProjectStatus.DRAFT.name,
"visibility": project_metadata.visibility.name,
"outline": str(project_metadata.outline),
"no_fly_zones": str(project_metadata.no_fly_zones),
"no_fly_zones": str(project_metadata.no_fly_zones) if project_metadata.no_fly_zones is not None else None,
"dem_url": project_metadata.dem_url,
"output_orthophoto_url": project_metadata.output_orthophoto_url,
"output_pointcloud_url": project_metadata.output_pointcloud_url,
Expand Down
15 changes: 15 additions & 0 deletions src/backend/app/tasks/task_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,18 @@ async def get_requested_user_id(
if result is None:
raise ValueError("No user requested for mapping")
return result["user_id"]



async def get_project_task_by_id(db: Database, project_id: uuid.UUID):
"""Get all tasks associated with a specific project by project_id."""
raw_sql = """
SELECT t.id AS task_id, te.event_id, te.user_id, te.comment, te.state, te.created_at
FROM tasks t
LEFT JOIN task_events te ON t.id = te.task_id
WHERE t.project_id = :project_id
ORDER BY t.project_task_index;
"""
db_tasks = await db.fetch_all(raw_sql, {"project_id": project_id})

return db_tasks
18 changes: 17 additions & 1 deletion src/backend/app/tasks/task_routes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import uuid
from fastapi import APIRouter, BackgroundTasks, Depends
from fastapi import APIRouter, BackgroundTasks, Depends, HTTPException
from app.config import settings
from app.models.enums import EventType, State
from app.tasks import task_schemas, task_crud
Expand Down Expand Up @@ -140,3 +140,19 @@ async def new_event(
)

return True



@router.get("/requested_tasks/{project_id}/pending")
async def get_pending_tasks(
project_id: uuid.UUID,
user_data: AuthUser = Depends(login_required),
db: Database = Depends(database.encode_db),
):
"""Get a list of pending tasks for a specific project and user."""
# Ensure that the user is authorized to view tasks for the project
pending_tasks = await task_crud.get_project_task_by_id(db, project_id)
if pending_tasks is None:
raise HTTPException(status_code=404, detail="Project not found")
# Fetch the pending tasks for the project
return pending_tasks

0 comments on commit 11db42b

Please sign in to comment.