From 86dca97f3f08cb1be3764e6ba6c7ec82a1b40ee6 Mon Sep 17 00:00:00 2001 From: mikael-zakaria Date: Fri, 1 Aug 2025 22:33:41 +0700 Subject: [PATCH] Update Perbaikan Controller Patient & Routes --- app/Config/Routes.php | 4 ++-- app/Controllers/Patient.php | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index aae5441..2652364 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -16,8 +16,8 @@ $routes->post('/auth/register/', 'Auth::register'); $routes->get('/api/patient', 'Patient::index'); $routes->post('/api/patient', 'Patient::create'); -$routes->get('/api/patient/(:any)', 'Patient::show/$1'); -$routes->delete('/api/patient/(:any)', 'Patient::delete/$1'); +$routes->get('/api/patient/(:num)', 'Patient::show/$1'); +$routes->delete('/api/patient/(:num)', 'Patient::delete/$1'); $routes->patch('/api/patient/(:num)', 'Patient::update/$1'); $routes->get('/api/race', 'Race::index'); diff --git a/app/Controllers/Patient.php b/app/Controllers/Patient.php index 66a531e..4aeb5d6 100644 --- a/app/Controllers/Patient.php +++ b/app/Controllers/Patient.php @@ -63,7 +63,7 @@ class Patient extends Controller { } catch (\Exception $e) { // Error Server Mengembalikan 500 - return $this->failServerError('Something went wrong.'); + return $this->failServerError('Something went wrong.'.$e->getMessage()); } } @@ -73,7 +73,7 @@ class Patient extends Controller { try { $builder = $this->db->table('patient'); - $patient = $builder->where('InternalPID', $InternalPID)->get()->getRowArray(); + $patient = $builder->where('InternalPID', ((int) $InternalPID))->get()->getRowArray(); // Data pasien tidak ada mengembalikan - success 200 if (empty($patient)) { @@ -94,7 +94,7 @@ class Patient extends Controller { } catch (\Exception $e) { // Error Server Mengembalikan 500 - return $this->failServerError('Something went wrong'); + return $this->failServerError('Something went wrong'.$e->getMessage()); } } @@ -182,14 +182,17 @@ class Patient extends Controller { } catch (\Exception $e) { // Error Server = 500 - return $this->failServerError('Something went wrong'.$e); + return $this->failServerError('Something went wrong'.$e->getMessage()); } } - // OK + // OK - Done public function update($InternalPID = null) { try { + + $InternalPID = (int) $InternalPID; + $input = $this->request->getJSON(true); $data = [ @@ -286,14 +289,16 @@ class Patient extends Controller { } catch (\Exception $e) { // Error Server = 500 - return $this->failServerError('Something went wrong '.$e); + return $this->failServerError('Something went wrong '.$e->getMessage()); } } - // OK + // OK - Done public function delete($InternalPID = null) { try { + + $InternalPID = (int) $InternalPID; if (!$InternalPID) { return $this->failValidationError('Patient ID is required.');