@Controller
class AController {
@Data
public static class ChangeBirthdayForm {
@NotNull @Min(1917) Integer year;
@NotNull @Min(1) @Max(12) Integer month;
@NotNull @Min(1) @Max(31) Integer day;
}
public ResponseEntity changeBirthday(@Valid @ModelAttribute ChangeBirthdayForm form) {
Date newBirthDay = new Date(year -1900, month -1, day);
UserBirthdayChangeRequest request = new UserBirthdayChangeRequest(newBirthDay);
userInfoInteractor.changeBirthday(request);
}
}
@Data @AllArgsConstructor
class UserBirthdayChangeRequest {
Date birthday;
public void validate() {
assertNotNull (birthday);
assert(DateUtil.pastThan(newDate, now));
}
}
@Service
class UserInfoInteractor {
public void changeBirthday(@Valid UserBirthdayChangeRequest request){
assert(userGradePolicy.acceptUserAge(request.getBirthday()));
}
}