From 6cc90d281f582ebf555e82dbda4ac4734130ab26 Mon Sep 17 00:00:00 2001 From: Pierre Date: Sun, 11 Mar 2018 10:57:01 +0100 Subject: [PATCH] Can get informations about a specific user --- RestControllers/friendsController.php | 23 +++++++++++++++++++++++ classes/components/friends.php | 14 ++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/RestControllers/friendsController.php b/RestControllers/friendsController.php index ac5b496..1039218 100644 --- a/RestControllers/friendsController.php +++ b/RestControllers/friendsController.php @@ -79,6 +79,29 @@ class friendsController{ return $IDs; } + /** + * Get friendship informations about a specific friend + * + * @url POST /friends/get_single_infos + */ + public function get_single_infos(){ + + user_login_required(); + + //Get friendID + $friendID = getPostUserID('friendID'); + + //Get informations about the friendship + $list = components()->friends->getList(userID, $friendID); + + //Check if the friend was found or not + if(count($list) == 0) + Rest_fatal_error(404, "Specified friend not found !"); + + //Return informations about the friend + return $this->parseFriendAPI($list[0], true); + } + /** * Send a friendship request * diff --git a/classes/components/friends.php b/classes/components/friends.php index dc288e6..8999823 100644 --- a/classes/components/friends.php +++ b/classes/components/friends.php @@ -28,15 +28,25 @@ class friends { * Get and returns the list of the friends of a user * * @param int $userID The ID of the user + * @param int $friendID The ID of a specific friend (default -1) * @return array The list of the friends of the user (Friend objects) */ - public function getList(int $userID) : array { + public function getList(int $userID, int $friendID = -1) : array { //Prepare the request on the database $tableName = $this->friendsTable.", utilisateurs"; - $condition = "WHERE ID_personne = ? AND amis.ID_amis = utilisateurs.ID ORDER BY utilisateurs.last_activity DESC"; + $condition = "WHERE ID_personne = ? AND amis.ID_amis = utilisateurs.ID "; $condValues = array($userID); + //Check if the request is targeting a specific friend + if($friendID != -1){ + $condition .= " AND ID_amis = ?"; + $condValues[] = $friendID; + } + + //Complete conditions + $condition .= "ORDER BY utilisateurs.last_activity DESC"; + //Specify which fields to get $fieldsList = array( "utilisateurs.last_activity",