38 lines
1.4 KiB
PHP
38 lines
1.4 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
class ApartmentFavController extends BaseController
|
||
|
|
{
|
||
|
|
public $model = null;
|
||
|
|
|
||
|
|
public function __construct() {
|
||
|
|
parent::__construct();
|
||
|
|
$this->model = new ApartmentFavModel();
|
||
|
|
}
|
||
|
|
|
||
|
|
public function toggleFavoriteApartment($params) {
|
||
|
|
// return $this->response(json_decode(file_get_contents("php://input")));
|
||
|
|
// Проверка существования параметров
|
||
|
|
|
||
|
|
if (!isset($params['catalogId']) || !isset($params['apartmentId']) || !isset($this->post->isFavorite)) {
|
||
|
|
return $this->response(['error' => 'Missing parameters'], 400);
|
||
|
|
}
|
||
|
|
|
||
|
|
// Валидация и санитизация входных данных
|
||
|
|
$catalogId = intval($params['catalogId']);
|
||
|
|
$apartmentId = intval($params['apartmentId']);
|
||
|
|
$isFavorite = filter_var($this->post->isFavorite, FILTER_VALIDATE_BOOLEAN);
|
||
|
|
|
||
|
|
// Проверка корректности данных
|
||
|
|
if ($catalogId <= 0 || $apartmentId <= 0) {
|
||
|
|
return $this->response(['error' => 'Invalid catalogId or apartmentId'], 400);
|
||
|
|
}
|
||
|
|
|
||
|
|
$result = $this->model->toggleFavoriteApartment($catalogId, $apartmentId, $isFavorite);
|
||
|
|
if ($result) {
|
||
|
|
return $this->response(['success' => true]);
|
||
|
|
} else {
|
||
|
|
return $this->response(['success' => false]);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|