First API method.

This commit is contained in:
Alexey Skobkin 2015-10-08 02:11:57 +03:00
parent a6628b4369
commit 3bb54550eb
3 changed files with 55 additions and 1 deletions

View file

@ -0,0 +1,45 @@
<?php
namespace Skobkin\Bundle\PointToolsBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Skobkin\Bundle\PointToolsBundle\Entity\SubscriptionEvent;
use Skobkin\Bundle\PointToolsBundle\Entity\User;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
class ApiController extends Controller
{
/**
* Returns last user subscribers log
*
* @param $login
* @ParamConverter("user", class="SkobkinPointToolsBundle:User")
* @return Response
*/
public function lastUserSubscribersByIdAction(User $user)
{
$qb = $this->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);
}
}

View file

@ -0,0 +1,5 @@
last_user_events:
path: /user/id/{id}/events
defaults: { _controller: SkobkinPointToolsBundle:Api:lastUserSubscribersById, _format: json }
requirements:
id: \d+

View file

@ -20,3 +20,7 @@ users_top:
events_last: events_last:
path: /last path: /last
defaults: { _controller: SkobkinPointToolsBundle:Events:last } defaults: { _controller: SkobkinPointToolsBundle:Events:last }
skobkin_point_tools:
resource: "@SkobkinPointToolsBundle/Resources/config/api/routing.yml"
prefix: /api/v1