Updated appointments API resource controller with the newest helper methods.

This commit is contained in:
Alex Tselegidis 2016-07-10 13:00:42 +02:00
parent c39c7c3df2
commit 0a8e70f2ec

View file

@ -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));
} }