Ajout des fonctions
continuous-integration/drone/push Build is passing Details

issue_a
Paul LEVRAULT 1 year ago
parent cd927ed11c
commit 95593ae528

@ -7,6 +7,7 @@ use Model\Coach;
use Model\User; use Model\User;
use Network\IAuthService; use Network\IAuthService;
use Shared\Validation; use Shared\Validation;
use Stub\UserRepository;
// c'est le modéle // c'est le modéle
// should be here try catch ?? // should be here try catch ??
@ -18,6 +19,8 @@ class UserManager
private User $currentUser; private User $currentUser;
private UserRepository $userRepo
public function __construct(IAuthService $authService,IFriendRequestService $friendService) public function __construct(IAuthService $authService,IFriendRequestService $friendService)
{ {
$this->authService = $authService; $this->authService = $authService;
@ -35,11 +38,20 @@ class UserManager
} }
public function addFriends($newFriendId) { public function addFriends($newFriendId) {
// should verifie si l'user exist si il existe pas return paas ajouter foreach($u in $this->userRepo->getItems()){
// verifier si il est pas déja dans la liste des amis if($u->getId()==$newFriendId){
// throw new \Exception("User non existing");
$this->friendService->sendRequest($this->currentUser->getId(), $newFriendId); }
// if est bien ajouter }
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 public function register($loginUser, $passwordUser,$data): bool
@ -88,6 +100,25 @@ class UserManager
} }
return false; 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;
}
} }

Loading…
Cancel
Save