From 2332ec58d51c7a729523c28e519f988d07f2b59e Mon Sep 17 00:00:00 2001 From: vidane Date: Sat, 2 May 2026 18:03:41 -0400 Subject: [PATCH] Add src/app/api/kanban/route.ts --- src/app/api/kanban/route.ts | 57 +++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/app/api/kanban/route.ts diff --git a/src/app/api/kanban/route.ts b/src/app/api/kanban/route.ts new file mode 100644 index 0000000..55cfdbb --- /dev/null +++ b/src/app/api/kanban/route.ts @@ -0,0 +1,57 @@ +import { NextRequest, NextResponse } from 'next/server'; +import { getDb } from '@/server/db'; +import { tasks, projects } from '@/server/db/schema'; +import { eq, isNull, and } from 'drizzle-orm'; + +export async function GET(request: NextRequest) { + const db = getDb(); + const { searchParams } = new URL(request.url); + const projectId = searchParams.get('project'); + + try { + let whereCondition; + + if (projectId) { + whereCondition = and( + eq(tasks.projectId, projectId), + isNull(tasks.parentTaskId) // Only top-level tasks + ); + } else { + whereCondition = isNull(tasks.parentTaskId); + } + + // Get all tasks (not subtasks) + const allTasks = await db + .select({ + id: tasks.id, + projectId: tasks.projectId, + title: tasks.title, + description: tasks.description, + completed: tasks.completed, + priority: tasks.priority, + dueDate: tasks.dueDate, + status: tasks.status, + sortOrder: tasks.sortOrder, + recurrenceRule: tasks.recurrenceRule, + recurrenceInterval: tasks.recurrenceInterval, + projectColor: projects.color, + projectName: projects.name, + }) + .from(tasks) + .leftJoin(projects, eq(tasks.projectId, projects.id)) + .where(whereCondition) + .orderBy(tasks.sortOrder); + + // Group by status + const grouped = { + todo: allTasks.filter(t => t.status === 'todo'), + in_progress: allTasks.filter(t => t.status === 'in_progress'), + done: allTasks.filter(t => t.status === 'done'), + }; + + return NextResponse.json(grouped); + } catch (error) { + console.error('Error fetching kanban data:', error); + return NextResponse.json({ error: 'Failed to fetch kanban data' }, { status: 500 }); + } +}