mirror of
				https://github.com/pierre42100/ComunicAPI
				synced 2025-11-04 04:04:20 +00:00 
			
		
		
		
	Created remove a friend method
This commit is contained in:
		@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -124,7 +124,7 @@ class friends {
 | 
			
		||||
	 * @param Integer $friendID The destination of the request
 | 
			
		||||
	 * @return Boolean True or false depending of the success of the operation
 | 
			
		||||
	 */
 | 
			
		||||
	 public function checkFriendShipRequestExistence($userID, $friendID){
 | 
			
		||||
	public function checkFriendShipRequestExistence($userID, $friendID){
 | 
			
		||||
		//Perform a request on the database
 | 
			
		||||
		$conditions = "WHERE ID_personne = ? AND ID_amis = ? AND actif = 0";
 | 
			
		||||
		$dataConditions = array(
 | 
			
		||||
@@ -143,7 +143,27 @@ class friends {
 | 
			
		||||
		//Else we check the results
 | 
			
		||||
		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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user