Skip to content

Commit

Permalink
Ajout de la route pour le grand responsables de groupe (#37)
Browse files Browse the repository at this point in the history
* Ajout route grand_responsable

* Documentation
  • Loading branch information
prytoegrian committed May 21, 2018
1 parent b25249d commit 7f67d36
Show file tree
Hide file tree
Showing 8 changed files with 647 additions and 0 deletions.
87 changes: 87 additions & 0 deletions Groupe/GrandResponsable/GrandResponsableController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php declare(strict_types = 1);
namespace LibertAPI\Groupe\GrandResponsable;

use LibertAPI\Tools\Exceptions\MissingArgumentException;
use LibertAPI\Tools\Interfaces;
use Psr\Http\Message\ServerRequestInterface as IRequest;
use Psr\Http\Message\ResponseInterface as IResponse;
use LibertAPI\Utilisateur\UtilisateurEntite;

/**
* Contrôleur de grand responsable de groupes
*
* @author Prytoegrian <prytoegrian@protonmail.com>
* @author Wouldsmina
*
* @since 1.0
* @see \Tests\Units\GroupeController
*
* Ne devrait être contacté que par le routeur
* Ne devrait contacter que le GrandResponsableRepository
*/
final class GrandResponsableController extends \LibertAPI\Tools\Libraries\AController
implements Interfaces\IGetable
{
/**
* {@inheritDoc}
*/
protected function ensureAccessUser(string $order, UtilisateurEntite $utilisateur)
{
unset($order);
if (!$utilisateur->isAdmin()) {
throw new \LibertAPI\Tools\Exceptions\MissingRightException('');
}
}

/**
* {@inheritDoc}
*/
public function get(IRequest $request, IResponse $response, array $arguments) : IResponse
{
unset($arguments);
try {
$this->ensureAccessUser(__FUNCTION__, $this->currentUser);
$groupes = $this->repository->getList(
$request->getQueryParams()
);
} catch (\UnexpectedValueException $e) {
return $this->getResponseNoContent($response);
} catch (\LibertAPI\Tools\Exceptions\MissingRightException $e) {
return $this->getResponseForbidden($response, $request);
} catch (\Exception $e) {
return $this->getResponseError($response, $e);
}
$entites = array_map([$this, 'buildData'], $groupes);

return $this->getResponseSuccess($response, $entites, 200);
}

/**
* Construit le « data » du json
*
* @param UtilisateurEntite $entite Responsable
*
* @return array
*/
private function buildData(UtilisateurEntite $entite)
{
return [
'id' => $entite->getId(),
'login' => $entite->getLogin(),
'nom' => $entite->getNom(),
'prenom' => $entite->getPrenom(),
'isResp' => $entite->isResponsable(),
'isAdmin' => $entite->isAdmin(),
'isHr' => $entite->isHautReponsable(),
'isActif' => $entite->isActif(),
'password' => $entite->getMotDePasse(),
'quotite' => $entite->getQuotite(),
'email' => $entite->getMail(),
'numeroExercice' => $entite->getNumeroExercice(),
'planningId' => $entite->getPlanningId(),
'heureSolde' => $entite->getHeureSolde(),
'dateInscription' => $entite->getDateInscription(),
'dateLastAccess' => $entite->getDateLastAccess(),
];
}
}
148 changes: 148 additions & 0 deletions Groupe/GrandResponsable/GrandResponsableDao.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
<?php declare(strict_types = 1);
namespace LibertAPI\Groupe\GrandResponsable;

use LibertAPI\Tools\Libraries\AEntite;
use LibertAPI\Utilisateur\UtilisateurEntite;

/**
* {@inheritDoc}
*
* @author Prytoegrian <prytoegrian@protonmail.com>
* @author Wouldsmina
*
* @since 1.0
*
* Ne devrait être contacté que par GrandResponsableRepository
* Ne devrait contacter personne
*/
class GrandResponsableDao extends \LibertAPI\Tools\Libraries\ADao
{
/*************************************************
* GET
*************************************************/

/**
* @inheritDoc
*/
public function getById(int $id) : AEntite
{
throw new \RuntimeException('Action is forbidden');
}

/**
* @inheritDoc
*/
public function getList(array $parametres) : array
{
$this->queryBuilder->select('users.*, users.u_login AS id');
$this->queryBuilder->innerJoin('current', 'conges_users', 'users', 'current.ggr_login = u_login');
$this->setWhere($parametres);
$res = $this->queryBuilder->execute();

$data = $res->fetchAll(\PDO::FETCH_ASSOC);
if (empty($data)) {
throw new \UnexpectedValueException('No resource match with these parameters');
}

$entites = array_map(function ($value) {
return new UtilisateurEntite($this->getStorage2Entite($value));
}, $data);

return $entites;
}

/**
* @inheritDoc
*
* Duplication de la fonction dans UtilisateurDao (Cf. decisions.md #2018-02-17)
*/
final protected function getStorage2Entite(array $dataDao) : array
{
return [
'id' => $dataDao['id'],
'login' => $dataDao['u_login'],
'nom' => $dataDao['u_nom'],
'prenom' => $dataDao['u_prenom'],
'isResp' => $dataDao['u_is_resp'] === 'Y',
'isAdmin' => $dataDao['u_is_admin'] === 'Y',
'isHr' => $dataDao['u_is_hr'] === 'Y',
'isActive' => $dataDao['u_is_active'] === 'Y',
'seeAll' => $dataDao['u_see_all'] === 'Y',
'password' => $dataDao['u_passwd'],
'quotite' => $dataDao['u_quotite'],
'email' => $dataDao['u_email'],
'numeroExercice' => $dataDao['u_num_exercice'],
'planningId' => $dataDao['planning_id'],
'heureSolde' => $dataDao['u_heure_solde'],
'dateInscription' => $dataDao['date_inscription'],
'token' => $dataDao['token'],
'dateLastAccess' => $dataDao['date_last_access'],
];
}

/*************************************************
* POST
*************************************************/

/**
* @inheritDoc
*/
public function post(AEntite $entite) : int
{
throw new \RuntimeException('Action is forbidden');
}

/*************************************************
* PUT
*************************************************/

/**
* @inheritDoc
*/
public function put(AEntite $entite)
{
throw new \RuntimeException('Action is forbidden');
}

/**
* @inheritDoc
*/
final protected function getEntite2Storage(AEntite $entite) : array
{
return [];
}

/*************************************************
* DELETE
*************************************************/

/**
* @inheritDoc
*/
public function delete(int $id) : int
{
throw new \RuntimeException('Action is forbidden');
}

/**
* Définit les filtres à appliquer à la requête
*
* @param array $parametres
* @example [filter => []]
*/
private function setWhere(array $parametres)
{
if (!empty($parametres['id'])) {
$this->queryBuilder->andWhere('ggr_gid = :id');
$this->queryBuilder->setParameter(':id', (int) $parametres['id']);
}
}

/**
* @inheritDoc
*/
final protected function getTableName() : string
{
return 'conges_groupe_grd_resp';
}
}
73 changes: 73 additions & 0 deletions Groupe/GrandResponsable/GrandResponsableRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php declare(strict_types = 1);
namespace LibertAPI\Groupe\GrandResponsable;

use LibertAPI\Tools\Libraries\AEntite;

/**
* {@inheritDoc}
*
* @author Prytoegrian <prytoegrian@protonmail.com>
* @author Wouldsmina
*
* @since 1.0
* @see \LibertAPI\Tests\Units\Groupe\GrandResponsable\GrandResponsableRepository
*/
class GrandResponsableRepository extends \LibertAPI\Tools\Libraries\ARepository
{
/*************************************************
* GET
*************************************************/

/**
* @inheritDoc
*/
public function getOne(int $id) : AEntite
{
throw new \RuntimeException('#' . $id . ' is not a callable resource');
}

/**
* @inheritDoc
*/
final protected function getParamsConsumer2Dao(array $paramsConsumer) : array
{
unset($paramsConsumer);
return [];
}

/*************************************************
* POST
*************************************************/

/**
* @inheritDoc
*/
public function postOne(array $data, AEntite $entite)
{
throw new \RuntimeException('Action is forbidden');
}

/*************************************************
* PUT
*************************************************/

/**
* @inheritDoc
*/
public function putOne(array $data, AEntite $entite)
{
throw new \RuntimeException('Action is forbidden');
}

/*************************************************
* DELETE
*************************************************/

/**
* @inheritDoc
*/
public function deleteOne(AEntite $entite)
{
throw new \RuntimeException('Action is forbidden');
}
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Suivant les règles de l'architecture REST, les routes disponibles à ce jour so
* `GET /groupe`
* `GET /groupe/{id}`
* `GET /groupe/{id}/responsable`
* `GET /groupe/{id}/grand_responsable`
* `GET /journal`
* `GET|POST /planning`
* `GET|PUT|DELETE /planning/{id}`
Expand Down
Loading

0 comments on commit 7f67d36

Please sign in to comment.