modify my task
This commit is contained in:
@@ -286,6 +286,88 @@ async def get_tasks(
|
||||
raise HTTPException(status_code=500, detail=f"Error fetching tasks: {str(e)}")
|
||||
|
||||
|
||||
@router.get("/my-tasks", response_model=List[TaskListResponse])
|
||||
async def get_my_tasks(
|
||||
project_id: Optional[int] = Query(None, description="Filter by project ID"),
|
||||
status: Optional[str] = Query(None, description="Filter by task status"),
|
||||
skip: int = Query(0, ge=0),
|
||||
limit: int = Query(100, ge=1, le=1000),
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""
|
||||
Get all tasks assigned to the current user across all projects.
|
||||
This endpoint is designed for the My Tasks page.
|
||||
"""
|
||||
try:
|
||||
# Build query to get tasks assigned to current user
|
||||
query = db.query(Task).options(
|
||||
joinedload(Task.project),
|
||||
joinedload(Task.episode),
|
||||
joinedload(Task.shot),
|
||||
joinedload(Task.asset),
|
||||
joinedload(Task.assigned_user)
|
||||
)
|
||||
|
||||
# Always filter by assignee (current user)
|
||||
query = query.filter(Task.assigned_user_id == current_user.id)
|
||||
|
||||
# Exclude soft-deleted tasks and tasks from deleted parents
|
||||
query = query.outerjoin(Shot, Task.shot_id == Shot.id).outerjoin(Asset, Task.asset_id == Asset.id)
|
||||
query = query.filter(
|
||||
Task.deleted_at.is_(None),
|
||||
or_(
|
||||
and_(Task.shot_id.is_(None), Task.asset_id.is_(None)), # Tasks without shot/asset
|
||||
and_(Task.shot_id.isnot(None), Shot.deleted_at.is_(None)), # Tasks with non-deleted shot
|
||||
and_(Task.asset_id.isnot(None), Asset.deleted_at.is_(None)) # Tasks with non-deleted asset
|
||||
)
|
||||
)
|
||||
|
||||
# Filter by project if provided
|
||||
if project_id:
|
||||
query = query.filter(Task.project_id == project_id)
|
||||
|
||||
# Filter by status if provided
|
||||
if status:
|
||||
query = query.filter(Task.status == status)
|
||||
|
||||
# Apply pagination
|
||||
query = query.order_by(Task.deadline.asc().nullslast(), Task.updated_at.desc())
|
||||
tasks = query.offset(skip).limit(limit).all()
|
||||
|
||||
# Build response
|
||||
result = []
|
||||
for task in tasks:
|
||||
result.append(TaskListResponse(
|
||||
id=task.id,
|
||||
name=task.name,
|
||||
task_type=task.task_type,
|
||||
status=task.status,
|
||||
deadline=task.deadline,
|
||||
project_id=task.project_id,
|
||||
project_name=task.project.name if task.project else "Unknown",
|
||||
episode_id=task.episode_id,
|
||||
episode_name=task.episode.name if task.episode else None,
|
||||
shot_id=task.shot_id,
|
||||
shot_name=task.shot.name if task.shot else None,
|
||||
asset_id=task.asset_id,
|
||||
asset_name=task.asset.name if task.asset else None,
|
||||
assigned_user_id=task.assigned_user_id,
|
||||
assigned_user_name=f"{task.assigned_user.first_name} {task.assigned_user.last_name}" if task.assigned_user else None,
|
||||
created_at=task.created_at,
|
||||
updated_at=task.updated_at
|
||||
))
|
||||
|
||||
return result
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
import traceback
|
||||
print(f"ERROR in get_my_tasks: {str(e)}")
|
||||
print(traceback.format_exc())
|
||||
raise HTTPException(status_code=500, detail=f"Error fetching my tasks: {str(e)}")
|
||||
|
||||
|
||||
@router.post("/", response_model=TaskResponse)
|
||||
async def create_task(
|
||||
task: TaskCreate,
|
||||
|
||||
Reference in New Issue
Block a user