diff --git a/Sources/src/data/model/manager/UserManager.php b/Sources/src/data/model/manager/UserManager.php index 72b774d0..1db65906 100644 --- a/Sources/src/data/model/manager/UserManager.php +++ b/Sources/src/data/model/manager/UserManager.php @@ -7,6 +7,7 @@ use Model\Coach; use Model\User; use Network\IAuthService; use Shared\Validation; +use Stub\UserRepository; // c'est le modéle // should be here try catch ?? @@ -18,6 +19,8 @@ class UserManager private User $currentUser; + private UserRepository $userRepo + public function __construct(IAuthService $authService,IFriendRequestService $friendService) { $this->authService = $authService; @@ -35,11 +38,20 @@ class UserManager } public function addFriends($newFriendId) { - // should verifie si l'user exist si il existe pas return paas ajouter - // verifier si il est pas déja dans la liste des amis - // - $this->friendService->sendRequest($this->currentUser->getId(), $newFriendId); - // if est bien ajouter + foreach($u in $this->userRepo->getItems()){ + if($u->getId()==$newFriendId){ + throw new \Exception("User non existing"); + } + } + foreach($u in $this->currentUser->getFriendsList()){ + if($newFriendId==$u->getId()){ + throw new \Exception("Already friend"); + } + } + if($this->friendService->sendRequest($this->currentUser->getId(), $newFriendId)==true){ + return true; + } + return false; } public function register($loginUser, $passwordUser,$data): bool @@ -88,6 +100,25 @@ class UserManager } return false; } + public function searchUsersByName(string $name) : array{ + $list=array(); + foreach($u in $this->currentUser->getFriendsList()){ + if(strcasecmp($name,$u->getNom())==0 || strcasecmp($name,$u->getPrenom())==0){ + array_push($list, $u); + return true; + } + } + return $list; + } + public function deleteFriend(int $id){ + foreach($u in $this->currentUser->getFriendsList()){ + if($id==$u->getId()){ + unset($u); + return true; + } + } + return false; + } }