Can remove a previously sent frienship request.

This commit is contained in:
Pierre 2017-12-23 09:03:00 +01:00
parent 235428982d
commit 9fb9b30b1f
2 changed files with 46 additions and 0 deletions

View File

@ -66,6 +66,33 @@ class friendsController{
}
/**
* Remove a previously send frienship request
*
* @url POST /friends/removeRequest
*/
public function removeRequest(){
user_login_required(); //Login required
//Check parametres
if(!isset($_POST["friendID"]))
Rest_fatal_error(400, "Please specify a user ID !");
//Extract informations and process request
$friendID = toInt($_POST['friendID']);
//Check if the current user has sent a request to the other user
if(!CS::get()->components->friends->sent_request(userID, $friendID))
Rest_fatal_error(401, "You didn't send a friendship request to this user !");
//Try to remove the friendship request
if(!CS::get()->components->friends->remove_request(userID, $friendID))
Rest_fatal_error(500, "An error occured while trying to remove the friendship request !");
//This is a success
return array("success" => "The friendship request has been removed!");
}
/**
* Respond to a friendship request
*

View File

@ -208,6 +208,25 @@ class friends {
}
/**
* Delete a friendship request previously created
*
* @param $userID The ID of the user removing its request
* @param $targetID The ID of the target of the request
* @return TRUE in case of success / false else
*/
public function remove_request(int $userID, int $targetID) : bool {
//Prepare the request on the database
$tableName = $this->friendsTable;
$conditions = "ID_personne = ? AND ID_amis = ? AND actif = 0";
$values = array($targetID, $userID);
//Try to perform the request
return CS::get()->db->deleteEntry($tableName, $conditions, $values);
}
/**
* Check wether a user has sent a friendship
* request to another friend