From f4325bfb4f0d2b251d0a841cdee5f0b05ed54d8e Mon Sep 17 00:00:00 2001 From: afornerot Date: Fri, 3 Jul 2020 10:30:41 +0200 Subject: [PATCH] rest users & groups --- .../CoreBundle/Controller/RestController.php | 66 ++++++++++++++++++- .../CoreBundle/Resources/config/routing.yml | 10 ++- 2 files changed, 72 insertions(+), 4 deletions(-) diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/RestController.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/RestController.php index 440b12f0..75ac2da8 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/RestController.php +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/RestController.php @@ -66,7 +66,7 @@ class RestController extends Controller // Construction de la réponse $output["user"]["firstname"] = $user->getFirstname(); - $output["user"]["lasttname"] = $user->getLastname(); + $output["user"]["lastname"] = $user->getLastname(); $output["user"]["email"] = $user->getEmail(); $output["user"]["avatar"] = $weburl."uploads/avatar/".$user->getAvatar(); $output["user"]["niveau01"] = $user->getNiveau01()->getLabel(); @@ -127,10 +127,70 @@ class RestController extends Controller } } - - // Retour return new Response(json_encode($output), 200); } + + public function usersAction($key, Request $request) + { + // Vérification de la clé + $realkey = $this->getParameter("apikeyninegate"); + if($key!=$realkey) { + $output["error"]="error key"; + return new Response(json_encode($output), 400); + } + + $weburl="https://".$this->getParameter("weburl")."/".$this->getParameter("alias")."/"; + + $em = $this->getDoctrine()->getManager(); + $output = []; + + $users=$em->getRepository('CadolesCoreBundle:User')->findAll(); + + foreach($users as $user) { + // Construction de la réponse + $output[$user->getId()]["id"] = $user->getId(); + $output[$user->getId()]["username"] = $user->getUsername(); + $output[$user->getId()]["firstname"] = $user->getFirstname(); + $output[$user->getId()]["lastname"] = $user->getLastname(); + $output[$user->getId()]["email"] = $user->getEmail(); + $output[$user->getId()]["avatar"] = $weburl."uploads/avatar/".$user->getAvatar(); + } + + // Retour + return new Response(json_encode($output), 200); + } + + public function groupsAction($key, Request $request) + { + // Vérification de la clé + $realkey = $this->getParameter("apikeyninegate"); + if($key!=$realkey) { + $output["error"]="error key"; + return new Response(json_encode($output), 400); + } + + $em = $this->getDoctrine()->getManager(); + $output = []; + + $groups=$em->getRepository('CadolesCoreBundle:Group')->findAll(); + + foreach($groups as $group) { + // Construction de la réponse + $output[$group->getId()]["id"] = $group->getId(); + $output[$group->getId()]["name"] = $group->getLabel(); + $output[$group->getId()]["users"] = []; + + $usergroups=$group->getUsers(); + foreach($usergroups as $usergroup) { + $user=$usergroup->getUser(); + $output[$group->getId()]["users"][$user->getId()]["id"]=$user->getId(); + $output[$group->getId()]["users"][$user->getId()]["username"]=$user->getUsername(); + } + } + + // Retour + return new Response(json_encode($output), 200); + } } diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/config/routing.yml b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/config/routing.yml index bbfe07fd..b96d99ba 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/config/routing.yml +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/config/routing.yml @@ -494,4 +494,12 @@ cadoles_core_config_statistic: #== REST ================================================================================================================== cadoles_core_rest_user: path: /rest/user/{key}/{login} - defaults: { _controller: CadolesCoreBundle:Rest:user } \ No newline at end of file + defaults: { _controller: CadolesCoreBundle:Rest:user } + +cadoles_core_rest_users: + path: /rest/users/{key} + defaults: { _controller: CadolesCoreBundle:Rest:users } + +cadoles_core_rest_groups: + path: /rest/groups/{key} + defaults: { _controller: CadolesCoreBundle:Rest:groups } \ No newline at end of file