repository = $repository; $this->service = $service; //set filters allowed values $this->allowed_filter_fields = array('*'); $this->allowed_projection_fields = array('*'); } /** * @param $id * @return mixed */ protected function _delete($id) { try { $res = $this->service->delete($id); return $res ? $this->deleted() : $this->error404(array('error' => 'operation failed')); } catch (Exception $ex) { $this->log_service->error($ex); return $this->error500($ex); } } protected function _update($id) { try { $values = Input::all(); $rules = array( 'id' => 'required|integer', 'active' => 'required|boolean', ); // Creates a Validator instance and validates the data. $validation = Validator::make($values, $rules); if ($validation->fails()) { $messages = $validation->messages()->toArray(); return $this->error400(array('error' => 'validation', 'messages' => $messages)); } $res = $this->service->update(intval($id), $values); return $res ? $this->ok() : $this->error400(array('error' => 'operation failed')); } catch (AbsentClientException $ex1) { $this->log_service->error($ex1); return $this->error404(array('error' => $ex1->getMessage())); } catch (Exception $ex) { $this->log_service->error($ex); return $this->error500($ex); } } /** * @return mixed */ protected function _getByPage() { try { //check for optional filters param on querystring $fields = $this->getProjection(Input::get('fields', null)); $filters = $this->getFilters(Input::except('fields', 'limit', 'offset')); $page_nbr = intval(Input::get('offset', 1)); $page_size = intval(Input::get('limit', 10)); $list = $this->repository->getAll($page_nbr, $page_size, $filters, $fields); $items = array(); foreach ($list->getItems() as $private_key) { $data = $private_key->toArray(); $data['sha_256'] = $private_key->getSHA_256_Thumbprint(); array_push($items, $data); } return $this->ok(array( 'page' => $items, 'total_items' => $list->getTotal() )); } catch (Exception $ex) { $this->log_service->error($ex); return $this->error500($ex); } } }