- Add PostgreSQL service to docker-compose with health checks
- Add migrate service that runs prisma migrate deploy on startup
- Integrate Prisma client in worker: checks for existing generations
(same repo+commit) before regenerating, writes to Postgres on completion
- Update /api/docs/[id] with Redis → PostgreSQL fallback + cache repopulation
- Update Dockerfile: prisma generate in build, copy Prisma engine to worker/web
- Add @codeboard/database dependency to web and worker packages
- Add initial SQL migration for Generation and User tables
- Change removeOnComplete to { age: 3600 } for job retention
43 lines
927 B
TypeScript
43 lines
927 B
TypeScript
import { NextResponse } from "next/server";
|
|
import { getRedis } from "@/lib/redis";
|
|
import { prisma } from "@codeboard/database";
|
|
|
|
export async function GET(
|
|
_request: Request,
|
|
{ params }: { params: Promise<{ id: string }> }
|
|
) {
|
|
const { id } = await params;
|
|
const redis = getRedis();
|
|
|
|
let result = await redis.get(`codeboard:result:${id}`);
|
|
|
|
if (result) {
|
|
return NextResponse.json(JSON.parse(result));
|
|
}
|
|
|
|
const generation = await prisma.generation.findFirst({
|
|
where: { id }
|
|
});
|
|
|
|
if (!generation || !generation.result) {
|
|
return NextResponse.json(
|
|
{ error: "Documentation not found" },
|
|
{ status: 404 }
|
|
);
|
|
}
|
|
|
|
const docs = generation.result as any;
|
|
docs.id = id;
|
|
docs.repoUrl = generation.repoUrl;
|
|
docs.repoName = generation.repoName;
|
|
|
|
await redis.set(
|
|
`codeboard:result:${id}`,
|
|
JSON.stringify(docs),
|
|
"EX",
|
|
86400
|
|
);
|
|
|
|
return NextResponse.json(docs);
|
|
}
|