Replace title mutation API routes with server actions

Move all title page mutations (status, rating, movie watch, episode
watch/unwatch, season watch/unwatch) from API route handlers to server
actions called directly from TitleInteractionProvider. Same optimistic
update pattern, no behavioral change — just eliminates the fetch()
round-trip through 5 API routes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-02 15:47:04 -05:00
co-authored by Claude Opus 4.6
parent c1867a4f23
commit f16ccc2f3f
7 changed files with 92 additions and 211 deletions
-30
View File
@@ -1,30 +0,0 @@
import { headers } from "next/headers";
import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
import { auth } from "@/lib/auth/server";
import { rateTitleStars } from "@/lib/services/tracking";
export async function POST(
req: NextRequest,
{ params }: { params: Promise<{ id: string }> },
) {
const session = await auth.api.getSession({
headers: await headers(),
});
if (!session)
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
const { id } = await params;
const body = await req.json();
const { ratingStars } = body;
if (typeof ratingStars !== "number" || ratingStars < 0 || ratingStars > 5) {
return NextResponse.json(
{ error: "ratingStars must be 0-5" },
{ status: 400 },
);
}
await rateTitleStars(session.user.id, id, ratingStars);
return NextResponse.json({ ok: true });
}
-47
View File
@@ -1,47 +0,0 @@
import { headers } from "next/headers";
import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
import { auth } from "@/lib/auth/server";
import {
getUserTitleInfo,
removeTitleStatus,
setTitleStatus,
} from "@/lib/services/tracking";
export async function GET(
_req: NextRequest,
{ params }: { params: Promise<{ id: string }> },
) {
const session = await auth.api.getSession({
headers: await headers(),
});
if (!session)
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
const { id } = await params;
const info = await getUserTitleInfo(session.user.id, id);
return NextResponse.json(info);
}
export async function POST(
req: NextRequest,
{ params }: { params: Promise<{ id: string }> },
) {
const session = await auth.api.getSession({
headers: await headers(),
});
if (!session)
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
const { id } = await params;
const body = await req.json();
const { status } = body;
if (status === null || status === undefined) {
await removeTitleStatus(session.user.id, id);
} else {
await setTitleStatus(session.user.id, id, status);
}
return NextResponse.json({ ok: true });
}