diff --git a/src/application/controllers/api/v1/Appointments.php b/src/application/controllers/api/v1/Appointments.php index c19e4d1a..b30fddd0 100644 --- a/src/application/controllers/api/v1/Appointments.php +++ b/src/application/controllers/api/v1/Appointments.php @@ -56,13 +56,14 @@ class Appointments extends API_V1_Controller { } $response = new Response($appointments); - $response->encode($this->parser)->search()->sort()->paginate()->minimize(); + $response->encode($this->parser) + ->search() + ->sort() + ->paginate() + ->minimize() + ->singleEntry($id) + ->output(); - if ($id !== null) { - $response->singleEntry(); - } - - $response->output(); } catch(\Exception $exception) { exit($this->_handleException($exception)); } diff --git a/src/engine/Api/V1/Response.php b/src/engine/Api/V1/Response.php index 974a4c75..73e848af 100644 --- a/src/engine/Api/V1/Response.php +++ b/src/engine/Api/V1/Response.php @@ -105,13 +105,19 @@ class Response { /** * Return a single entry instead of an array of entries. * - * This is useful whenever the client requests only a single entry. + * This is useful whenever the client requests only a single entry. Make sure that you call this method + * right before the output() in order to avoid side-effects with the other processor methods of this class. * + * @param int $id Provide the ID value of the request UI and if is not null the response will be + * converted into an associative array. + * * @return \EA\Engine\Api\V1\Response */ - public function singleEntry() { - $this->response = array_shift($this->response); - + public function singleEntry($id) { + if ($id !== null) { + $this->response = array_shift($this->response); + } + return $this; }