Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accès aux jours fériés via l'API #39

Merged
merged 7 commits into from
May 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Groupe/Employe/EmployeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private function buildData(UtilisateurEntite $entite)
'prenom' => $entite->getPrenom(),
'isResp' => $entite->isResponsable(),
'isAdmin' => $entite->isAdmin(),
'isHr' => $entite->isHautReponsable(),
'isHr' => $entite->isHautResponsable(),
'isActif' => $entite->isActif(),
'password' => $entite->getMotDePasse(),
'quotite' => $entite->getQuotite(),
Expand Down
2 changes: 1 addition & 1 deletion Groupe/GrandResponsable/GrandResponsableController.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private function buildData(UtilisateurEntite $entite)
'prenom' => $entite->getPrenom(),
'isResp' => $entite->isResponsable(),
'isAdmin' => $entite->isAdmin(),
'isHr' => $entite->isHautReponsable(),
'isHr' => $entite->isHautResponsable(),
'isActif' => $entite->isActif(),
'password' => $entite->getMotDePasse(),
'quotite' => $entite->getQuotite(),
Expand Down
2 changes: 1 addition & 1 deletion Groupe/Responsable/ResponsableController.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private function buildData(UtilisateurEntite $entite)
'prenom' => $entite->getPrenom(),
'isResp' => $entite->isResponsable(),
'isAdmin' => $entite->isAdmin(),
'isHr' => $entite->isHautReponsable(),
'isHr' => $entite->isHautResponsable(),
'isActif' => $entite->isActif(),
'password' => $entite->getMotDePasse(),
'quotite' => $entite->getQuotite(),
Expand Down
76 changes: 76 additions & 0 deletions JourFerie/JourFerieController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php declare(strict_types = 1);
namespace LibertAPI\JourFerie;

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

/**
* Contrôleur de jour férié
*
* @author Prytoegrian <prytoegrian@protonmail.com>
* @author Wouldsmina
*
* @since 1.0
*
* Ne devrait être contacté que par le routeur
* Ne devrait contacter que le JourFerieRepository
*/
final class JourFerieController extends \LibertAPI\Tools\Libraries\AController
implements Interfaces\IGetable
{
/**
* {@inheritDoc}
*/
protected function ensureAccessUser(string $order, \LibertAPI\Utilisateur\UtilisateurEntite $utilisateur)
{
unset($order);
if (!$utilisateur->isHautResponsable()) {
throw new \LibertAPI\Tools\Exceptions\MissingRightException('');
}
}

/**
* {@inheritDoc}
*/
public function get(IRequest $request, IResponse $response, array $arguments) : IResponse
{
return $this->getList($request, $response);
}

/**
* Retourne un tableau de jours fériés
*
* @param IRequest $request Requête Http
* @param IResponse $response Réponse Http
*/
private function getList(IRequest $request, IResponse $response) : IResponse
{
try {
$this->ensureAccessUser(__FUNCTION__, $this->currentUser);
$jours = $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'], $jours);

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

/**
* Construit le « data » du json
*/
private function buildData(JourFerieEntite $entite) : array
{
return [
'date' => $entite->getDate(),
];
}
}
132 changes: 132 additions & 0 deletions JourFerie/JourFerieDao.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?php declare(strict_types = 1);
namespace LibertAPI\JourFerie;

use LibertAPI\Tools\Libraries\AEntite;

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

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

/**
* @inheritDoc
* @TODO : cette méthode le montre, JourFerie n'est pas une entité, mais un value object.
* L'id n'est donc pas nécessaire, et l'arbo habituelle est remise en cause
*/
final protected function getStorage2Entite(array $dataDao)
{
return [
'id' => uniqid(),
'date' => $dataDao['jf_date'],
];
}

/**
* @inheritDoc
*/
public function getList(array $parametres) : array
{
$this->queryBuilder->select('*');
$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 JourFerieEntite($this->getStorage2Entite($value));
},
$data
);

return $entites;
}

/*************************************************
* 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 [
'jf_date' => $entite->getDate(),
];
}

/*************************************************
* 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)
{
unset($parametres);
}

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

use LibertAPI\Tools\Exceptions\MissingArgumentException;

/**
* @inheritDoc
*
* @author Prytoegrian <prytoegrian@protonmail.com>
* @author Wouldsmina
*
* @since 1.0
*
* Ne devrait être contacté que par le JourFerieDao
* Ne devrait contacter personne
*/
class JourFerieEntite extends \LibertAPI\Tools\Libraries\AEntite
{
/**
* Retourne la donnée la plus à jour du champ date
*
* @return string
*/
public function getDate()
{
return $this->getFreshData('date');
}

/**
* @inheritDoc
*/
public function populate(array $data)
{
}
}
45 changes: 45 additions & 0 deletions JourFerie/JourFerieRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php declare(strict_types = 1);
namespace LibertAPI\JourFerie;

use LibertAPI\Tools\Libraries\AEntite;

/**
* {@inheritDoc}
*
* @author Prytoegrian <prytoegrian@protonmail.com>
* @author Wouldsmina
*
* @since 1.0
*
* Ne devrait être contacté que par le JourFerieController
* Ne devrait contacter que le JourFerieEntite, JourFerieDao
*/
class JourFerieRepository extends \LibertAPI\Tools\Libraries\ARepository
{
/*************************************************
* GET
*************************************************/

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


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

/**
* @inheritDoc
*/
public function deleteOne(AEntite $entite)
{
$this->dao->delete($entite->getId());
$entite->reset();
}
}
2 changes: 1 addition & 1 deletion Planning/PlanningController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class PlanningController extends \LibertAPI\Tools\Libraries\AController
protected function ensureAccessUser(string $order, \LibertAPI\Utilisateur\UtilisateurEntite $utilisateur)
{
$rights = [
'getList' => $utilisateur->isResponsable() || $utilisateur->isHautReponsable() || $utilisateur->isAdmin(),
'getList' => $utilisateur->isResponsable() || $utilisateur->isHautResponsable() || $utilisateur->isAdmin(),
];

if (isset($rights[$order]) && !$rights[$order]) {
Expand Down
1 change: 1 addition & 0 deletions Public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
require_once ROUTE_PATH . 'Authentification.php';
require_once ROUTE_PATH . 'Groupe.php';
require_once ROUTE_PATH . 'Journal.php';
require_once ROUTE_PATH . 'JourFerie.php';
require_once ROUTE_PATH . 'Planning.php';
require_once ROUTE_PATH . 'Utilisateur.php';
/* Jump in ! */
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ Suivant les règles de l'architecture REST, les routes disponibles à ce jour so
* `GET /groupe/{id}/grand_responsable`
* `GET /groupe/{id}/responsable`
* `GET /journal`
* `GET /jour_ferie`
* `GET|POST /planning`
* `GET|PUT|DELETE /planning/{id}`
* `GET|POST /planning/{id}/creneau`
Expand Down
Loading