Agent turn complete
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
"""Task management routes for the kanban board."""
|
||||
|
||||
from typing import Optional
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.database import get_db
|
||||
from app.models import Task
|
||||
from app.schemas import TaskCreate, TaskUpdate, TaskResponse, TaskListResponse
|
||||
|
||||
router = APIRouter(prefix="/tasks", tags=["tasks"])
|
||||
|
||||
|
||||
@router.post("", response_model=TaskResponse)
|
||||
def create_task(task: TaskCreate, db: Session = Depends(get_db)):
|
||||
"""Create a new task."""
|
||||
db_task = Task(**task.model_dump())
|
||||
db.add(db_task)
|
||||
db.commit()
|
||||
db.refresh(db_task)
|
||||
return db_task
|
||||
|
||||
|
||||
@router.get("", response_model=TaskListResponse)
|
||||
def list_tasks(
|
||||
status: Optional[str] = Query(None),
|
||||
priority: Optional[str] = Query(None),
|
||||
tags: Optional[str] = Query(None),
|
||||
search: Optional[str] = Query(None),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""List tasks with optional filtering."""
|
||||
query = db.query(Task)
|
||||
|
||||
# Filter by status
|
||||
if status:
|
||||
query = query.filter(Task.status == status)
|
||||
|
||||
# Filter by priority
|
||||
if priority:
|
||||
query = query.filter(Task.priority == priority)
|
||||
|
||||
# Filter by tags (partial match)
|
||||
if tags:
|
||||
query = query.filter(Task.tags.ilike(f"%{tags}%"))
|
||||
|
||||
# Search in title and description
|
||||
if search:
|
||||
query = query.filter(
|
||||
(Task.title.ilike(f"%{search}%")) | (Task.description.ilike(f"%{search}%"))
|
||||
)
|
||||
|
||||
tasks = query.order_by(Task.created_at.desc()).all()
|
||||
return TaskListResponse(tasks=tasks, total=len(tasks))
|
||||
|
||||
|
||||
@router.get("/{task_id}", response_model=TaskResponse)
|
||||
def get_task(task_id: int, db: Session = Depends(get_db)):
|
||||
"""Get a specific task by ID."""
|
||||
task = db.query(Task).filter(Task.id == task_id).first()
|
||||
if not task:
|
||||
raise HTTPException(status_code=404, detail="Task not found")
|
||||
return task
|
||||
|
||||
|
||||
@router.put("/{task_id}", response_model=TaskResponse)
|
||||
def update_task(task_id: int, task_update: TaskUpdate, db: Session = Depends(get_db)):
|
||||
"""Update a task."""
|
||||
task = db.query(Task).filter(Task.id == task_id).first()
|
||||
if not task:
|
||||
raise HTTPException(status_code=404, detail="Task not found")
|
||||
|
||||
# Update only provided fields
|
||||
update_data = task_update.model_dump(exclude_unset=True)
|
||||
for field, value in update_data.items():
|
||||
setattr(task, field, value)
|
||||
|
||||
db.commit()
|
||||
db.refresh(task)
|
||||
return task
|
||||
|
||||
|
||||
@router.delete("/{task_id}")
|
||||
def delete_task(task_id: int, db: Session = Depends(get_db)):
|
||||
"""Delete a task."""
|
||||
task = db.query(Task).filter(Task.id == task_id).first()
|
||||
if not task:
|
||||
raise HTTPException(status_code=404, detail="Task not found")
|
||||
|
||||
db.delete(task)
|
||||
db.commit()
|
||||
return {"message": "Task deleted successfully"}
|
||||
Reference in New Issue
Block a user