mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-27 18:13:48 +00:00
change logic of dashboard item to return user config, reinstate news items api
This commit is contained in:
@@ -11,55 +11,40 @@ use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
class DashboardApiController extends ApiController
|
||||
class DashboardApiController
|
||||
{
|
||||
public function __construct(private readonly EntityManagerInterface $em)
|
||||
public function __construct(private readonly Security $security)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Give an answer to a calendar invite.
|
||||
*
|
||||
* @Route("/api/1.0/main/dashboard-item/{user_id}.json", methods={"get"})
|
||||
*/
|
||||
public function getDataForDashboard(int $userId): JsonResponse
|
||||
public function setCrudConfig()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
//with the userId get the dashboard config for that user?
|
||||
$user = $this->security->getUser();
|
||||
|
||||
if (!$user instanceof User) {
|
||||
throw new AccessDeniedHttpException('You must be an authenticated user');
|
||||
}
|
||||
/**
|
||||
* Give the user dashboard configuration
|
||||
*
|
||||
* @Route("/api/1.0/main/dashboard-config-item.json", methods={"post"})
|
||||
*/
|
||||
public function getDashboardConfiguration(): JsonResponse
|
||||
{
|
||||
$data = [
|
||||
[
|
||||
'position' => 'top-left',
|
||||
'id' => 1,
|
||||
'type' => 'news',
|
||||
'metadata' => [
|
||||
// arbitrary data that will be store "some time"
|
||||
'only_unread' => false,
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$config = ['types' => ['news']];
|
||||
|
||||
//based on the user dashboard config fetch the items to be displayed
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ($config['types'] as $type)
|
||||
{
|
||||
switch ($type) {
|
||||
case 'news':
|
||||
$qb = $this->em->createQueryBuilder();
|
||||
$qb->select('n')
|
||||
->from(NewsItem::class)
|
||||
->where(
|
||||
$qb->expr()->lt('n.endDate', ':today')
|
||||
);
|
||||
|
||||
$qb->setParameter('today', new \DateTimeImmutable('now'));
|
||||
|
||||
$newsItems = $qb->getQuery()->getResult();
|
||||
$data[] = $newsItems;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return new JsonResponse($data, Response::HTTP_ACCEPTED, [], true);
|
||||
return new JsonResponse($data);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user