class FunctionController {

	@PostMapping("/_update")
	@ResponseStatus(HttpStatus.CREATED)
	public FunctionResponse update(@RequestBody FunctionRequest functionRequest, BindingResult errors,@RequestParam String tenantId) {

		if (errors.hasErrors()) {
			throw new CustomBindException(errors);
		}
		functionRequest.getRequestInfo().setAction(Constants.ACTION_UPDATE);
		ModelMapper model = new ModelMapper();
		FunctionResponse functionResponse = new FunctionResponse();
		List<Function> functions = new ArrayList<>();
		functionResponse.setResponseInfo(getResponseInfo(functionRequest.getRequestInfo()));
		Function function;
		FunctionContract contract;
		List<FunctionContract> functionContracts = new ArrayList<>();
		for (FunctionContract functionContract : functionRequest.getFunctions()) {
			function = new Function();
			model.map(functionContract, function);
			function.setLastModifiedBy(functionRequest.getRequestInfo().getUserInfo());
			function.setLastModifiedDate(new Date());
			functions.add(function);
		}

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

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

		functionResponse.setFunctions(functionContracts);

		return functionResponse;
	}

}