* api implementation
* no auth yet * images renamed to reflect name-prefix changes * yearservice now gets years from judge data
This commit is contained in:
@@ -6,15 +6,22 @@ namespace App\Service;
|
||||
|
||||
use App\Entity\Awardee;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use DoctrineExpressiveModule\Hydrator\DoctrineObject;
|
||||
|
||||
class AwardeeManager
|
||||
{
|
||||
/** @var EntityManager */
|
||||
private $entityManager;
|
||||
|
||||
public function __construct(EntityManager $entityManager)
|
||||
{
|
||||
/** @var DoctrineObject */
|
||||
private $hydrator;
|
||||
|
||||
public function __construct(
|
||||
EntityManager $entityManager,
|
||||
DoctrineObject $hydrator
|
||||
) {
|
||||
$this->entityManager = $entityManager;
|
||||
$this->hydrator = $hydrator;
|
||||
}
|
||||
|
||||
public function getAwardees(): ?array
|
||||
@@ -54,4 +61,50 @@ class AwardeeManager
|
||||
]);
|
||||
return $awardee;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Awardee
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
*/
|
||||
public function create($data): Awardee
|
||||
{
|
||||
/** @var Awardee $awardee */
|
||||
$awardee = $this->hydrator->hydrate($data, new Awardee());
|
||||
$this->entityManager->persist($awardee);
|
||||
$this->entityManager->flush();
|
||||
return $awardee;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param $data
|
||||
* @return Awardee
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
*/
|
||||
public function update(int $id, $data): Awardee
|
||||
{
|
||||
$awardee = $this->entityManager->getRepository(Awardee::class)->find($id);
|
||||
/** @var Awardee $awardee */
|
||||
$awardee = $this->hydrator->hydrate($data, $awardee);
|
||||
$this->entityManager->persist($awardee);
|
||||
$this->entityManager->flush();
|
||||
return $awardee;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return bool
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
*/
|
||||
public function delete(int $id): bool {
|
||||
if (null !== ($entity = $this->getAwardee($id))) {
|
||||
$this->entityManager->remove($entity);
|
||||
$this->entityManager->flush();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user