feat: api v1 routes for calendar lists and notes

This commit is contained in:
ginnoir
2026-07-04 19:03:08 -05:00
parent ea5d1d050c
commit d4304b005c
25 changed files with 1141 additions and 236 deletions
+33
View File
@@ -0,0 +1,33 @@
import { apiJson, withApiHandler } from "@/lib/api-handler";
import { deleteCalendarForScope, updateCalendarForScope } from "@/modules/calendar/server/actions";
import { calendarUpdateInput } from "@/modules/calendar/server/schemas";
import { getCalendarForScope } from "@/modules/calendar/server/queries";
import { z } from "zod";
export async function GET(request: Request, { params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
return withApiHandler(request, async (scope) => {
const calendar = await getCalendarForScope(scope, id);
return apiJson(calendar);
});
}
export async function PATCH(request: Request, { params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
return withApiHandler(request, async (scope, req) => {
const body: unknown = await req.json();
const parsed = calendarUpdateInput.parse(body);
await updateCalendarForScope(scope, { id, ...parsed });
const calendar = await getCalendarForScope(scope, id);
return apiJson(calendar);
});
}
export async function DELETE(request: Request, { params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
return withApiHandler(request, async (scope) => {
z.string().uuid().parse(id);
await deleteCalendarForScope(scope, { id });
return apiJson({ ok: true });
});
}
+29
View File
@@ -0,0 +1,29 @@
import { apiJson, withApiHandler } from "@/lib/api-handler";
import { createCalendarForScope } from "@/modules/calendar/server/actions";
import { calendarInput } from "@/modules/calendar/server/schemas";
import { listCalendarsForScope } from "@/modules/calendar/server/queries";
export async function GET(request: Request) {
return withApiHandler(request, async (scope) => {
const calendars = await listCalendarsForScope(scope);
return apiJson(calendars);
});
}
export async function POST(request: Request) {
return withApiHandler(request, async (scope, req) => {
const body: unknown = await req.json();
const parsed = calendarInput.parse(body);
const calendar = await createCalendarForScope(scope, parsed);
return apiJson(
{
id: calendar.id,
name: calendar.name,
color: calendar.color,
visibility: calendar.visibility as "private" | "household",
ownerId: calendar.ownerId,
},
201,
);
});
}