diff --git a/app/Controllers/Api/ZonesApi.php b/app/Controllers/Api/ZonesApi.php index 934c7c6..5752529 100644 --- a/app/Controllers/Api/ZonesApi.php +++ b/app/Controllers/Api/ZonesApi.php @@ -15,18 +15,27 @@ class ZonesApi extends BaseController { } public function getProvinces() { + $filters = [ + 'zoneid' => $this->request->getVar('zoneid') ?? null, + 'zonename' => $this->request->getVar('zonename') ?? null + ]; - $rows = $this->model->getAllProvinces(); + $rows = $this->model->getAllProvinces($filters); - if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); } + 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); } public function getCities() { - $rows = $this->model->getAllCities(); + $filters = [ + 'zoneid' => $this->request->getVar('zoneid') ?? null, + 'zonename' => $this->request->getVar('zonename') ?? null + ]; + + $rows = $this->model->getAllCities($filters); - if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); } + 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); } } \ No newline at end of file diff --git a/app/Models/ZonesModel.php b/app/Models/ZonesModel.php index 4d99912..f6fb33a 100644 --- a/app/Models/ZonesModel.php +++ b/app/Models/ZonesModel.php @@ -8,14 +8,30 @@ class ZonesModel extends Model { 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 getAllProvinces($filters = []) { + $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'); + } + + return $this->findAll(); } - public function getAllCities() { - $rows = $this->select('zoneid, zonename')->where('parentzoneid IS NOT NULL', null, false)->findAll(); - return $rows; + public function getAllCities($filters = []) { + $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'); + } + + return $this->findAll(); } } \ No newline at end of file