mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-11-10 01:52:22 +03:00
Implemented the PUT method of appointments resource.
This commit is contained in:
parent
a40bb1ae4c
commit
4c1ec9ea2f
2 changed files with 45 additions and 17 deletions
|
@ -45,30 +45,38 @@ class Appointments extends API_V1_Controller {
|
|||
* @param int $id Optional (null), the record ID to be returned.
|
||||
*/
|
||||
public function get($id = null) {
|
||||
$condition = $id !== null ? 'id = ' . $id : null;
|
||||
$appointments = $this->appointments_model->get_batch($condition);
|
||||
try {
|
||||
$condition = $id !== null ? 'id = ' . $id : null;
|
||||
$appointments = $this->appointments_model->get_batch($condition);
|
||||
|
||||
$response = new Response($appointments);
|
||||
$response->encode($this->parser)->search()->sort()->paginate()->minimize();
|
||||
$response = new Response($appointments);
|
||||
$response->encode($this->parser)->search()->sort()->paginate()->minimize();
|
||||
|
||||
if ($id !== null) {
|
||||
$response->singleEntry();
|
||||
}
|
||||
if ($id !== null) {
|
||||
$response->singleEntry();
|
||||
}
|
||||
|
||||
$response->output();
|
||||
$response->output();
|
||||
} catch(\Exception $exception) {
|
||||
exit($this->_handleException($exception));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* POST API Method
|
||||
*/
|
||||
public function post() {
|
||||
$request = json_decode(file_get_contents('php://input'), true);
|
||||
$this->parser->decode($request);
|
||||
$id = $this->appointments_model->add($request);
|
||||
$appointments = $this->appointments_model->get_batch('id = ' . $id);
|
||||
$response = new Response($appointments);
|
||||
$status = new NonEmptyString('201 Created');
|
||||
$response->encode($this->parser)->singleEntry()->output($status);
|
||||
try {
|
||||
$request = json_decode(file_get_contents('php://input'), true);
|
||||
$this->parser->decode($request);
|
||||
$id = $this->appointments_model->add($request);
|
||||
$appointments = $this->appointments_model->get_batch('id = ' . $id);
|
||||
$response = new Response($appointments);
|
||||
$status = new NonEmptyString('201 Created');
|
||||
$response->encode($this->parser)->singleEntry()->output($status);
|
||||
} catch(\Exception $exception) {
|
||||
exit($this->_handleException($exception));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -77,7 +85,23 @@ class Appointments extends API_V1_Controller {
|
|||
* @param int $id The record ID to be updated.
|
||||
*/
|
||||
public function put($id) {
|
||||
try {
|
||||
if (empty($id) || !is_numeric($id)) {
|
||||
throw new \EA\Engine\Api\V1\Exception('The provided URI ID is not a numeric value: ' . $id);
|
||||
}
|
||||
|
||||
$appointment = $this->appointments_model->get_row($id);
|
||||
$request = json_decode(file_get_contents('php://input'), true);
|
||||
$this->parser->decode($request, $appointment);
|
||||
$request['id'] = $id;
|
||||
$id = $this->appointments_model->add($request);
|
||||
$appointments = $this->appointments_model->get_batch('id = ' . $id);
|
||||
$response = new Response($appointments);
|
||||
$status = new NonEmptyString('201 Created');
|
||||
$response->encode($this->parser)->singleEntry()->output($status);
|
||||
} catch(\Exception $exception) {
|
||||
exit($this->_handleException($exception));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -86,7 +110,11 @@ class Appointments extends API_V1_Controller {
|
|||
* @param int $id The record ID to be deleted.
|
||||
*/
|
||||
public function delete($id) {
|
||||
try {
|
||||
|
||||
} catch(\Exception $exception) {
|
||||
exit($this->_handleException($exception));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,8 +31,8 @@ class Appointments implements ParsersInterface {
|
|||
$response = $encodedResponse;
|
||||
}
|
||||
|
||||
public function decode(array &$request) {
|
||||
$decodedRequest = [];
|
||||
public function decode(array &$request, array $base = null) {
|
||||
$decodedRequest = $base ?: [];
|
||||
|
||||
if (!empty($request['id'])) {
|
||||
$decodedRequest['id'] = $request['id'];
|
||||
|
|
Loading…
Reference in a new issue