refactor: move createPerson logic into PersonService
Controller was directly calling personRepository.save() for person creation. Extracted into PersonService.createPerson() to enforce Controller → Service → Repository layering. Also documented the layering rules in CLAUDE.md. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -51,12 +51,7 @@ public class PersonController {
|
||||
if (firstName == null || firstName.isBlank() || lastName == null || lastName.isBlank()) {
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Vor- und Nachname sind Pflichtfelder");
|
||||
}
|
||||
Person person = Person.builder()
|
||||
.firstName(firstName.trim())
|
||||
.lastName(lastName.trim())
|
||||
.alias(body.get("alias"))
|
||||
.build();
|
||||
return ResponseEntity.ok(personRepository.save(person));
|
||||
return ResponseEntity.ok(personService.createPerson(firstName.trim(), lastName.trim(), body.get("alias")));
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
|
||||
@@ -16,6 +16,16 @@ public class PersonService {
|
||||
|
||||
private final PersonRepository personRepository;
|
||||
|
||||
@Transactional
|
||||
public Person createPerson(String firstName, String lastName, String alias) {
|
||||
Person person = Person.builder()
|
||||
.firstName(firstName)
|
||||
.lastName(lastName)
|
||||
.alias(alias == null || alias.isBlank() ? null : alias.trim())
|
||||
.build();
|
||||
return personRepository.save(person);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Person updatePerson(UUID id, String firstName, String lastName, String alias) {
|
||||
Person person = personRepository.findById(id)
|
||||
|
||||
Reference in New Issue
Block a user