mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-11-22 16:02:54 +03:00
Added API method for getting a single appointment.
This commit is contained in:
parent
02ac330b3b
commit
de4bc1217a
2 changed files with 23 additions and 4 deletions
|
@ -45,13 +45,19 @@ class Appointments extends API_V1_Controller {
|
||||||
* @param int $id Optional (null), the record ID to be returned.
|
* @param int $id Optional (null), the record ID to be returned.
|
||||||
*/
|
*/
|
||||||
public function get($id = null) {
|
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);
|
$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();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -98,6 +98,19 @@ class Response {
|
||||||
return $this;
|
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.
|
* Output the response as a JSON with the provided status header.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue