class FunctionController {

	@PostMapping("/_create")
	@ResponseStatus(HttpStatus.CREATED)
	public FunctionResponse create(@RequestBody FunctionRequest functionRequest, BindingResult errors,@RequestParam String tenantId) {
		if (errors.hasErrors()) {
			throw new CustomBindException(errors);
		}

		ModelMapper model = new ModelMapper();
		FunctionResponse functionResponse = new FunctionResponse();
		functionResponse.setResponseInfo(getResponseInfo(functionRequest.getRequestInfo()));
		List<Function> functions = new ArrayList<>();
		Function function;
		List<FunctionContract> functionContracts = new ArrayList<>();
		FunctionContract contract;

		functionRequest.getRequestInfo().setAction(Constants.ACTION_CREATE);

		for (FunctionContract functionContract : functionRequest.getFunctions()) {
			function = new Function();
			model.map(functionContract, function);
			function.setCreatedDate(new Date());
			function.setCreatedBy(functionRequest.getRequestInfo().getUserInfo());
			function.setLastModifiedBy(functionRequest.getRequestInfo().getUserInfo());
			functions.add(function);
		}

		functions = functionService.create(functions, errors, functionRequest.getRequestInfo());

		for (Function f : functions) {
			contract = new FunctionContract();
			contract.setCreatedDate(new Date());
			model.map(f, contract);
			functionContracts.add(contract);
		}

		functionResponse.setFunctions(functionContracts);

		return functionResponse;
	}

}