feat(confidence-engine): add authenticated investigation persistence
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import { loadInvestigation } from "@/lib/storage/server-investigation-persistence.js";
|
||||
import { withAuthenticatedApi } from "@/lib/supabase/api-auth.js";
|
||||
|
||||
async function get(_request, { params }) {
|
||||
try {
|
||||
const snapshot = await loadInvestigation(params.id);
|
||||
if (!snapshot) return Response.json({ error: "Investigation not found" }, { status: 404 });
|
||||
return Response.json({ snapshot });
|
||||
} catch {
|
||||
return Response.json({ error: "Investigation persistence request failed" }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
export const GET = withAuthenticatedApi(get);
|
||||
@@ -0,0 +1,29 @@
|
||||
import {
|
||||
listInvestigations,
|
||||
saveInvestigation,
|
||||
} from "@/lib/storage/server-investigation-persistence.js";
|
||||
import { withAuthenticatedApi } from "@/lib/supabase/api-auth.js";
|
||||
|
||||
async function get() {
|
||||
try {
|
||||
return Response.json({ investigations: await listInvestigations() });
|
||||
} catch {
|
||||
return Response.json({ error: "Investigation persistence request failed" }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
async function post(request) {
|
||||
try {
|
||||
const { id, snapshot } = await request.json();
|
||||
if (!id || !snapshot || typeof snapshot !== "object") {
|
||||
return Response.json({ error: "An investigation id and snapshot are required" }, { status: 400 });
|
||||
}
|
||||
const savedSnapshot = await saveInvestigation(snapshot, id);
|
||||
return Response.json({ snapshot: savedSnapshot }, { status: 200 });
|
||||
} catch {
|
||||
return Response.json({ error: "Investigation persistence request failed" }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
export const GET = withAuthenticatedApi(get);
|
||||
export const POST = withAuthenticatedApi(post);
|
||||
Reference in New Issue
Block a user