class AssessmentFeedbackController {

    @PostMapping("/question/{questionId}")
    public String save(
            Model model,
            @ModelAttribute(FORM_ATTR_NAME) Form form,
            @SuppressWarnings("UnusedParameters") BindingResult bindingResult,
            ValidationHandler validationHandler,
            @PathVariable("assessmentId") long assessmentId,
            @PathVariable("questionId") long questionId) {

        Supplier<String> failureView = () -> doViewQuestion(model, assessmentId, getQuestionForAssessment(questionId, assessmentId));

        return validationHandler.failNowOrSucceedWith(failureView, () -> {
            List<FormInputResource> formInputs = getAssessmentFormInputsForQuestion(questionId);
            AssessorFormInputResponsesResource responses = getFormInputResponses(form, formInputs, assessmentId);
            RestResult<Void> updateResult = assessorFormInputResponseRestService.updateFormInputResponses(responses);

            return validationHandler.addAnyErrors(updateResult, mappingFieldErrorToField(e -> {
                Matcher matcher = Pattern.compile("responses\\[(\\d)\\]\\.value").matcher(e.getFieldName());

                if (matcher.find()) {
                    int errorIndex = Integer.parseInt(matcher.group(1));
                    Long formInputResponseWithError = responses.getResponses().get(errorIndex).getFormInput();

                    return format("formInput[%s]", formInputResponseWithError);
                } else if (e.isFieldError() && !e.getArguments().isEmpty()) {
                    return format("formInput[%s]", e.getArguments().get(0));
                }

                return e.getFieldName();
            }), asGlobalErrors()).failNowOrSucceedWith(failureView, () -> redirectToAssessmentOverview(assessmentId));
        });
    }

}