feat(api): REST-Endpunkte fuer Projekte, Notizen, Verbindungen und Sync
Alles, was die Oberflaeche kann, ist damit auch scriptbar: GET POST /api/projects GET PATCH DELETE /api/projects/:id POST /api/projects/:id/sync GET POST /api/projects/:id/notes PATCH DELETE /api/notes/:id GET POST /api/connections PATCH DELETE /api/connections/:id POST /api/connections/:id/check GET /api/connections/:id/repos GET /api/health Details: - Jede Eingabe laeuft durch Zod; Feldfehler kommen als Objekt zurueck, damit Formulare sie direkt anzeigen koennen. - Beim Anlegen werden Owner und Repo-Name aus der URL abgeleitet, falls nicht explizit angegeben. - Ein leeres Token-Feld beim Bearbeiten einer Verbindung laesst das gespeicherte Token unveraendert; null entfernt es. - Verbindungsantworten enthalten nie das Chiffrat, nur einen Hinweis wie "ghp_...9f3a". - /api/health prueft die Datenbank und dient dem Docker-Healthcheck. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib/db";
|
||||
import { clientForConnection } from "@/lib/git";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
type Params = { params: Promise<{ id: string }> };
|
||||
|
||||
/** Testet Erreichbarkeit und Token einer Verbindung und merkt sich das Ergebnis. */
|
||||
export async function POST(_request: Request, { params }: Params) {
|
||||
const { id } = await params;
|
||||
|
||||
const connection = await prisma.gitConnection.findUnique({ where: { id } });
|
||||
if (!connection) {
|
||||
return NextResponse.json({ error: "Verbindung nicht gefunden" }, { status: 404 });
|
||||
}
|
||||
|
||||
const result = await clientForConnection(connection).check();
|
||||
|
||||
await prisma.gitConnection.update({
|
||||
where: { id },
|
||||
data: {
|
||||
lastCheckedAt: new Date(),
|
||||
lastCheckOk: result.ok,
|
||||
lastCheckMessage: result.message,
|
||||
username: result.user ?? connection.username,
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json(result, { status: result.ok ? 200 : 502 });
|
||||
}
|
||||
Reference in New Issue
Block a user