fix(api): add input validation to PersonNameAliasDTO
Adds @NotBlank @Size(max=255) on lastName, @NotNull on type, @Valid on controller parameter. Blank/null input now returns 400 instead of reaching the DB constraint. 2 new controller tests. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -104,7 +104,7 @@ public class PersonController {
|
||||
|
||||
@PostMapping("/{id}/aliases")
|
||||
@RequirePermission(Permission.WRITE_ALL)
|
||||
public PersonNameAlias addAlias(@PathVariable UUID id, @RequestBody PersonNameAliasDTO dto) {
|
||||
public PersonNameAlias addAlias(@PathVariable UUID id, @Valid @RequestBody PersonNameAliasDTO dto) {
|
||||
return personService.addAlias(id, dto);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package org.raddatz.familienarchiv.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import org.raddatz.familienarchiv.model.PersonNameAliasType;
|
||||
|
||||
public record PersonNameAliasDTO(
|
||||
String lastName,
|
||||
String firstName,
|
||||
PersonNameAliasType type
|
||||
@NotBlank @Size(max = 255) String lastName,
|
||||
@Size(max = 255) String firstName,
|
||||
@NotNull PersonNameAliasType type
|
||||
) {}
|
||||
|
||||
Reference in New Issue
Block a user