class BudgetDetailController {

    @PostMapping("/_create")
    @ResponseStatus(HttpStatus.CREATED)
    public BudgetDetailResponse create(@RequestBody final BudgetDetailRequest budgetDetailRequest, final BindingResult errors) {

        final BudgetDetailMapper mapper = new BudgetDetailMapper();
        final BudgetDetailResponse budgetDetailResponse = new BudgetDetailResponse();
        budgetDetailResponse.setResponseInfo(getResponseInfo(budgetDetailRequest.getRequestInfo()));
        List<BudgetDetail> budgetdetails = new ArrayList<>();
        BudgetDetail budgetDetail = null;
        final List<BudgetDetailContract> budgetDetailContracts = new ArrayList<BudgetDetailContract>();
        BudgetDetailContract contract = null;

        budgetDetailRequest.getRequestInfo().setAction(ACTION_CREATE);

        for (final BudgetDetailContract budgetDetailContract : budgetDetailRequest.getBudgetDetails()) {
            budgetDetail = mapper.toDomain(budgetDetailContract);
            budgetDetail.setCreatedBy(budgetDetailRequest.getRequestInfo().getUserInfo());
            budgetDetail.setLastModifiedBy(budgetDetailRequest.getRequestInfo().getUserInfo());
            budgetdetails.add(budgetDetail);
        }

        budgetdetails = budgetDetailService.create(budgetdetails, errors, budgetDetailRequest.getRequestInfo());

        for (final BudgetDetail bd : budgetdetails) {
            contract = mapper.toContract(bd);
            budgetDetailContracts.add(contract);
        }

        budgetDetailResponse.setBudgetDetails(budgetDetailContracts);

        return budgetDetailResponse;
    }

}