Agent turn complete
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
"""Route barrel — every router the app serves is mounted here.
|
||||
|
||||
Adding a resource is two steps: create ``app/routes/<name>.py`` with a
|
||||
module-level ``router``, then append one ``include_router`` line below. A route
|
||||
file that is never mounted 404s silently.
|
||||
"""
|
||||
|
||||
from fastapi import APIRouter
|
||||
|
||||
from app.routes import health, items, tasks
|
||||
|
||||
api_router = APIRouter()
|
||||
|
||||
api_router.include_router(health.router, tags=["health"])
|
||||
api_router.include_router(items.router, tags=["items"])
|
||||
api_router.include_router(tasks.router)
|
||||
@@ -0,0 +1,15 @@
|
||||
"""Liveness endpoint. The shape every other route module copies."""
|
||||
|
||||
from fastapi import APIRouter
|
||||
from pydantic import BaseModel
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
class Health(BaseModel):
|
||||
status: str
|
||||
|
||||
|
||||
@router.get("/health", response_model=Health)
|
||||
def health() -> Health:
|
||||
return Health(status="ok")
|
||||
@@ -0,0 +1,21 @@
|
||||
"""One demo resource. Its rows mirror the frontend seed, so Preview and the
|
||||
deployed app render the same screen. Replace both together."""
|
||||
|
||||
from fastapi import APIRouter
|
||||
from pydantic import BaseModel
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
class Item(BaseModel):
|
||||
id: int
|
||||
name: str
|
||||
status: str
|
||||
|
||||
|
||||
@router.get("/items", response_model=list[Item])
|
||||
def list_items() -> list[Item]:
|
||||
return [
|
||||
Item(id=1, name="Draft the launch checklist", status="in progress"),
|
||||
Item(id=2, name="Review onboarding copy", status="todo"),
|
||||
]
|
||||
@@ -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