feat: add create person feature via web interface

- Backend: new POST /api/persons endpoint in PersonController
- Frontend: new /persons/new route with Vorname/Nachname/Alias form,
  redirects to the new person's detail page on success
- Persons list: subtle '+ Neue Person' link below the page title

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-03-16 16:23:05 +01:00
parent b583c8489d
commit 0123dffdc4
5 changed files with 323 additions and 112 deletions

View File

@@ -0,0 +1,26 @@
import { fail, redirect } from '@sveltejs/kit';
import { createApiClient } from '$lib/api.server';
export const actions = {
default: async ({ request, fetch }) => {
const formData = await request.formData();
const firstName = formData.get('firstName')?.toString().trim();
const lastName = formData.get('lastName')?.toString().trim();
const alias = formData.get('alias')?.toString().trim() || undefined;
if (!firstName || !lastName) {
return fail(400, { error: 'Vor- und Nachname sind Pflichtfelder.' });
}
const api = createApiClient(fetch);
const result = await api.POST('/api/persons', {
body: { firstName, lastName, ...(alias ? { alias } : {}) }
});
if (!result.response.ok) {
return fail(result.response.status, { error: 'Person konnte nicht gespeichert werden.' });
}
throw redirect(303, `/persons/${result.data!.id}`);
}
};