feat(relationship): editable relationships with LocalDate+DatePrecision dates and notes (#841)
All checks were successful
CI / Unit & Component Tests (push) Successful in 5m10s
CI / OCR Service Tests (push) Successful in 24s
CI / Backend Unit Tests (push) Successful in 5m14s
CI / fail2ban Regex (push) Successful in 50s
CI / Semgrep Security Scan (push) Successful in 27s
CI / Compose Bucket Idempotency (push) Successful in 1m5s
All checks were successful
CI / Unit & Component Tests (push) Successful in 5m10s
CI / OCR Service Tests (push) Successful in 24s
CI / Backend Unit Tests (push) Successful in 5m14s
CI / fail2ban Regex (push) Successful in 50s
CI / Semgrep Security Scan (push) Successful in 27s
CI / Compose Bucket Idempotency (push) Successful in 1m5s
Closes #837 Makes `PersonRelationship` fully editable (type, related person, dates, notes), migrates its dates from `Integer fromYear/toYear` to `LocalDate + DatePrecision` (mirroring the #773 person pattern, ADR-039 / V76), activates the previously-dead `notes` column, and gives the Zeitstrahl's derived **Heirat** events full date precision for free. Both Open Decisions confirmed as adopted: **no `@Version`** (last-write-wins, single-writer archive) and **`DELETE` ownership-mismatch aligned 403 → 404** (anti-enumeration, matching the new `PUT`). ## What's in it - **V78** migrates `person_relationships.from_year/to_year` → `from_date`/`to_date` + NOT-NULL `*_date_precision` (default `UNKNOWN`); pre-check abort on corrupt years, `YYYY-01-01`/`YEAR` backfill, 5 named CHECK constraints, year columns dropped. - **`PUT /api/persons/{id}/relationships/{relId}`** (`@RequirePermission(WRITE_ALL)`) re-runs every create invariant (self / coherence / order / reverse-PARENT_OF / duplicate) and re-flags family membership; orientation preserved per viewpoint. - New `ErrorCode.INVALID_RELATIONSHIP_DATES` registered in all four sites (§3.6). - `TimelineEventService` sources the derived marriage date from `SPOUSE_OF.fromDate` + precision. - Frontend: `RelationshipDateField` (DAY/MONTH/YEAR), upsert-capable `AddRelationshipForm` (pre-fill + notes + in-flight submit lock), `RelationshipChip` Edit affordance, `updateRelationship` server action, read-view date range + notes, `formatRelationshipDateRange` helper. `api.ts` regenerated. - Docs: ADR-044, db-orm/db-relationships diagrams, DEPLOYMENT §5 deploy note, RTM REQ-001…REQ-019. ## Requirements All 19 EARS requirements implemented red/green and marked `Done` in `.specify/rtm.md`. ## Test plan - **Backend** (targeted, green): `RelationshipMigrationTest` (Testcontainers pg16, 8), `RelationshipServiceTest` (22), `RelationshipControllerTest` (15), `RelationshipServiceIntegrationTest` (real DB, 10), `DerivedEventsAssemblyTest` (17), `ArchitectureTest` (14); `clean package` builds. - **Frontend** (green): `relationshipDates.spec.ts`, `AddRelationshipForm.svelte.spec.ts`, `RelationshipChip.svelte.spec.ts`, `PersonRelationshipsCard.svelte.test.ts`, `page.server.spec.ts`, `messages.spec.ts`. `npm run check` = 798 (below the ~834 baseline); `npm run lint` clean. ## Notes for reviewers - **Spec deviation:** the edit form was built by making `AddRelationshipForm` upsert-capable rather than a duplicate `EditRelationshipForm` (DRY); RTM rows reference `AddRelationshipForm.svelte.spec.ts`. - `api.ts` regenerated from the live spec; only relationship-relevant hunks remain (one springdoc `PageableObject` field-reorder pruned). - **Deploy:** V78 is one-way and not rolling-deploy-safe — stop old JAR → start new JAR (Flyway runs first); targeted `pg_restore -t person_relationships` for rollback. No maintenance window. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Marcel <marcel@familienarchiv> Reviewed-on: #841
This commit was merged in pull request #841.
This commit is contained in:
@@ -10,6 +10,7 @@ export type ErrorCode =
|
||||
| 'INVALID_PERSON_TYPE'
|
||||
| 'BIRTH_AFTER_DEATH'
|
||||
| 'INVALID_DATE_PRECISION'
|
||||
| 'INVALID_RELATIONSHIP_DATES'
|
||||
| 'INVALID_DATE_RANGE'
|
||||
| 'DOCUMENT_NOT_FOUND'
|
||||
| 'DOCUMENT_NO_FILE'
|
||||
@@ -106,6 +107,8 @@ export function getErrorMessage(code: ErrorCode | string | undefined): string {
|
||||
return m.error_birth_after_death();
|
||||
case 'INVALID_DATE_PRECISION':
|
||||
return m.error_invalid_date_precision();
|
||||
case 'INVALID_RELATIONSHIP_DATES':
|
||||
return m.error_invalid_relationship_dates();
|
||||
case 'INVALID_DATE_RANGE':
|
||||
return m.error_invalid_date_range();
|
||||
case 'DOCUMENT_NOT_FOUND':
|
||||
|
||||
106
frontend/src/lib/shared/primitives/DateInputWithPrecision.svelte
Normal file
106
frontend/src/lib/shared/primitives/DateInputWithPrecision.svelte
Normal file
@@ -0,0 +1,106 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import DateInput from '$lib/shared/primitives/DateInput.svelte';
|
||||
import type { DatePrecision } from '$lib/shared/utils/documentDate';
|
||||
|
||||
/**
|
||||
* Compact date + precision field: the {@link DateInput} primitive paired with a
|
||||
* precision <select> offering a caller-chosen subset of precisions. Shared base of
|
||||
* PersonLifeDateField (birth/death) and RelationshipDateField (from/to).
|
||||
*
|
||||
* Distinct from {@link DatePrecisionField} — that one is the full document/timeline
|
||||
* field (all seven precisions, German free-text entry, RANGE end-date disclosure).
|
||||
* This one is the restricted, single-input variant for the person-family forms.
|
||||
*
|
||||
* All copy (legend, precision labels, hint, the select's accessible name) and the
|
||||
* offered precisions are injected by the caller so this stays domain-agnostic.
|
||||
*/
|
||||
let {
|
||||
name,
|
||||
legend,
|
||||
precisionLabel,
|
||||
hint,
|
||||
precisions,
|
||||
initialIso = '',
|
||||
initialPrecision = null,
|
||||
inputClass = '',
|
||||
selectClass = ''
|
||||
}: {
|
||||
name: string;
|
||||
legend: string;
|
||||
precisionLabel: string;
|
||||
hint: string;
|
||||
precisions: { value: DatePrecision; label: string }[];
|
||||
initialIso?: string | null;
|
||||
initialPrecision?: string | null;
|
||||
inputClass?: string;
|
||||
selectClass?: string;
|
||||
} = $props();
|
||||
|
||||
let iso = $state('');
|
||||
let errorMessage = $state<string | null>(null);
|
||||
let inputEl = $state<HTMLInputElement | undefined>();
|
||||
let precision = $state<DatePrecision>('DAY');
|
||||
|
||||
// Seed once at mount so a later load() rerun does not stomp an in-progress edit.
|
||||
onMount(() => {
|
||||
if (initialIso) {
|
||||
iso = initialIso;
|
||||
}
|
||||
const offered = precisions.some((p) => p.value === initialPrecision);
|
||||
if (offered) {
|
||||
precision = initialPrecision as DatePrecision;
|
||||
} else if (initialIso) {
|
||||
// A stored non-offered precision (SEASON/RANGE/APPROX) seeds as YEAR so an
|
||||
// untouched save does not silently claim DAY precision for the stored date.
|
||||
precision = 'YEAR';
|
||||
}
|
||||
});
|
||||
|
||||
// A partial date leaves the hidden ISO empty — block native submission until the
|
||||
// date is completed or fully emptied, so a save can never silently clear a date.
|
||||
$effect(() => {
|
||||
inputEl?.setCustomValidity(errorMessage ?? '');
|
||||
});
|
||||
|
||||
const controlCls =
|
||||
'block min-h-[44px] w-full rounded border border-line px-3 py-2 font-serif text-ink focus:outline-none focus-visible:ring-2 focus-visible:ring-focus-ring';
|
||||
</script>
|
||||
|
||||
<fieldset>
|
||||
<legend class="mb-1 block text-xs font-bold tracking-widest text-ink-3 uppercase">
|
||||
{legend}
|
||||
</legend>
|
||||
<div class="flex flex-col gap-2 sm:flex-row">
|
||||
<div class="flex-1">
|
||||
<DateInput
|
||||
bind:value={iso}
|
||||
bind:errorMessage={errorMessage}
|
||||
bind:inputEl={inputEl}
|
||||
name={name}
|
||||
id={name}
|
||||
placeholder="TT.MM.JJJJ"
|
||||
ariaLabel={legend}
|
||||
ariaDescribedby={errorMessage ? `${name}-error` : undefined}
|
||||
class="{controlCls} {inputClass}"
|
||||
/>
|
||||
{#if errorMessage}
|
||||
<p id="{name}-error" class="mt-1 font-sans text-xs text-red-600">{errorMessage}</p>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="flex-1">
|
||||
<select
|
||||
id="{name}Precision"
|
||||
name="{name}Precision"
|
||||
aria-label="{legend}: {precisionLabel}"
|
||||
bind:value={precision}
|
||||
class="{controlCls} {selectClass}"
|
||||
>
|
||||
{#each precisions as p (p.value)}
|
||||
<option value={p.value}>{p.label}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<p class="mt-1 font-sans text-xs text-ink-3">{hint}</p>
|
||||
</fieldset>
|
||||
@@ -66,6 +66,27 @@ export function formatDocumentDate(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats one nullable date at the precision the data claims, delegating all
|
||||
* rendering to {@link formatDocumentDate}. Returns '' for a missing date; a
|
||||
* missing precision falls back to YEAR — pre-precision rows knew only a year,
|
||||
* and a bare year is the only safe rendering without precision metadata.
|
||||
*
|
||||
* This is the shared core of {@link formatLifeDate} (person birth/death) and the
|
||||
* relationship from/to formatter. Range-level glyphs and dashes belong in those
|
||||
* domain wrappers, never here.
|
||||
*/
|
||||
export function formatDatePart(
|
||||
date: string | null | undefined,
|
||||
precision: DatePrecision | null | undefined,
|
||||
locale?: string
|
||||
): string {
|
||||
if (!date) {
|
||||
return '';
|
||||
}
|
||||
return formatDocumentDate(date, precision ?? 'YEAR', null, null, locale);
|
||||
}
|
||||
|
||||
// ─── precision branches ──────────────────────────────────────────────────────
|
||||
|
||||
function longDate(iso: string, locale: string): string {
|
||||
|
||||
Reference in New Issue
Block a user