mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-28 10:33:49 +00:00
create API for news item + testing if fetch works : to be generalized to accomodate other types of dashboard items
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Serializer\Normalizer;
|
||||
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Entity\NewsItem;
|
||||
use Chill\MainBundle\Repository\CenterRepository;
|
||||
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
|
||||
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||
|
||||
class NewsItemNormalizer implements NormalizerInterface
|
||||
{
|
||||
public function __construct(private readonly CenterRepository $repository) {}
|
||||
|
||||
public function normalize($newsItem, $format = null, array $context = [])
|
||||
{
|
||||
/* @var NewsItem $newsItem */
|
||||
return [
|
||||
'id' => $newsItem->getId(),
|
||||
'type' => 'news',
|
||||
'title' => $newsItem->getTitle(),
|
||||
'content' => $newsItem->getContent(),
|
||||
'startdate' => $newsItem->getStartDate(),
|
||||
'enddate' => $newsItem->getEndDate()
|
||||
];
|
||||
}
|
||||
|
||||
public function supportsNormalization($data, $format = null): bool
|
||||
{
|
||||
return $data instanceof NewsItem && 'json' === $format;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user