model = new LocationModel($database->getConnection()); } public function insertLocation(array $post): void { if (empty($post['country']) || empty($post['town']) || !is_numeric($post['delivery_price'])) { $this->jsonResponse(false, 'All fields are required and must be valid.'); return; } if ($this->model->insert($post)) { $this->jsonResponse(true, 'Location added successfully.'); } else { $this->jsonResponse(false, 'Failed to add location.'); } } public function updateLocation(array $post): void { if (empty($post['id']) || empty($post['country']) || empty($post['town']) || !is_numeric($post['delivery_price'])) { $this->jsonResponse(false, 'Invalid data provided.'); return; } if ($this->model->update($post)) { $this->jsonResponse(true, 'Location updated successfully.'); } else { $this->jsonResponse(false, 'Update failed.'); } } public function deleteDeliveryLocation(int $id): void { if ($this->model->delete($id)) { $this->jsonResponse(true, 'Location deleted.'); } else { $this->jsonResponse(false, 'Failed to delete location.'); } } public function deleteFooter(int $id): void { if ($this->model->deleteFooter($id)) { $this->jsonResponse(true, 'Footer location deleted.'); } else { $this->jsonResponse(false, 'Could not delete footer location.'); } } private function jsonResponse(bool $success, string $message): void { echo json_encode([ 'status' => $success ? 'success' : 'error', 'message' => $message ]); } }