Make sure the API returns 404 on show if the ID was not found
This commit is contained in:
parent
aee7bb80c0
commit
cd6280b97d
9 changed files with 72 additions and 54 deletions
|
@ -82,6 +82,14 @@ class Admins_api_v1 extends EA_Controller
|
||||||
public function show(int $id = null): void
|
public function show(int $id = null): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
$occurrences = $this->admins_model->get(['id' => $id]);
|
||||||
|
|
||||||
|
if (empty($occurrences)) {
|
||||||
|
response('', 404);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$fields = $this->api->request_fields();
|
$fields = $this->api->request_fields();
|
||||||
|
|
||||||
$with = $this->api->request_with();
|
$with = $this->api->request_with();
|
||||||
|
@ -98,12 +106,6 @@ class Admins_api_v1 extends EA_Controller
|
||||||
$this->admins_model->load($admin, $with);
|
$this->admins_model->load($admin, $with);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$admin) {
|
|
||||||
response('', 404);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
json_response($admin);
|
json_response($admin);
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
json_exception($e);
|
json_exception($e);
|
||||||
|
|
|
@ -174,6 +174,14 @@ class Appointments_api_v1 extends EA_Controller
|
||||||
public function show(int $id = null): void
|
public function show(int $id = null): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
$occurrences = $this->appointments_model->get(['id' => $id]);
|
||||||
|
|
||||||
|
if (empty($occurrences)) {
|
||||||
|
response('', 404);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$fields = $this->api->request_fields();
|
$fields = $this->api->request_fields();
|
||||||
|
|
||||||
$with = $this->api->request_with();
|
$with = $this->api->request_with();
|
||||||
|
@ -190,12 +198,6 @@ class Appointments_api_v1 extends EA_Controller
|
||||||
$this->appointments_model->load($appointment, $with);
|
$this->appointments_model->load($appointment, $with);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$appointment) {
|
|
||||||
response('Not Found', 404);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
json_response($appointment);
|
json_response($appointment);
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
json_exception($e);
|
json_exception($e);
|
||||||
|
|
|
@ -80,6 +80,14 @@ class Customers_api_v1 extends EA_Controller
|
||||||
public function show(int $id = null): void
|
public function show(int $id = null): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
$occurrences = $this->customers_model->get(['id' => $id]);
|
||||||
|
|
||||||
|
if (empty($occurrences)) {
|
||||||
|
response('', 404);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$fields = $this->api->request_fields();
|
$fields = $this->api->request_fields();
|
||||||
|
|
||||||
$customer = $this->customers_model->find($id);
|
$customer = $this->customers_model->find($id);
|
||||||
|
@ -90,12 +98,6 @@ class Customers_api_v1 extends EA_Controller
|
||||||
$this->customers_model->only($customer, $fields);
|
$this->customers_model->only($customer, $fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$customer) {
|
|
||||||
response('', 404);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
json_response($customer);
|
json_response($customer);
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
json_exception($e);
|
json_exception($e);
|
||||||
|
|
|
@ -80,6 +80,14 @@ class Providers_api_v1 extends EA_Controller
|
||||||
public function show(int $id = null): void
|
public function show(int $id = null): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
$occurrences = $this->providers_model->get(['id' => $id]);
|
||||||
|
|
||||||
|
if (empty($occurrences)) {
|
||||||
|
response('', 404);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$fields = $this->api->request_fields();
|
$fields = $this->api->request_fields();
|
||||||
|
|
||||||
$with = $this->api->request_with();
|
$with = $this->api->request_with();
|
||||||
|
@ -96,12 +104,6 @@ class Providers_api_v1 extends EA_Controller
|
||||||
$this->providers_model->load($provider, $with);
|
$this->providers_model->load($provider, $with);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$provider) {
|
|
||||||
response('', 404);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
json_response($provider);
|
json_response($provider);
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
json_exception($e);
|
json_exception($e);
|
||||||
|
|
|
@ -80,6 +80,14 @@ class Secretaries_api_v1 extends EA_Controller
|
||||||
public function show(int $id = null): void
|
public function show(int $id = null): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
$occurrences = $this->secretaries_model->get(['id' => $id]);
|
||||||
|
|
||||||
|
if (empty($occurrences)) {
|
||||||
|
response('', 404);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$fields = $this->api->request_fields();
|
$fields = $this->api->request_fields();
|
||||||
|
|
||||||
$secretary = $this->secretaries_model->find($id);
|
$secretary = $this->secretaries_model->find($id);
|
||||||
|
@ -90,12 +98,6 @@ class Secretaries_api_v1 extends EA_Controller
|
||||||
$this->secretaries_model->only($secretary, $fields);
|
$this->secretaries_model->only($secretary, $fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$secretary) {
|
|
||||||
response('', 404);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
json_response($secretary);
|
json_response($secretary);
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
json_exception($e);
|
json_exception($e);
|
||||||
|
|
|
@ -80,6 +80,14 @@ class Service_categories_api_v1 extends EA_Controller
|
||||||
public function show(int $id = null): void
|
public function show(int $id = null): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
$occurrences = $this->service_categories_model->get(['id' => $id]);
|
||||||
|
|
||||||
|
if (empty($occurrences)) {
|
||||||
|
response('', 404);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$fields = $this->api->request_fields();
|
$fields = $this->api->request_fields();
|
||||||
|
|
||||||
$with = $this->api->request_with();
|
$with = $this->api->request_with();
|
||||||
|
@ -96,12 +104,6 @@ class Service_categories_api_v1 extends EA_Controller
|
||||||
$this->service_categories_model->load($service_category, $with);
|
$this->service_categories_model->load($service_category, $with);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$service_category) {
|
|
||||||
response('', 404);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
json_response($service_category);
|
json_response($service_category);
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
json_exception($e);
|
json_exception($e);
|
||||||
|
|
|
@ -80,6 +80,14 @@ class Services_api_v1 extends EA_Controller
|
||||||
public function show(int $id = null): void
|
public function show(int $id = null): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
$occurrences = $this->services_model->get(['id' => $id]);
|
||||||
|
|
||||||
|
if (empty($occurrences)) {
|
||||||
|
response('', 404);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$fields = $this->api->request_fields();
|
$fields = $this->api->request_fields();
|
||||||
|
|
||||||
$with = $this->api->request_with();
|
$with = $this->api->request_with();
|
||||||
|
@ -96,12 +104,6 @@ class Services_api_v1 extends EA_Controller
|
||||||
$this->services_model->load($service, $with);
|
$this->services_model->load($service, $with);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$service) {
|
|
||||||
response('', 404);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
json_response($service);
|
json_response($service);
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
json_exception($e);
|
json_exception($e);
|
||||||
|
|
|
@ -80,6 +80,14 @@ class Unavailabilities_api_v1 extends EA_Controller
|
||||||
public function show(int $id = null): void
|
public function show(int $id = null): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
$occurrences = $this->unavailabilities_model->get(['id' => $id]);
|
||||||
|
|
||||||
|
if (empty($occurrences)) {
|
||||||
|
response('', 404);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$fields = $this->api->request_fields();
|
$fields = $this->api->request_fields();
|
||||||
|
|
||||||
$with = $this->api->request_with();
|
$with = $this->api->request_with();
|
||||||
|
@ -96,12 +104,6 @@ class Unavailabilities_api_v1 extends EA_Controller
|
||||||
$this->unavailabilities_model->load($unavailability, $with);
|
$this->unavailabilities_model->load($unavailability, $with);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$unavailability) {
|
|
||||||
response('', 404);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
json_response($unavailability);
|
json_response($unavailability);
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
json_exception($e);
|
json_exception($e);
|
||||||
|
|
|
@ -80,6 +80,14 @@ class Webhooks_api_v1 extends EA_Controller
|
||||||
public function show(int $id = null): void
|
public function show(int $id = null): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
$occurrences = $this->webhooks_model->get(['id' => $id]);
|
||||||
|
|
||||||
|
if (empty($occurrences)) {
|
||||||
|
response('', 404);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$fields = $this->api->request_fields();
|
$fields = $this->api->request_fields();
|
||||||
|
|
||||||
$with = $this->api->request_with();
|
$with = $this->api->request_with();
|
||||||
|
@ -96,12 +104,6 @@ class Webhooks_api_v1 extends EA_Controller
|
||||||
$this->webhooks_model->load($webhook, $with);
|
$this->webhooks_model->load($webhook, $with);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$webhook) {
|
|
||||||
response('', 404);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
json_response($webhook);
|
json_response($webhook);
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
json_exception($e);
|
json_exception($e);
|
||||||
|
|
Loading…
Reference in a new issue