diff --git a/src/Skobkin/Bundle/PointToolsBundle/Controller/ApiController.php b/src/Skobkin/Bundle/PointToolsBundle/Controller/ApiController.php new file mode 100644 index 0000000..d136f3c --- /dev/null +++ b/src/Skobkin/Bundle/PointToolsBundle/Controller/ApiController.php @@ -0,0 +1,45 @@ +getDoctrine()->getRepository('SkobkinPointToolsBundle:SubscriptionEvent')->createQueryBuilder('se'); + $qb + ->select(['se', 'sub']) + ->innerJoin('se.subscriber', 'sub') + ->where($qb->expr()->eq('se.author', ':author')) + ->setParameter('author', $user) + ->setMaxResults(20) + ; + + $data = []; + + /** @var SubscriptionEvent $event */ + foreach ($qb->getQuery()->getResult() as $event) { + $data[] = [ + 'user' => $event->getSubscriber()->getLogin(), + 'action' => $event->getAction(), + 'datetime' => $event->getDate()->format('d.m.Y H:i:s'), + ]; + } + + return new JsonResponse($data); + } +} diff --git a/src/Skobkin/Bundle/PointToolsBundle/Resources/config/api/routing.yml b/src/Skobkin/Bundle/PointToolsBundle/Resources/config/api/routing.yml new file mode 100644 index 0000000..b0035d4 --- /dev/null +++ b/src/Skobkin/Bundle/PointToolsBundle/Resources/config/api/routing.yml @@ -0,0 +1,5 @@ +last_user_events: + path: /user/id/{id}/events + defaults: { _controller: SkobkinPointToolsBundle:Api:lastUserSubscribersById, _format: json } + requirements: + id: \d+ \ No newline at end of file diff --git a/src/Skobkin/Bundle/PointToolsBundle/Resources/config/routing.yml b/src/Skobkin/Bundle/PointToolsBundle/Resources/config/routing.yml index f153f20..98c91f7 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Resources/config/routing.yml +++ b/src/Skobkin/Bundle/PointToolsBundle/Resources/config/routing.yml @@ -19,4 +19,8 @@ users_top: events_last: path: /last - defaults: { _controller: SkobkinPointToolsBundle:Events:last } \ No newline at end of file + defaults: { _controller: SkobkinPointToolsBundle:Events:last } + +skobkin_point_tools: + resource: "@SkobkinPointToolsBundle/Resources/config/api/routing.yml" + prefix: /api/v1