From b88b5873583afb651482a223036bf8c6867acb84 Mon Sep 17 00:00:00 2001 From: mikael-zakaria Date: Tue, 21 Oct 2025 15:27:22 +0700 Subject: [PATCH] Update API Zones for city and province --- app/Config/Routes.php | 4 ++++ app/Controllers/Api/ZonesApi.php | 32 ++++++++++++++++++++++++++++++++ app/Models/ZonesModel.php | 12 ++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 app/Controllers/Api/ZonesApi.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 8220e7a..e25dfc8 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -256,10 +256,14 @@ $routes->group('', ['filter' => 'cors'], function($routes) { }); // REST API +$routes->get('/api/provinces', 'Api\ZonesApi::getProvinces'); +$routes->get('/api/cities', 'Api\ZonesApi::getCities'); +// $routes->get('/api/zones', 'Api::ZonesApi/'); // $routes->get('/api/getProductList', 'Api::getProductList'); $routes->get('/api/getProductAlias', 'Api::getProductAlias'); $routes->get('/api/getProductSites', 'Api::getProductSites'); + //CLQMS // $routes->get('/clqms', 'Clqms::index'); // for CLQMS Inst select /* diff --git a/app/Controllers/Api/ZonesApi.php b/app/Controllers/Api/ZonesApi.php new file mode 100644 index 0000000..934c7c6 --- /dev/null +++ b/app/Controllers/Api/ZonesApi.php @@ -0,0 +1,32 @@ +model = new ZonesModel(); + } + + public function getProvinces() { + + $rows = $this->model->getAllProvinces(); + + if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); } + return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200); + } + + public function getCities() { + + $rows = $this->model->getAllCities(); + + if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); } + return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200); + } +} \ No newline at end of file diff --git a/app/Models/ZonesModel.php b/app/Models/ZonesModel.php index c607bc7..4d99912 100644 --- a/app/Models/ZonesModel.php +++ b/app/Models/ZonesModel.php @@ -3,7 +3,19 @@ use CodeIgniter\Model; class ZonesModel extends Model { + protected $table = 'zones'; protected $primaryKey = 'zoneid'; protected $allowedFields = [ 'zonecode', 'zoneclass', 'parentzoneid', 'zonename' ]; + + public function getAllProvinces() { + $rows = $this->select('zoneid, zonename')->where('parentzoneid IS NULL', null, false)->findAll(); + return $rows; + } + + public function getAllCities() { + $rows = $this->select('zoneid, zonename')->where('parentzoneid IS NOT NULL', null, false)->findAll(); + return $rows; + } + } \ No newline at end of file