From 3bb54550ebdcdeb215a7d850510a72289e244fac Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Thu, 8 Oct 2015 02:11:57 +0300 Subject: [PATCH] First API method. --- .../Controller/ApiController.php | 45 +++++++++++++++++++ .../Resources/config/api/routing.yml | 5 +++ .../Resources/config/routing.yml | 6 ++- 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 src/Skobkin/Bundle/PointToolsBundle/Controller/ApiController.php create mode 100644 src/Skobkin/Bundle/PointToolsBundle/Resources/config/api/routing.yml 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