mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-11-25 17:33:19 +03:00
Changed the 'singleEntry' response method in order to avoid writing the ID condition in every API controller.
This commit is contained in:
parent
ff558f99c4
commit
eed53d44cd
2 changed files with 17 additions and 10 deletions
|
@ -56,13 +56,14 @@ class Appointments extends API_V1_Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
$response = new Response($appointments);
|
$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) {
|
} catch(\Exception $exception) {
|
||||||
exit($this->_handleException($exception));
|
exit($this->_handleException($exception));
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,12 +105,18 @@ class Response {
|
||||||
/**
|
/**
|
||||||
* Return a single entry instead of an array of entries.
|
* 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
|
* @return \EA\Engine\Api\V1\Response
|
||||||
*/
|
*/
|
||||||
public function singleEntry() {
|
public function singleEntry($id) {
|
||||||
|
if ($id !== null) {
|
||||||
$this->response = array_shift($this->response);
|
$this->response = array_shift($this->response);
|
||||||
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue