model = new BlockFavModel(); } public function toggleFavoriteBlock($params) { if (!isset($params['catalogId']) || !isset($params['blockId']) || !isset($this->post->isFavorite)) { return $this->response(['error' => 'Missing parameters'], 400); } // Валидация и санитизация входных данных $catalogId = intval($params['catalogId']); $blockId = intval($params['blockId']); $isFavorite = filter_var($this->post->isFavorite, FILTER_VALIDATE_BOOLEAN); // Проверка корректности данных if ($catalogId <= 0 || $blockId <= 0) { return $this->response(['error' => 'Invalid catalogId or blockId'], 400); } $result = $this->model->toggleFavoriteBlock($catalogId, $blockId, $isFavorite); if (count($result)) { return $this->response(['success' => true]); } else { return $this->response(['success' => false]); } } }