From 34449ec836f8aa57ace2fe9b8cedfb05d1906d3a Mon Sep 17 00:00:00 2001 From: mikael-zakaria Date: Wed, 22 Oct 2025 10:23:46 +0700 Subject: [PATCH] Update Zones Api Perbaikan hanya get cities pakai Params zoneid saja --- app/Controllers/Api/ZonesApi.php | 17 ++++++++--------- app/Models/ZonesModel.php | 23 ++++++++++------------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/app/Controllers/Api/ZonesApi.php b/app/Controllers/Api/ZonesApi.php index 5752529..297fd62 100644 --- a/app/Controllers/Api/ZonesApi.php +++ b/app/Controllers/Api/ZonesApi.php @@ -15,12 +15,12 @@ class ZonesApi extends BaseController { } public function getProvinces() { - $filters = [ - 'zoneid' => $this->request->getVar('zoneid') ?? null, - 'zonename' => $this->request->getVar('zonename') ?? null - ]; + // $filters = [ + // 'zoneid' => $this->request->getVar('zoneid') ?? null, + // 'zonename' => $this->request->getVar('zonename') ?? null + // ]; - $rows = $this->model->getAllProvinces($filters); + $rows = $this->model->getAllProvinces(); if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "data not found", 'data' => [] ], 200); } return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200); @@ -28,12 +28,11 @@ class ZonesApi extends BaseController { public function getCities() { - $filters = [ - 'zoneid' => $this->request->getVar('zoneid') ?? null, - 'zonename' => $this->request->getVar('zonename') ?? null + $filter = [ + 'zoneid' => $this->request->getVar('zoneid') ?? null ]; - $rows = $this->model->getAllCities($filters); + $rows = $this->model->getAllCities($filter); if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "data not found", 'data' => [] ], 200); } return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200); diff --git a/app/Models/ZonesModel.php b/app/Models/ZonesModel.php index f6fb33a..773460f 100644 --- a/app/Models/ZonesModel.php +++ b/app/Models/ZonesModel.php @@ -8,27 +8,24 @@ class ZonesModel extends Model { protected $primaryKey = 'zoneid'; protected $allowedFields = [ 'zonecode', 'zoneclass', 'parentzoneid', 'zonename' ]; - public function getAllProvinces($filters = []) { + public function getAllProvinces() { $this->select('zoneid, zonename')->where('parentzoneid IS NULL', null, false); - if (!empty($filters['zoneid'])) { - $this->where('zoneid', $filters['zoneid']); - } - if (!empty($filters['zonename'])) { - $this->like('zonename', $filters['zonename'], 'both'); - } + // if (!empty($filters['zoneid'])) { + // $this->where('zoneid', $filters['zoneid']); + // } + // if (!empty($filters['zonename'])) { + // $this->like('zonename', $filters['zonename'], 'both'); + // } return $this->findAll(); } - public function getAllCities($filters = []) { + public function getAllCities($filter = []) { $rows = $this->select('zoneid, zonename')->where('parentzoneid IS NOT NULL', null, false); - if (!empty($filters['zoneid'])) { - $this->where('zoneid', $filters['zoneid']); - } - if (!empty($filters['zonename'])) { - $this->like('zonename', $filters['zonename'], 'both'); + if (!empty($filter['zoneid'])) { + $this->where('parentzoneid', $filter['zoneid']); } return $this->findAll();