diff --git a/src/Bundle/ChillMainBundle/Controller/DashboardApiController.php b/src/Bundle/ChillMainBundle/Controller/DashboardApiController.php new file mode 100644 index 000000000..ed0f55cfd --- /dev/null +++ b/src/Bundle/ChillMainBundle/Controller/DashboardApiController.php @@ -0,0 +1,65 @@ +security->getUser(); + + if (!$user instanceof User) { + throw new AccessDeniedHttpException('You must be an authenticated user'); + } + + $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); + } + +} diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php index bc4929dfb..6db465cc1 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php @@ -792,11 +792,11 @@ class ChillMainExtension extends Extension implements ], ], ], - [ - 'class' => \Chill\MainBundle\Entity\NewsItem::class, - 'controller' => \Chill\MainBundle\Controller\NewsItemApiController::class, +/* [ + 'class' => \Chill\MainBundle\Entity\DashboardItem::class, + 'controller' => \Chill\MainBundle\Controller\DashboardApiController::class, 'name' => 'news-item', - 'base_path' => '/api/1.0/main/news', + 'base_path' => '/api/1.0/main/dashboard-item', 'base_role' => 'ROLE_USER', 'actions' => [ '_index' => [ @@ -812,7 +812,7 @@ class ChillMainExtension extends Extension implements ], ], ], - ], + ],*/ ], ]); } diff --git a/src/Bundle/ChillMainBundle/chill.api.specs.yaml b/src/Bundle/ChillMainBundle/chill.api.specs.yaml index 8df409dfb..936712a11 100644 --- a/src/Bundle/ChillMainBundle/chill.api.specs.yaml +++ b/src/Bundle/ChillMainBundle/chill.api.specs.yaml @@ -137,7 +137,7 @@ components: id: type: integer - News: + DashboardItem: type: object properties: id: @@ -146,15 +146,6 @@ components: type: string metadata: type: object - properties: - title: - type: string - content: - type: string - startdate: - $ref: "#/components/schemas/Date" - enddate: - $ref: "#/components/schemas/Date" paths: @@ -868,11 +859,20 @@ paths: $ref: '#/components/schemas/Workflow' 403: description: "Unauthorized" - /1.0/main/news.json: + /1.0/main/dashboard-item/{user_id}.json: get: tags: - - news - summary: Returns a list of news items + - dashboard item + summary: Returns a list of dashboard items for the user in question + parameters: + - name: user_id + in: path + required: true + description: The user id + schema: + type: integer + format: integer + minimum: 1 responses: 200: description: "ok" @@ -881,7 +881,7 @@ paths: schema: type: array items: - $ref: '#/components/schemas/News' + $ref: '#/components/schemas/DashboardItem' 403: description: "Unauthorized"