Created
February 24, 2015 06:29
-
-
Save memphys/ac6777bdef81e5ca0237 to your computer and use it in GitHub Desktop.
Revisions
-
Roman Lapin created this gist
Feb 24, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,49 @@ <?php namespace App\ApiBundle\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; use FOS\RestBundle\Controller\Annotations\View; use Nelmio\ApiDocBundle\Annotation\ApiDoc; use Symfony\Component\HttpFoundation\Request; class ProductController extends BaseController { /** * @View(serializerGroups={"productList"}) * @Route("/products") * @Method({"GET", "OPTIONS"}) * * @ApiDoc( * section="Продукты", * description="Получение страниц по id каталога", * parameters={ * {"name"="shop", "dataType"="integer", "description"="ID магазина", "required"=false, "readonly"=false} * }, * output={ * {"items", "array", "Product"}, * } * ) */ public function listAction(Request $request) { $repository = $this->getDoctrine()->getManager()->getRepository('AppBundle:Product'); $requestQuery = $this->get('request'); $perPageCount = $requestQuery->get('perPage', 100); $query = $repository->getProductsByParams([ 'store' => $request->query->get('shop'), ]); $pagination = $this->get('knp_paginator')->paginate($query, $requestQuery->get('page', 1), $perPageCount); return [ 'items' => $pagination->getItems(), 'pagination' => $pagination->getPaginationData() ]; } }