class AccountCodePurposeController {

	@PostMapping("_search")
	@ResponseBody
	@ResponseStatus(HttpStatus.OK)
	public AccountCodePurposeContractResponse search(
			@ModelAttribute AccountCodePurposeGetRequest accountCodePurposeGetRequest,
			@RequestBody RequestInfo requestInfo, BindingResult errors) {
		AccountCodePurposeContractRequest accountCodePurposeContractRequest = new AccountCodePurposeContractRequest();
		accountCodePurposeContractRequest.setAccountCodePurposeGetRequest(accountCodePurposeGetRequest);
		accountCodePurposeContractRequest.setRequestInfo(requestInfo);
		accountCodePurposeService.validate(accountCodePurposeContractRequest, "search", errors);
		if (errors.hasErrors()) {
			throw new CustomBindException(errors);
		}
		accountCodePurposeService.fetchRelatedContracts(accountCodePurposeContractRequest);
		AccountCodePurposeContractResponse accountCodePurposeContractResponse = new AccountCodePurposeContractResponse();
		accountCodePurposeContractResponse.setAccountCodePurposes(new ArrayList<AccountCodePurposeContract>());
		accountCodePurposeContractResponse.setPage(new Pagination());
		List<AccountCodePurpose> accountCodePurposesList = null;
		accountCodePurposesList = accountCodePurposeService.getAccountCodePurposes(accountCodePurposeGetRequest);

		for (AccountCodePurpose b : accountCodePurposesList) {
			accountCodePurposeContractResponse.getAccountCodePurposes().add(new AccountCodePurposeContract(b));
		}
		accountCodePurposeContractResponse.getPage().map(new PageImpl<AccountCodePurpose>(accountCodePurposesList));
		accountCodePurposeContractResponse
				.setResponseInfo(getResponseInfo(accountCodePurposeContractRequest.getRequestInfo()));
		accountCodePurposeContractResponse.getResponseInfo().setStatus(HttpStatus.OK.toString());
		return accountCodePurposeContractResponse;
	}

}