mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-11-24 06:19:29 +00:00
59 lines
1.2 KiB
PHP
59 lines
1.2 KiB
PHP
|
<?php
|
||
|
/**
|
||
|
* API likes controller
|
||
|
*
|
||
|
* @author Pierre HUBERT
|
||
|
*/
|
||
|
|
||
|
class likesController {
|
||
|
|
||
|
/**
|
||
|
* Update a specific component like
|
||
|
*
|
||
|
* @url POST /likes/update
|
||
|
*/
|
||
|
public function update_like(){
|
||
|
|
||
|
user_login_required(); //Need login
|
||
|
|
||
|
//Get component kind
|
||
|
if(!isset($_POST["type"]))
|
||
|
Rest_fatal_error(401, "Please specify like type !");
|
||
|
|
||
|
$type = $_POST["type"];
|
||
|
|
||
|
//Check new status for the like
|
||
|
if(!isset($_POST['like']))
|
||
|
Rest_fatal_error(400, "Please specify the new like status with the request !");
|
||
|
$like = $_POST['like'] == "true";
|
||
|
|
||
|
//Find the right component type for checks
|
||
|
switch($type){
|
||
|
|
||
|
//In case of user
|
||
|
case "user":
|
||
|
|
||
|
//Extract informations
|
||
|
$id = getPostUserId("id");
|
||
|
$componentType = Likes::LIKE_USER;
|
||
|
|
||
|
//Check if user can access page
|
||
|
if(!CS::get()->components->user->userAllowed(userID, $id))
|
||
|
Rest_fatal_error(401, "You can not access this user information !");
|
||
|
|
||
|
break;
|
||
|
|
||
|
|
||
|
//Default case : error
|
||
|
default:
|
||
|
Rest_fatal_error(404, "Didn't find specified component type !");
|
||
|
}
|
||
|
|
||
|
//Update like status
|
||
|
CS::get()->components->likes->update(userID, $like, $id, $componentType);
|
||
|
|
||
|
//Success
|
||
|
return array("success" => "Like status updated.");
|
||
|
}
|
||
|
|
||
|
}
|