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
|
||||
{
|
||||
try {
|
||||
$occurrences = $this->admins_model->get(['id' => $id]);
|
||||
|
||||
if (empty($occurrences)) {
|
||||
response('', 404);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$fields = $this->api->request_fields();
|
||||
|
||||
$with = $this->api->request_with();
|
||||
|
@ -98,12 +106,6 @@ class Admins_api_v1 extends EA_Controller
|
|||
$this->admins_model->load($admin, $with);
|
||||
}
|
||||
|
||||
if (!$admin) {
|
||||
response('', 404);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
json_response($admin);
|
||||
} catch (Throwable $e) {
|
||||
json_exception($e);
|
||||
|
|
|
@ -174,6 +174,14 @@ class Appointments_api_v1 extends EA_Controller
|
|||
public function show(int $id = null): void
|
||||
{
|
||||
try {
|
||||
$occurrences = $this->appointments_model->get(['id' => $id]);
|
||||
|
||||
if (empty($occurrences)) {
|
||||
response('', 404);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$fields = $this->api->request_fields();
|
||||
|
||||
$with = $this->api->request_with();
|
||||
|
@ -190,12 +198,6 @@ class Appointments_api_v1 extends EA_Controller
|
|||
$this->appointments_model->load($appointment, $with);
|
||||
}
|
||||
|
||||
if (!$appointment) {
|
||||
response('Not Found', 404);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
json_response($appointment);
|
||||
} catch (Throwable $e) {
|
||||
json_exception($e);
|
||||
|
|
|
@ -80,6 +80,14 @@ class Customers_api_v1 extends EA_Controller
|
|||
public function show(int $id = null): void
|
||||
{
|
||||
try {
|
||||
$occurrences = $this->customers_model->get(['id' => $id]);
|
||||
|
||||
if (empty($occurrences)) {
|
||||
response('', 404);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$fields = $this->api->request_fields();
|
||||
|
||||
$customer = $this->customers_model->find($id);
|
||||
|
@ -90,12 +98,6 @@ class Customers_api_v1 extends EA_Controller
|
|||
$this->customers_model->only($customer, $fields);
|
||||
}
|
||||
|
||||
if (!$customer) {
|
||||
response('', 404);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
json_response($customer);
|
||||
} catch (Throwable $e) {
|
||||
json_exception($e);
|
||||
|
|
|
@ -80,6 +80,14 @@ class Providers_api_v1 extends EA_Controller
|
|||
public function show(int $id = null): void
|
||||
{
|
||||
try {
|
||||
$occurrences = $this->providers_model->get(['id' => $id]);
|
||||
|
||||
if (empty($occurrences)) {
|
||||
response('', 404);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$fields = $this->api->request_fields();
|
||||
|
||||
$with = $this->api->request_with();
|
||||
|
@ -96,12 +104,6 @@ class Providers_api_v1 extends EA_Controller
|
|||
$this->providers_model->load($provider, $with);
|
||||
}
|
||||
|
||||
if (!$provider) {
|
||||
response('', 404);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
json_response($provider);
|
||||
} catch (Throwable $e) {
|
||||
json_exception($e);
|
||||
|
|
|
@ -80,6 +80,14 @@ class Secretaries_api_v1 extends EA_Controller
|
|||
public function show(int $id = null): void
|
||||
{
|
||||
try {
|
||||
$occurrences = $this->secretaries_model->get(['id' => $id]);
|
||||
|
||||
if (empty($occurrences)) {
|
||||
response('', 404);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$fields = $this->api->request_fields();
|
||||
|
||||
$secretary = $this->secretaries_model->find($id);
|
||||
|
@ -90,12 +98,6 @@ class Secretaries_api_v1 extends EA_Controller
|
|||
$this->secretaries_model->only($secretary, $fields);
|
||||
}
|
||||
|
||||
if (!$secretary) {
|
||||
response('', 404);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
json_response($secretary);
|
||||
} catch (Throwable $e) {
|
||||
json_exception($e);
|
||||
|
|
|
@ -80,6 +80,14 @@ class Service_categories_api_v1 extends EA_Controller
|
|||
public function show(int $id = null): void
|
||||
{
|
||||
try {
|
||||
$occurrences = $this->service_categories_model->get(['id' => $id]);
|
||||
|
||||
if (empty($occurrences)) {
|
||||
response('', 404);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$fields = $this->api->request_fields();
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
if (!$service_category) {
|
||||
response('', 404);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
json_response($service_category);
|
||||
} catch (Throwable $e) {
|
||||
json_exception($e);
|
||||
|
|
|
@ -80,6 +80,14 @@ class Services_api_v1 extends EA_Controller
|
|||
public function show(int $id = null): void
|
||||
{
|
||||
try {
|
||||
$occurrences = $this->services_model->get(['id' => $id]);
|
||||
|
||||
if (empty($occurrences)) {
|
||||
response('', 404);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$fields = $this->api->request_fields();
|
||||
|
||||
$with = $this->api->request_with();
|
||||
|
@ -96,12 +104,6 @@ class Services_api_v1 extends EA_Controller
|
|||
$this->services_model->load($service, $with);
|
||||
}
|
||||
|
||||
if (!$service) {
|
||||
response('', 404);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
json_response($service);
|
||||
} catch (Throwable $e) {
|
||||
json_exception($e);
|
||||
|
|
|
@ -80,6 +80,14 @@ class Unavailabilities_api_v1 extends EA_Controller
|
|||
public function show(int $id = null): void
|
||||
{
|
||||
try {
|
||||
$occurrences = $this->unavailabilities_model->get(['id' => $id]);
|
||||
|
||||
if (empty($occurrences)) {
|
||||
response('', 404);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$fields = $this->api->request_fields();
|
||||
|
||||
$with = $this->api->request_with();
|
||||
|
@ -96,12 +104,6 @@ class Unavailabilities_api_v1 extends EA_Controller
|
|||
$this->unavailabilities_model->load($unavailability, $with);
|
||||
}
|
||||
|
||||
if (!$unavailability) {
|
||||
response('', 404);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
json_response($unavailability);
|
||||
} catch (Throwable $e) {
|
||||
json_exception($e);
|
||||
|
|
|
@ -80,6 +80,14 @@ class Webhooks_api_v1 extends EA_Controller
|
|||
public function show(int $id = null): void
|
||||
{
|
||||
try {
|
||||
$occurrences = $this->webhooks_model->get(['id' => $id]);
|
||||
|
||||
if (empty($occurrences)) {
|
||||
response('', 404);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$fields = $this->api->request_fields();
|
||||
|
||||
$with = $this->api->request_with();
|
||||
|
@ -96,12 +104,6 @@ class Webhooks_api_v1 extends EA_Controller
|
|||
$this->webhooks_model->load($webhook, $with);
|
||||
}
|
||||
|
||||
if (!$webhook) {
|
||||
response('', 404);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
json_response($webhook);
|
||||
} catch (Throwable $e) {
|
||||
json_exception($e);
|
||||
|
|
Loading…
Reference in a new issue