First API method.
This commit is contained in:
parent
a6628b4369
commit
3bb54550eb
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
last_user_events:
|
||||||
|
path: /user/id/{id}/events
|
||||||
|
defaults: { _controller: SkobkinPointToolsBundle:Api:lastUserSubscribersById, _format: json }
|
||||||
|
requirements:
|
||||||
|
id: \d+
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue