refactor(relationship): use typed RelationType enum in CreateRelationshipRequest #365
Reference in New Issue
Block a user
Delete Branch "fix/stammbaum-relationtype-enum"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Replace the
String relationTypefield onCreateRelationshipRequestwith the typedRelationTypeenum. Spring's Jackson layer now does the parsing directly; invalid values are caught by theHttpMessageNotReadableException → 400handler added in commit99d00537, which already returns a structuredVALIDATION_ERROR. The manualparseType()helper inRelationshipServiceis therefore redundant and removed.Why
When
99d00537landed (PR #360, "fix(stammbaum): handle HttpMessageNotReadableException → 400 for invalid enum values"), the controller boundary already produced the sameVALIDATION_ERRORresponse 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 aString relationType, but the only acceptable strings areRelationTypeenum names. Letting Jackson deserialize the enum directly makes that contract visible at compile time.Changes
CreateRelationshipRequest.relationType:String→RelationType(annotation@NotBlank→@NotNull).RelationshipService.createRelationship: dropparseType(); usedto.relationType()directly. Helper method removed.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 greenrelationType(e.g."FRIEND_OF") still returns 400 withcode: VALIDATION_ERROR(covered by the existingHttpMessageNotReadableExceptionhandler)🤖 Generated with Claude Code