src/Controller/DocumentController.php line 39

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Constants\AppConstants;
  4. use App\Manager\UserDocumentManagerInterface;
  5. use Swagger\Annotations as SWG;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\JsonResponse;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. class DocumentController extends AbstractController
  12. {
  13. protected UserDocumentManagerInterface $userDocumentManager;
  14.     public function __construct(UserDocumentManagerInterface $userDocumentManager)
  15.     {
  16.         $this->userDocumentManager $userDocumentManager;
  17.     }
  18.     /**
  19.      * Get document notifications
  20.      *
  21.      * @Route("/api/widget/document/notifications", name="get_document_notification",  methods={"GET"})
  22.      *
  23.      * @SWG\Get (
  24.      *      path="/api/widget/document/notifications",
  25.      *      tags={"document"},
  26.      *      summary="get document notifications",
  27.      *     @SWG\Response(
  28.      *         response="200",
  29.      *         description="notifications"
  30.      *     )
  31.      * )
  32.      */
  33.     public function getNotifications(): JsonResponse
  34.     {
  35.         $notifications $this->userDocumentManager->getNotifications($this->getUser()->getUsername());
  36.         return new JsonResponse($notifications);
  37.     }
  38.     /**
  39.      * Get last created documents
  40.      *
  41.      * @Route("/api/widget/document/last/created", name="get_document_last_created",  methods={"GET"})
  42.      *
  43.      * @SWG\Get (
  44.      *      path="/api/widget/document/last/created",
  45.      *      tags={"document"},
  46.      *      summary="get last created document",
  47.      *     @SWG\Response(
  48.      *         response="200",
  49.      *         description="last created documents"
  50.      *     )
  51.      * )
  52.      */
  53.     public function getLastCreated(): JsonResponse
  54.     {
  55.         $documents $this->userDocumentManager->getLastCreatedDocuments($this->getUser()->getUsername());
  56.         return new JsonResponse($documents);
  57.     }
  58.     /**
  59.      * Get  documents
  60.      *
  61.      * @Route("/api/widget/document", name="get_documents",  methods={"GET"})
  62.      *
  63.      * @SWG\Get (
  64.      *      path="/api/widget/document",
  65.      *      tags={"document"},
  66.      *      summary="get  documents",
  67.      *     @SWG\Parameter(
  68.      *         name="currentPage",
  69.      *         in="query",
  70.      *         description="current page",
  71.      *         required=false,
  72.      *         default=1,
  73.      *         type="number"
  74.      *     ),
  75.      *     @SWG\Parameter(
  76.      *         name="itemsPerPage",
  77.      *         in="query",
  78.      *         description="item per page",
  79.      *         required=false,
  80.      *         default=10,
  81.      *         type="number"
  82.      *     ),
  83.      *     @SWG\Response(
  84.      *         response="200",
  85.      *         description="documents"
  86.      *     )
  87.      * )
  88.      */
  89.     public function getDocuments(Request $request): JsonResponse
  90.     {
  91.         $currentPage $request->query->get('currentPage'AppConstants::DEFAULT_CURRENT_PAGE);
  92.         $itemPerPage $request->query->get('itemsPerPage'AppConstants::DEFAULT_DOCUMENTS_PER_PAGE);
  93.         $documents $this->userDocumentManager->getDocuments($this->getUser()->getUsername(), $currentPage$itemPerPage);
  94.         return new JsonResponse($documents);
  95.     }
  96. }