class MonitoringOfficerController {

    @PostMapping("/create")
    public String createUser(@Valid @ModelAttribute(FORM) MonitoringOfficerCreateForm form,
                             BindingResult bindingResult,
                             ValidationHandler validationHandler,
                             Model model) {

        Supplier<String> failureView = () -> {
            model.addAttribute("emailAddress", form.getEmailAddress());
            model.addAttribute(FORM, form);
            return "project/monitoring-officer/create-new";
        };

        return validationHandler
                .failNowOrSucceedWith(failureView, () -> {
                    MonitoringOfficerCreateResource resource = new MonitoringOfficerCreateResource(form.getFirstName(),
                            form.getLastName(),
                            form.getPhoneNumber(),
                            form.getEmailAddress());

                    RestResult<Void> result = monitoringOfficerRegistrationRestService.createMonitoringOfficer(resource);
                    return validationHandler
                            .addAnyErrors(result)
                            .failNowOrSucceedWith(failureView,
                                    () -> "redirect:/monitoring-officer/view-all");
                });
    }

}