diff --git a/src/application/controllers/api/v1/Appointments.php b/src/application/controllers/api/v1/Appointments.php index a3de0a93..e8ea86c1 100644 --- a/src/application/controllers/api/v1/Appointments.php +++ b/src/application/controllers/api/v1/Appointments.php @@ -45,13 +45,19 @@ class Appointments extends API_V1_Controller { * @param int $id Optional (null), the record ID to be returned. */ public function get($id = null) { - $appointments = $this->appointments_model->get_batch(); - + $condition = $id !== null ? 'id = ' . $id : null; + + $appointments = $this->appointments_model->get_batch($condition); + $response = new Response($appointments); - $status = new NonEmptyString('200 OK'); + $response->format($this->formatter)->search()->sort()->paginate()->minimize(); - $response->format($this->formatter)->search()->sort()->paginate()->minimize()->output(); + if ($id !== null) { + $response->singleEntry(); + } + + $response->output(); } /** diff --git a/src/engine/Api/V1/Response.php b/src/engine/Api/V1/Response.php index 5dee0d7e..1583b124 100644 --- a/src/engine/Api/V1/Response.php +++ b/src/engine/Api/V1/Response.php @@ -98,6 +98,19 @@ class Response { return $this; } + /** + * Return a single entry instead of an array of entries. + * + * This is useful whenever the client requests only a single entry. + * + * @return \EA\Engine\Api\V1\Response + */ + public function singleEntry() { + $this->response = array_shift($this->response); + + return $this; + } + /** * Output the response as a JSON with the provided status header. *