Update Zones Api With Params zoneid & zonename

This commit is contained in:
mikael-zakaria 2025-10-22 10:09:31 +07:00
parent 9deab403d7
commit f4961f862e
2 changed files with 35 additions and 10 deletions

View File

@ -15,18 +15,27 @@ class ZonesApi extends BaseController {
} }
public function getProvinces() { 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); return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200);
} }
public function getCities() { 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); return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200);
} }
} }

View File

@ -8,14 +8,30 @@ class ZonesModel extends Model {
protected $primaryKey = 'zoneid'; protected $primaryKey = 'zoneid';
protected $allowedFields = [ 'zonecode', 'zoneclass', 'parentzoneid', 'zonename' ]; protected $allowedFields = [ 'zonecode', 'zoneclass', 'parentzoneid', 'zonename' ];
public function getAllProvinces() { public function getAllProvinces($filters = []) {
$rows = $this->select('zoneid, zonename')->where('parentzoneid IS NULL', null, false)->findAll(); $this->select('zoneid, zonename')->where('parentzoneid IS NULL', null, false);
return $rows;
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() { public function getAllCities($filters = []) {
$rows = $this->select('zoneid, zonename')->where('parentzoneid IS NOT NULL', null, false)->findAll(); $rows = $this->select('zoneid, zonename')->where('parentzoneid IS NOT NULL', null, false);
return $rows;
if (!empty($filters['zoneid'])) {
$this->where('zoneid', $filters['zoneid']);
}
if (!empty($filters['zonename'])) {
$this->like('zonename', $filters['zonename'], 'both');
}
return $this->findAll();
} }
} }