Joywork/presentation-api/Controllers/BlockFavController.php

38 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2026-05-22 20:21:54 +02:00
<?php
class BlockFavController extends BaseController
{
public $model = null;
public function __construct() {
parent::__construct();
$this->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]);
}
}
}