Updated all the API controllers to work with the updated code.

This commit is contained in:
Alex Tselegidis 2021-10-28 14:01:27 +02:00
parent a280496294
commit 8ecf389bf1
11 changed files with 113 additions and 113 deletions

View file

@ -41,7 +41,7 @@ class API_V1_Controller extends EA_Controller {
$this->load->model('settings_model');
$api_token = $this->settings_model->get_setting('api_token');
$api_token = setting('api_token');
$authorization = new Authorization($this);
@ -60,7 +60,7 @@ class API_V1_Controller extends EA_Controller {
$password = new NonEmptyText($_SERVER['PHP_AUTH_PW']);
$authorization->basic($username, $password);
}
catch (Exception $exception)
catch (Throwable $e)
{
$this->handle_exception($exception);
exit;
@ -147,7 +147,7 @@ class API_V1_Controller extends EA_Controller {
{
$error = [
'code' => $exception->getCode() ?: 500,
'message' => $exception->getMessage(),
'message' => $e->getMessage(),
];
$header = $exception instanceof \EA\Engine\Api\V1\Exception

View file

@ -51,7 +51,7 @@ class Admins extends API_V1_Controller {
{
$where = $id !== NULL ? ['id' => $id] : NULL;
$admins = $this->admins_model->get_batch($where);
$admins = $this->admins_model->get($where);
if ($id !== NULL && count($admins) === 0)
{
@ -69,7 +69,7 @@ class Admins extends API_V1_Controller {
->output();
}
catch (Exception $exception)
catch (Throwable $e)
{
$this->handle_exception($exception);
}
@ -97,15 +97,15 @@ class Admins extends API_V1_Controller {
throw new Exception('No settings property provided.');
}
$id = $this->admins_model->add($admin);
$id = $this->admins_model->save($admin);
// Fetch the new object from the database and return it to the client.
$batch = $this->admins_model->get_batch(['id' => $id]);
$batch = $this->admins_model->get(['id' => $id]);
$response = new Response($batch);
$status = new NonEmptyText('201 Created');
$response->encode($this->parser)->singleEntry(TRUE)->output($status);
}
catch (Exception $exception)
catch (Throwable $e)
{
$this->handle_exception($exception);
}
@ -121,7 +121,7 @@ class Admins extends API_V1_Controller {
try
{
// Update the admin record.
$batch = $this->admins_model->get_batch(['id' => $id]);
$batch = $this->admins_model->get(['id' => $id]);
if ($id !== NULL && count($batch) === 0)
{
@ -133,14 +133,14 @@ class Admins extends API_V1_Controller {
$baseAdmin = $batch[0];
$this->parser->decode($updatedAdmin, $baseAdmin);
$updatedAdmin['id'] = $id;
$id = $this->admins_model->add($updatedAdmin);
$id = $this->admins_model->save($updatedAdmin);
// Fetch the updated object from the database and return it to the client.
$batch = $this->admins_model->get_batch(['id' => $id]);
$batch = $this->admins_model->get(['id' => $id]);
$response = new Response($batch);
$response->encode($this->parser)->singleEntry($id)->output();
}
catch (Exception $exception)
catch (Throwable $e)
{
$this->handle_exception($exception);
}
@ -164,7 +164,7 @@ class Admins extends API_V1_Controller {
$response->output();
}
catch (Exception $exception)
catch (Throwable $e)
{
$this->handle_exception($exception);
}

View file

@ -64,7 +64,7 @@ class Appointments extends API_V1_Controller {
$where['id'] = $id;
}
$appointments = $this->appointments_model->get_batch($where, NULL, NULL, NULL, array_key_exists('aggregates', $_GET));
$appointments = $this->appointments_model->get($where, NULL, NULL, NULL, array_key_exists('aggregates', $_GET));
if ($id !== NULL && count($appointments) === 0)
{
@ -82,7 +82,7 @@ class Appointments extends API_V1_Controller {
->output();
}
catch (Exception $exception)
catch (Throwable $e)
{
$this->handle_exception($exception);
}
@ -108,7 +108,7 @@ class Appointments extends API_V1_Controller {
// Generate end_datetime based on service duration if this field is not defined
if ( ! isset($appointment['end_datetime']))
{
$service = $this->services_model->get_row($appointment['id_services']);
$service = $this->services_model->find($appointment['id_services']);
if (isset($service['duration']))
{
@ -118,30 +118,30 @@ class Appointments extends API_V1_Controller {
}
}
$id = $this->appointments_model->add($appointment);
$id = $this->appointments_model->save($appointment);
$appointment = $this->appointments_model->get_row($id);
$service = $this->services_model->get_row($appointment['id_services']);
$provider = $this->providers_model->get_row($appointment['id_users_provider']);
$customer = $this->customers_model->get_row($appointment['id_users_customer']);
$appointment = $this->appointments_model->find($id);
$service = $this->services_model->find($appointment['id_services']);
$provider = $this->providers_model->find($appointment['id_users_provider']);
$customer = $this->customers_model->find($appointment['id_users_customer']);
$settings = [
'company_name' => $this->settings_model->get_setting('company_name'),
'company_email' => $this->settings_model->get_setting('company_email'),
'company_link' => $this->settings_model->get_setting('company_link'),
'date_format' => $this->settings_model->get_setting('date_format'),
'time_format' => $this->settings_model->get_setting('time_format')
'company_name' => setting('company_name'),
'company_email' => setting('company_email'),
'company_link' => setting('company_link'),
'date_format' => setting('date_format'),
'time_format' => setting('time_format')
];
$this->synchronization->sync_appointment_saved($appointment, $service, $provider, $customer, $settings, FALSE);
$this->notifications->notify_appointment_saved($appointment, $service, $provider, $customer, $settings, FALSE);
// Fetch the new object from the database and return it to the client.
$batch = $this->appointments_model->get_batch(['id' => $id]);
$batch = $this->appointments_model->get(['id' => $id]);
$response = new Response($batch);
$status = new NonEmptyText('201 Created');
$response->encode($this->parser)->singleEntry(TRUE)->output($status);
}
catch (Exception $exception)
catch (Throwable $e)
{
$this->handle_exception($exception);
}
@ -157,7 +157,7 @@ class Appointments extends API_V1_Controller {
try
{
// Update the appointment record.
$batch = $this->appointments_model->get_batch(['id' => $id]);
$batch = $this->appointments_model->get(['id' => $id]);
if ($id !== NULL && count($batch) === 0)
{
@ -169,17 +169,17 @@ class Appointments extends API_V1_Controller {
$base_appointment = $batch[0];
$this->parser->decode($updated_appointment, $base_appointment);
$updated_appointment['id'] = $id;
$id = $this->appointments_model->add($updated_appointment);
$id = $this->appointments_model->save($updated_appointment);
$service = $this->services_model->get_row($updated_appointment['id_services']);
$provider = $this->providers_model->get_row($updated_appointment['id_users_provider']);
$customer = $this->customers_model->get_row($updated_appointment['id_users_customer']);
$service = $this->services_model->find($updated_appointment['id_services']);
$provider = $this->providers_model->find($updated_appointment['id_users_provider']);
$customer = $this->customers_model->find($updated_appointment['id_users_customer']);
$settings = [
'company_name' => $this->settings_model->get_setting('company_name'),
'company_email' => $this->settings_model->get_setting('company_email'),
'company_link' => $this->settings_model->get_setting('company_link'),
'date_format' => $this->settings_model->get_setting('date_format'),
'time_format' => $this->settings_model->get_setting('time_format')
'company_name' => setting('company_name'),
'company_email' => setting('company_email'),
'company_link' => setting('company_link'),
'date_format' => setting('date_format'),
'time_format' => setting('time_format')
];
$this->synchronization->sync_appointment_saved($updated_appointment, $service, $provider, $customer, $settings, TRUE);
@ -187,11 +187,11 @@ class Appointments extends API_V1_Controller {
// Fetch the updated object from the database and return it to the client.
$batch = $this->appointments_model->get_batch(['id' => $id]);
$batch = $this->appointments_model->get(['id' => $id]);
$response = new Response($batch);
$response->encode($this->parser)->singleEntry($id)->output();
}
catch (Exception $exception)
catch (Throwable $e)
{
$this->handle_exception($exception);
}
@ -206,16 +206,16 @@ class Appointments extends API_V1_Controller {
{
try
{
$appointment = $this->appointments_model->get_row($id);
$service = $this->services_model->get_row($appointment['id_services']);
$provider = $this->providers_model->get_row($appointment['id_users_provider']);
$customer = $this->customers_model->get_row($appointment['id_users_customer']);
$appointment = $this->appointments_model->find($id);
$service = $this->services_model->find($appointment['id_services']);
$provider = $this->providers_model->find($appointment['id_users_provider']);
$customer = $this->customers_model->find($appointment['id_users_customer']);
$settings = [
'company_name' => $this->settings_model->get_setting('company_name'),
'company_email' => $this->settings_model->get_setting('company_email'),
'company_link' => $this->settings_model->get_setting('company_link'),
'date_format' => $this->settings_model->get_setting('date_format'),
'time_format' => $this->settings_model->get_setting('time_format')
'company_name' => setting('company_name'),
'company_email' => setting('company_email'),
'company_link' => setting('company_link'),
'date_format' => setting('date_format'),
'time_format' => setting('time_format')
];
$this->appointments_model->delete($id);
@ -230,7 +230,7 @@ class Appointments extends API_V1_Controller {
$response->output();
}
catch (Exception $exception)
catch (Throwable $e)
{
$this->handle_exception($exception);
}

View file

@ -43,20 +43,20 @@ class Availabilities extends API_V1_Controller {
{
try
{
$provider_id = $this->input->get('providerId');
$provider_id = request('providerId');
$service_id = $this->input->get('serviceId');
$service_id = request('serviceId');
$date = $this->input->get('date');
$date = request('date');
if ( ! $date)
{
$date = date('Y-m-d');
}
$provider = $this->providers_model->get_row($provider_id);
$provider = $this->providers_model->find($provider_id);
$service = $this->services_model->get_row($service_id);
$service = $this->services_model->find($service_id);
$available_hours = $this->availability->get_available_hours($date, $service, $provider);
@ -64,7 +64,7 @@ class Availabilities extends API_V1_Controller {
->set_content_type('application/json')
->set_output(json_encode($available_hours));
}
catch (Exception $exception)
catch (Throwable $e)
{
$this->handle_exception($exception);
}

View file

@ -69,7 +69,7 @@ class Categories extends API_V1_Controller {
->output();
}
catch (Exception $exception)
catch (Throwable $e)
{
$this->handle_exception($exception);
}
@ -100,7 +100,7 @@ class Categories extends API_V1_Controller {
$status = new NonEmptyText('201 Created');
$response->encode($this->parser)->singleEntry(TRUE)->output($status);
}
catch (Exception $exception)
catch (Throwable $e)
{
$this->handle_exception($exception);
}
@ -135,7 +135,7 @@ class Categories extends API_V1_Controller {
$response = new Response($batch);
$response->encode($this->parser)->singleEntry($id)->output();
}
catch (Exception $exception)
catch (Throwable $e)
{
$this->handle_exception($exception);
}
@ -159,7 +159,7 @@ class Categories extends API_V1_Controller {
$response->output();
}
catch (Exception $exception)
catch (Throwable $e)
{
$this->handle_exception($exception);
}

View file

@ -51,7 +51,7 @@ class Customers extends API_V1_Controller {
{
$conditions = $id !== NULL ? ['id' => $id] : NULL;
$customers = $this->customers_model->get_batch($conditions);
$customers = $this->customers_model->get($conditions);
if ($id !== NULL && count($customers) === 0)
{
@ -69,7 +69,7 @@ class Customers extends API_V1_Controller {
->output();
}
catch (Exception $exception)
catch (Throwable $e)
{
$this->handle_exception($exception);
}
@ -92,15 +92,15 @@ class Customers extends API_V1_Controller {
unset($customer['id']);
}
$id = $this->customers_model->add($customer);
$id = $this->customers_model->save($customer);
// Fetch the new object from the database and return it to the client.
$batch = $this->customers_model->get_batch(['id' => $id]);
$batch = $this->customers_model->get(['id' => $id]);
$response = new Response($batch);
$status = new NonEmptyText('201 Created');
$response->encode($this->parser)->singleEntry(TRUE)->output($status);
}
catch (Exception $exception)
catch (Throwable $e)
{
$this->handle_exception($exception);
}
@ -116,7 +116,7 @@ class Customers extends API_V1_Controller {
try
{
// Update the customer record.
$batch = $this->customers_model->get_batch(['id' => $id]);
$batch = $this->customers_model->get(['id' => $id]);
if ($id !== NULL && count($batch) === 0)
{
@ -128,14 +128,14 @@ class Customers extends API_V1_Controller {
$base_customer = $batch[0];
$this->parser->decode($updated_customer, $base_customer);
$updated_customer['id'] = $id;
$id = $this->customers_model->add($updated_customer);
$id = $this->customers_model->save($updated_customer);
// Fetch the updated object from the database and return it to the client.
$batch = $this->customers_model->get_batch(['id' => $id]);
$batch = $this->customers_model->get(['id' => $id]);
$response = new Response($batch);
$response->encode($this->parser)->singleEntry($id)->output();
}
catch (Exception $exception)
catch (Throwable $e)
{
$this->handle_exception($exception);
}
@ -159,7 +159,7 @@ class Customers extends API_V1_Controller {
$response->output();
}
catch (Exception $exception)
catch (Throwable $e)
{
$this->handle_exception($exception);
}

View file

@ -51,7 +51,7 @@ class Providers extends API_V1_Controller {
{
$conditions = $id !== NULL ? ['id' => $id] : NULL;
$providers = $this->providers_model->get_batch($conditions);
$providers = $this->providers_model->get($conditions);
if ($id !== NULL && count($providers) === 0)
{
@ -69,7 +69,7 @@ class Providers extends API_V1_Controller {
->output();
}
catch (Exception $exception)
catch (Throwable $e)
{
$this->handle_exception($exception);
}
@ -104,18 +104,18 @@ class Providers extends API_V1_Controller {
if ( ! array_key_exists('working_plan', $provider['settings']))
{
$provider['settings']['working_plan'] = $this->settings_model->get_setting('company_working_plan');
$provider['settings']['working_plan'] = setting('company_working_plan');
}
$id = $this->providers_model->add($provider);
$id = $this->providers_model->save($provider);
// Fetch the new object from the database and return it to the client.
$batch = $this->providers_model->get_batch(['id' => $id]);
$batch = $this->providers_model->get(['id' => $id]);
$response = new Response($batch);
$status = new NonEmptyText('201 Created');
$response->encode($this->parser)->singleEntry(TRUE)->output($status);
}
catch (Exception $exception)
catch (Throwable $e)
{
$this->handle_exception($exception);
}
@ -131,7 +131,7 @@ class Providers extends API_V1_Controller {
try
{
// Update the provider record.
$batch = $this->providers_model->get_batch(['id' => $id]);
$batch = $this->providers_model->get(['id' => $id]);
if ($id !== NULL && count($batch) === 0)
{
@ -143,14 +143,14 @@ class Providers extends API_V1_Controller {
$base_provider = $batch[0];
$this->parser->decode($updated_provider, $base_provider);
$updated_provider['id'] = $id;
$id = $this->providers_model->add($updated_provider);
$id = $this->providers_model->save($updated_provider);
// Fetch the updated object from the database and return it to the client.
$batch = $this->providers_model->get_batch(['id' => $id]);
$batch = $this->providers_model->get(['id' => $id]);
$response = new Response($batch);
$response->encode($this->parser)->singleEntry($id)->output();
}
catch (Exception $exception)
catch (Throwable $e)
{
$this->handle_exception($exception);
}
@ -174,7 +174,7 @@ class Providers extends API_V1_Controller {
$response->output();
}
catch (Exception $exception)
catch (Throwable $e)
{
$this->handle_exception($exception);
}

View file

@ -51,7 +51,7 @@ class Secretaries extends API_V1_Controller {
{
$conditions = $id !== NULL ? ['id' => $id] : NULL;
$secretaries = $this->secretaries_model->get_batch($conditions);
$secretaries = $this->secretaries_model->get($conditions);
if ($id !== NULL && count($secretaries) === 0)
{
@ -69,7 +69,7 @@ class Secretaries extends API_V1_Controller {
->output();
}
catch (Exception $exception)
catch (Throwable $e)
{
$this->handle_exception($exception);
}
@ -102,15 +102,15 @@ class Secretaries extends API_V1_Controller {
throw new Exception('No settings property provided.');
}
$id = $this->secretaries_model->add($secretary);
$id = $this->secretaries_model->save($secretary);
// Fetch the new object from the database and return it to the client.
$batch = $this->secretaries_model->get_batch(['id' => $id]);
$batch = $this->secretaries_model->get(['id' => $id]);
$response = new Response($batch);
$status = new NonEmptyText('201 Created');
$response->encode($this->parser)->singleEntry(TRUE)->output($status);
}
catch (Exception $exception)
catch (Throwable $e)
{
$this->handle_exception($exception);
}
@ -126,7 +126,7 @@ class Secretaries extends API_V1_Controller {
try
{
// Update the secretary record.
$batch = $this->secretaries_model->get_batch(['id' => $id]);
$batch = $this->secretaries_model->get(['id' => $id]);
if ($id !== NULL && count($batch) === 0)
{
@ -138,14 +138,14 @@ class Secretaries extends API_V1_Controller {
$base_secretary = $batch[0];
$this->parser->decode($updated_secretary, $base_secretary);
$updated_secretary['id'] = $id;
$id = $this->secretaries_model->add($updated_secretary);
$id = $this->secretaries_model->save($updated_secretary);
// Fetch the updated object from the database and return it to the client.
$batch = $this->secretaries_model->get_batch(['id' => $id]);
$batch = $this->secretaries_model->get(['id' => $id]);
$response = new Response($batch);
$response->encode($this->parser)->singleEntry($id)->output();
}
catch (Exception $exception)
catch (Throwable $e)
{
$this->handle_exception($exception);
}
@ -169,7 +169,7 @@ class Secretaries extends API_V1_Controller {
$response->output();
}
catch (Exception $exception)
catch (Throwable $e)
{
$this->handle_exception($exception);
}

View file

@ -51,7 +51,7 @@ class Services extends API_V1_Controller {
{
$conditions = $id !== NULL ? ['id' => $id] : NULL;
$services = $this->services_model->get_batch($conditions);
$services = $this->services_model->get($conditions);
if ($id !== NULL && count($services) === 0)
{
@ -69,7 +69,7 @@ class Services extends API_V1_Controller {
->output();
}
catch (Exception $exception)
catch (Throwable $e)
{
$this->handle_exception($exception);
}
@ -92,15 +92,15 @@ class Services extends API_V1_Controller {
unset($service['id']);
}
$id = $this->services_model->add($service);
$id = $this->services_model->save($service);
// Fetch the new object from the database and return it to the client.
$batch = $this->services_model->get_batch(['id' => $id]);
$batch = $this->services_model->get(['id' => $id]);
$response = new Response($batch);
$status = new NonEmptyText('201 Created');
$response->encode($this->parser)->singleEntry(TRUE)->output($status);
}
catch (Exception $exception)
catch (Throwable $e)
{
$this->handle_exception($exception);
}
@ -116,7 +116,7 @@ class Services extends API_V1_Controller {
try
{
// Update the service record.
$batch = $this->services_model->get_batch(['id' => $id]);
$batch = $this->services_model->get(['id' => $id]);
if ($id !== NULL && count($batch) === 0)
{
@ -128,14 +128,14 @@ class Services extends API_V1_Controller {
$base_service = $batch[0];
$this->parser->decode($updated_service, $base_service);
$updated_service['id'] = $id;
$id = $this->services_model->add($updated_service);
$id = $this->services_model->save($updated_service);
// Fetch the updated object from the database and return it to the client.
$batch = $this->services_model->get_batch(['id' => $id]);
$batch = $this->services_model->get(['id' => $id]);
$response = new Response($batch);
$response->encode($this->parser)->singleEntry($id)->output();
}
catch (Exception $exception)
catch (Throwable $e)
{
$this->handle_exception($exception);
}
@ -159,7 +159,7 @@ class Services extends API_V1_Controller {
$response->output();
}
catch (Exception $exception)
catch (Throwable $e)
{
$this->handle_exception($exception);
}

View file

@ -48,7 +48,7 @@ class Settings extends API_V1_Controller {
{
try
{
$settings = $this->settings_model->get_settings();
$settings = $this->settings_model->get();
if ($name !== NULL)
{
@ -86,7 +86,7 @@ class Settings extends API_V1_Controller {
->output();
}
catch (Exception $exception)
catch (Throwable $e)
{
$this->handle_exception($exception);
}
@ -114,7 +114,7 @@ class Settings extends API_V1_Controller {
]);
$response->encode($this->parser)->singleEntry($name)->output();
}
catch (Exception $exception)
catch (Throwable $e)
{
$this->handle_exception($exception);
}
@ -138,7 +138,7 @@ class Settings extends API_V1_Controller {
$response->output();
}
catch (Exception $exception)
catch (Throwable $e)
{
$this->handle_exception($exception);
}

View file

@ -51,7 +51,7 @@ class Unavailabilities extends API_V1_Controller {
{
$where = $id !== NULL ? ['id' => $id] : ['is_unavailable' => TRUE];
$unavailabilities = $this->appointments_model->get_batch($where);
$unavailabilities = $this->appointments_model->get($where);
if ($id !== NULL && count($unavailabilities) === 0)
{
@ -69,7 +69,7 @@ class Unavailabilities extends API_V1_Controller {
->output();
}
catch (Exception $exception)
catch (Throwable $e)
{
$this->handle_exception($exception);
}
@ -95,12 +95,12 @@ class Unavailabilities extends API_V1_Controller {
$id = $this->appointments_model->add_unavailable($unavailability);
// Fetch the new object from the database and return it to the client.
$batch = $this->appointments_model->get_batch(['id' => $id]);
$batch = $this->appointments_model->get(['id' => $id]);
$response = new Response($batch);
$status = new NonEmptyText('201 Created');
$response->encode($this->parser)->singleEntry(TRUE)->output($status);
}
catch (Exception $exception)
catch (Throwable $e)
{
$this->handle_exception($exception);
}
@ -116,7 +116,7 @@ class Unavailabilities extends API_V1_Controller {
try
{
// Update the appointment record.
$batch = $this->appointments_model->get_batch(['id' => $id]);
$batch = $this->appointments_model->get(['id' => $id]);
if ($id !== NULL && count($batch) === 0)
{
@ -131,11 +131,11 @@ class Unavailabilities extends API_V1_Controller {
$id = $this->appointments_model->add_unavailable($updatedUnavailability);
// Fetch the updated object from the database and return it to the client.
$batch = $this->appointments_model->get_batch(['id' => $id]);
$batch = $this->appointments_model->get(['id' => $id]);
$response = new Response($batch);
$response->encode($this->parser)->singleEntry($id)->output();
}
catch (Exception $exception)
catch (Throwable $e)
{
$this->handle_exception($exception);
}
@ -159,7 +159,7 @@ class Unavailabilities extends API_V1_Controller {
$response->output();
}
catch (Exception $exception)
catch (Throwable $e)
{
$this->handle_exception($exception);
}