mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-11-27 15:59:29 +00:00
Created remove a friend method
This commit is contained in:
parent
310136c3b6
commit
2a9f0ed1a0
@ -56,4 +56,27 @@ class friendsController{
|
||||
return array("success" => "A response was given to friendship request !");
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a friend from the list
|
||||
*
|
||||
* @url POST /friends/remove
|
||||
*/
|
||||
public function delete(){
|
||||
user_login_required(); //Login required
|
||||
|
||||
//Check input parametres
|
||||
if(!isset($_POST['friendID']))
|
||||
Rest_fatal_error(400, "Please specify the ID of the friend to delete !");
|
||||
|
||||
//Delete the friend from the list
|
||||
$friendID = toInt($_POST['friendID']);
|
||||
$result = CS::get()->components->friends->remove(userID, $friendID);
|
||||
|
||||
//Check if the operation is a result
|
||||
if(!$result)
|
||||
Rest_fatal_error(500, "Couldn't remove user from the friendlist for an unexcepted reason !");
|
||||
else
|
||||
return array("success" => "The friend was removed from the list !");
|
||||
}
|
||||
|
||||
}
|
@ -487,7 +487,7 @@ class DBLibrary {
|
||||
* @param Array $conditionsValues The values of condition
|
||||
* @return Boolean True if succeed
|
||||
*/
|
||||
public function deleteEntry($tableName, $conditions = false, array $conditionsValues = array()) {
|
||||
public function deleteEntry(string $tableName, $conditions = false, array $conditionsValues = array()) : bool {
|
||||
//We try to perform the task
|
||||
try{
|
||||
//We check if any database is opened
|
||||
|
@ -144,6 +144,26 @@ class friends {
|
||||
else
|
||||
return count($results) === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a friend from the firends list
|
||||
*
|
||||
* @param int $userID The ID of the user who delete the friend
|
||||
* @param int $friendID The ID of the friend that is being removed from the list
|
||||
* @return bool True if the user was successfully removed / false else
|
||||
*/
|
||||
public function remove(int $userID, int $friendID) : bool {
|
||||
|
||||
//Delete the friend from the database
|
||||
$tableName = $this->friendsTable;
|
||||
$conditions = "(ID_personne = ? AND ID_amis = ?) OR (ID_personne = ? AND ID_amis = ?)";
|
||||
$condValues = array($userID, $friendID, $friendID, $userID);
|
||||
|
||||
//Try to perform the request
|
||||
$success = CS::get()->db->deleteEntry($tableName, $conditions, $condValues);
|
||||
|
||||
return $success;
|
||||
}
|
||||
}
|
||||
|
||||
//Register component
|
||||
|
Loading…
Reference in New Issue
Block a user