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:
2026-07-25 19:34:02 +02:00
co-authored by Claude Opus 5
parent 9ea6bb8d36
commit 7690bc87c5
10 changed files with 521 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
import { NextResponse } from "next/server";
import { prisma } from "@/lib/db";
import { projectDetailInclude } from "@/lib/projects";
import { syncProject } from "@/lib/sync";
export const dynamic = "force-dynamic";
type Params = { params: Promise<{ id: string }> };
/** Holt Branches, Tags, Commits und Releases beim Git-System ab. */
export async function POST(_request: Request, { params }: Params) {
const { id } = await params;
const result = await syncProject(id);
const project = await prisma.project.findUnique({
where: { id },
include: projectDetailInclude,
});
return NextResponse.json({ ...result, project }, { status: result.ok ? 200 : 502 });
}