refactor(relationship): use typed RelationType enum in CreateRelationshipRequest #365

Merged
marcel merged 1 commits from fix/stammbaum-relationtype-enum into main 2026-04-28 19:59:45 +02:00
Owner

Summary

Replace the String relationType field on CreateRelationshipRequest with the typed RelationType enum. Spring's Jackson layer now does the parsing directly; invalid values are caught by the HttpMessageNotReadableException → 400 handler added in commit 99d00537, which already returns a structured VALIDATION_ERROR. The manual parseType() helper in RelationshipService is therefore redundant and removed.

Why

When 99d00537 landed (PR #360, "fix(stammbaum): handle HttpMessageNotReadableException → 400 for invalid enum values"), the controller boundary already produced the same VALIDATION_ERROR response for malformed enum input. The string-then-parse path in the DTO + service was duplicate validation that obscured the contract: the DTO claims it accepts a String relationType, but the only acceptable strings are RelationType enum names. Letting Jackson deserialize the enum directly makes that contract visible at compile time.

Changes

  • CreateRelationshipRequest.relationType: StringRelationType (annotation @NotBlank@NotNull).
  • RelationshipService.createRelationship: drop parseType(); use dto.relationType() directly. Helper method removed.
  • Tests updated to pass the enum value (RelationType.PARENT_OF, etc.) where they previously passed strings.

Net: 29 insertions / 38 deletions across 5 files (DTO + service + 3 test files).

Test plan

  • ./mvnw test -Dtest='RelationshipServiceTest,RelationshipServiceIntegrationTest,RelationshipControllerTest' — 28 / 28 green
  • CI pipeline green
  • Spot-check on a running backend that POSTing with an invalid relationType (e.g. "FRIEND_OF") still returns 400 with code: VALIDATION_ERROR (covered by the existing HttpMessageNotReadableException handler)

🤖 Generated with Claude Code

## Summary Replace the `String relationType` field on `CreateRelationshipRequest` with the typed `RelationType` enum. Spring's Jackson layer now does the parsing directly; invalid values are caught by the `HttpMessageNotReadableException → 400` handler added in commit `99d00537`, which already returns a structured `VALIDATION_ERROR`. The manual `parseType()` helper in `RelationshipService` is therefore redundant and removed. ## Why When `99d00537` landed (PR #360, "fix(stammbaum): handle HttpMessageNotReadableException → 400 for invalid enum values"), the controller boundary already produced the same `VALIDATION_ERROR` response for malformed enum input. The string-then-parse path in the DTO + service was duplicate validation that obscured the contract: the DTO claims it accepts a `String relationType`, but the only acceptable strings are `RelationType` enum names. Letting Jackson deserialize the enum directly makes that contract visible at compile time. ## Changes - `CreateRelationshipRequest.relationType`: `String` → `RelationType` (annotation `@NotBlank` → `@NotNull`). - `RelationshipService.createRelationship`: drop `parseType()`; use `dto.relationType()` directly. Helper method removed. - Tests updated to pass the enum value (`RelationType.PARENT_OF`, etc.) where they previously passed strings. Net: 29 insertions / 38 deletions across 5 files (DTO + service + 3 test files). ## Test plan - [x] `./mvnw test -Dtest='RelationshipServiceTest,RelationshipServiceIntegrationTest,RelationshipControllerTest'` — 28 / 28 green - [ ] CI pipeline green - [ ] Spot-check on a running backend that POSTing with an invalid `relationType` (e.g. `"FRIEND_OF"`) still returns 400 with `code: VALIDATION_ERROR` (covered by the existing `HttpMessageNotReadableException` handler) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
marcel added 1 commit 2026-04-28 19:57:43 +02:00
refactor(relationship): use typed RelationType enum in CreateRelationshipRequest
Some checks failed
CI / Unit & Component Tests (pull_request) Failing after 3m2s
CI / OCR Service Tests (pull_request) Successful in 36s
CI / Backend Unit Tests (pull_request) Failing after 3m13s
CI / Unit & Component Tests (push) Failing after 3m7s
CI / OCR Service Tests (push) Successful in 34s
CI / Backend Unit Tests (push) Failing after 3m6s
5d82a3e471
Spring deserializes the enum directly; invalid values are caught by the
HttpMessageNotReadableException → 400 handler added in 99d00537, returning
a structured VALIDATION_ERROR. The manual parseType() helper is therefore
redundant and removed. Tests updated to construct requests with the enum.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
marcel merged commit 5d82a3e471 into main 2026-04-28 19:59:45 +02:00
marcel deleted branch fix/stammbaum-relationtype-enum 2026-04-28 19:59:46 +02:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: marcel/familienarchiv#365