mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-11-23 00:13:21 +03:00
Updated appointments API resource controller with the newest helper methods.
This commit is contained in:
parent
c39c7c3df2
commit
0a8e70f2ec
1 changed files with 9 additions and 12 deletions
|
@ -51,11 +51,11 @@ class Appointments extends API_V1_Controller {
|
||||||
$appointments = $this->appointments_model->get_batch($condition);
|
$appointments = $this->appointments_model->get_batch($condition);
|
||||||
|
|
||||||
if ($id !== null && count($appointments) === 0) {
|
if ($id !== null && count($appointments) === 0) {
|
||||||
throw new \EA\Engine\Api\V1\Exception('The requested appointment record was not found!', 404,
|
$this->_throwRecordNotFound();
|
||||||
'Not Found');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$response = new Response($appointments);
|
$response = new Response($appointments);
|
||||||
|
|
||||||
$response->encode($this->parser)
|
$response->encode($this->parser)
|
||||||
->search()
|
->search()
|
||||||
->sort()
|
->sort()
|
||||||
|
@ -86,10 +86,10 @@ class Appointments extends API_V1_Controller {
|
||||||
$id = $this->appointments_model->add($appointment);
|
$id = $this->appointments_model->add($appointment);
|
||||||
|
|
||||||
// Fetch the new object from the database and return it to the client.
|
// Fetch the new object from the database and return it to the client.
|
||||||
$appointments = $this->appointments_model->get_batch('id = ' . $id);
|
$batch = $this->appointments_model->get_batch('id = ' . $id);
|
||||||
$response = new Response($appointments);
|
$response = new Response($batch);
|
||||||
$status = new NonEmptyString('201 Created');
|
$status = new NonEmptyString('201 Created');
|
||||||
$response->encode($this->parser)->singleEntry()->output($status);
|
$response->encode($this->parser)->singleEntry(true)->output($status);
|
||||||
} catch(\Exception $exception) {
|
} catch(\Exception $exception) {
|
||||||
exit($this->_handleException($exception));
|
exit($this->_handleException($exception));
|
||||||
}
|
}
|
||||||
|
@ -106,8 +106,7 @@ class Appointments extends API_V1_Controller {
|
||||||
$batch = $this->appointments_model->get_batch('id = ' . $id);
|
$batch = $this->appointments_model->get_batch('id = ' . $id);
|
||||||
|
|
||||||
if ($id !== null && count($batch) === 0) {
|
if ($id !== null && count($batch) === 0) {
|
||||||
throw new \EA\Engine\Api\V1\Exception('The requested appointment record was not found!', 404,
|
$this->_throwRecordNotFound();
|
||||||
'Not Found');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$request = new Request();
|
$request = new Request();
|
||||||
|
@ -118,10 +117,9 @@ class Appointments extends API_V1_Controller {
|
||||||
$id = $this->appointments_model->add($updatedAppointment);
|
$id = $this->appointments_model->add($updatedAppointment);
|
||||||
|
|
||||||
// Fetch the updated object from the database and return it to the client.
|
// Fetch the updated object from the database and return it to the client.
|
||||||
$appointments = $this->appointments_model->get_batch('id = ' . $id);
|
$batch = $this->appointments_model->get_batch('id = ' . $id);
|
||||||
$response = new Response($appointments);
|
$response = new Response($batch);
|
||||||
$status = new NonEmptyString('201 Created');
|
$response->encode($this->parser)->singleEntry($id)->output();
|
||||||
$response->encode($this->parser)->singleEntry()->output($status);
|
|
||||||
} catch(\Exception $exception) {
|
} catch(\Exception $exception) {
|
||||||
exit($this->_handleException($exception));
|
exit($this->_handleException($exception));
|
||||||
}
|
}
|
||||||
|
@ -142,7 +140,6 @@ class Appointments extends API_V1_Controller {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$response->output();
|
$response->output();
|
||||||
|
|
||||||
} catch(\Exception $exception) {
|
} catch(\Exception $exception) {
|
||||||
exit($this->_handleException($exception));
|
exit($this->_handleException($exception));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue