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

Suppression de la DAO #42

Merged
merged 17 commits into from
May 26, 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
4 changes: 2 additions & 2 deletions Absence/Type/TypeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ private function getOne(IResponse $response, int $id) : IResponse
* @param IResponse $response Réponse Http
*
* @return IResponse
* @throws \Exception en cas d'erreur inconnue (fallback, ne doit pas arriver)
*/
private function getList(IRequest $request, IResponse $response)
{
Expand Down Expand Up @@ -155,7 +154,8 @@ public function put(IRequest $request, IResponse $response, array $arguments) :
}

try {
$this->repository->putOne($body, $resource);
$resource->populate($body);
$this->repository->putOne($resource);
} catch (MissingArgumentException $e) {
return $this->getResponseMissingArgument($response);
} catch (\DomainException $e) {
Expand Down
187 changes: 0 additions & 187 deletions Absence/Type/TypeDao.php

This file was deleted.

85 changes: 78 additions & 7 deletions Absence/Type/TypeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@
*/
class TypeRepository extends \LibertAPI\Tools\Libraries\ARepository
{
final protected function getEntiteClass() : string
{
return TypeEntite::class;
}

/**
* {@inheritDoc}
*/
final protected function getParamsConsumer2Dao(array $paramsConsumer) : array
final protected function getParamsConsumer2Storage(array $paramsConsumer) : array
{
unset($paramsConsumer);
return [];
Expand All @@ -26,13 +31,79 @@ final protected function getParamsConsumer2Dao(array $paramsConsumer) : array
/**
* @inheritDoc
*/
public function deleteOne(AEntite $entite)
final protected function getStorage2Entite(array $dataStorage)
{
return [
'id' => $dataStorage['ta_id'],
'type' => $dataStorage['ta_type'],
'libelle' => $dataStorage['ta_libelle'],
'libelleCourt' => $dataStorage['ta_short_libelle'],
];
}

/**
* Définit les values à insérer
*
* @param array $values
*/
final protected function setValues(array $values)
{
try {
$this->dao->delete($entite->getId());
$entite->reset();
} catch (\Exception $e) {
throw $e;
$this->queryBuilder->setValue('ta_type', ':type');
$this->queryBuilder->setParameter(':type', $values['type']);
$this->queryBuilder->setValue('ta_libelle', ':libelle');
$this->queryBuilder->setParameter(':libelle', $values['libelle']);
$this->queryBuilder->setValue('ta_short_libelle', ':libelleCourt');
$this->queryBuilder->setParameter(':libelleCourt', $values['libelleCourt']);
}

final protected function setSet(array $parametres)
{
if (!empty($parametres['type'])) {
$this->queryBuilder->set('ta_type', ':type');
$this->queryBuilder->setParameter(':type', $parametres['type']);
}
if (!empty($parametres['libelle'])) {
$this->queryBuilder->set('ta_libelle', ':libelle');
// @TODO : changer le schema
$this->queryBuilder->setParameter(':libelle', $parametres['libelle']);
}
if (!empty($parametres['libelleCourt'])) {
$this->queryBuilder->set('ta_short_libelle', ':libelleCourt');
$this->queryBuilder->setParameter(':libelleCourt', $parametres['libelleCourt']);
}
}

/**
* @inheritDoc
*/
final protected function getEntite2Storage(AEntite $entite) : array
{
return [
'type' => $entite->getType(),
'libelle' => $entite->getLibelle(),
'libelleCourt' => $entite->getLibelleCourt(),
];
}

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

/**
* @inheritDoc
*/
final protected function getTableName() : string
{
return 'conges_type_absence';
}
}
Loading