src/Controller/DocumentController.php line 47

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Constants\AppConstants;
  4. use App\Manager\UserDocumentManagerInterface;
  5. use App\Manager\UserManagerInterface;
  6. use App\Entity\User;
  7. use App\Manager\NextcloudManager;
  8. use Swagger\Annotations as SWG;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\HttpFoundation\JsonResponse;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. class DocumentController extends AbstractController
  15. {
  16.     protected UserDocumentManagerInterface $userDocumentManager;
  17.     protected UserManagerInterface $userManager;
  18.     protected NextcloudManager $nextcloudManager;
  19.     public function __construct(UserDocumentManagerInterface $userDocumentManagerUserManagerInterface $userManagerNextcloudManager $nextcloudManager)
  20.     {
  21.         $this->userDocumentManager $userDocumentManager;
  22.         $this->nextcloudManager $nextcloudManager;
  23.         $this->userManager $userManager;
  24.     }
  25.     /**
  26.      * Get document notifications
  27.      *
  28.      * @Route("/api/widget/document/notifications", name="get_document_notification",  methods={"GET"})
  29.      *
  30.      * @SWG\Get (
  31.      *      path="/api/widget/document/notifications",
  32.      *      tags={"document"},
  33.      *      summary="get document notifications",
  34.      *     @SWG\Response(
  35.      *         response="200",
  36.      *         description="notifications"
  37.      *     )
  38.      * )
  39.      */
  40.     public function getNotifications(): JsonResponse
  41.     {
  42.         $notifications $this->userDocumentManager->getNotifications($this->getUser()->getUsername());
  43.         return new JsonResponse($notifications);
  44.     }
  45.     /**
  46.      * Get last created documents
  47.      *
  48.      * @Route("/api/widget/document/last/created", name="get_document_last_created",  methods={"GET"})
  49.      *
  50.      * @SWG\Get (
  51.      *      path="/api/widget/document/last/created",
  52.      *      tags={"document"},
  53.      *      summary="get last created document",
  54.      *     @SWG\Response(
  55.      *         response="200",
  56.      *         description="last created documents"
  57.      *     )
  58.      * )
  59.      */
  60.     public function getLastCreated(): JsonResponse
  61.     {
  62.         $documents $this->userDocumentManager->getLastCreatedDocuments($this->getUser()->getUsername());
  63.         return new JsonResponse($documents);
  64.     }
  65.     /**
  66.      * Get  documents
  67.      *
  68.      * @Route("/api/widget/document", name="get_documents",  methods={"GET"})
  69.      *
  70.      * @SWG\Get (
  71.      *      path="/api/widget/document",
  72.      *      tags={"document"},
  73.      *      summary="get  documents",
  74.      *     @SWG\Parameter(
  75.      *         name="currentPage",
  76.      *         in="query",
  77.      *         description="current page",
  78.      *         required=false,
  79.      *         default=1,
  80.      *         type="number"
  81.      *     ),
  82.      *     @SWG\Parameter(
  83.      *         name="itemsPerPage",
  84.      *         in="query",
  85.      *         description="item per page",
  86.      *         required=false,
  87.      *         default=10,
  88.      *         type="number"
  89.      *     ),
  90.      *     @SWG\Response(
  91.      *         response="200",
  92.      *         description="documents"
  93.      *     )
  94.      * )
  95.      */
  96.     public function getDocuments(Request $request): JsonResponse
  97.     {
  98.         $currentPage $request->query->get('currentPage'AppConstants::DEFAULT_CURRENT_PAGE);
  99.         $itemPerPage $request->query->get('itemsPerPage'AppConstants::DEFAULT_DOCUMENTS_PER_PAGE);
  100.         $documents $this->userDocumentManager->getDocuments($this->getUser()->getUsername(), $currentPage$itemPerPage);
  101.         return new JsonResponse($documents);
  102.     }
  103.     /**
  104.      * Get last documents from Nextcloud
  105.      *
  106.      * @Route("/api/widget/nextcloud/last/created", name="get_nextcloud_last_documents",  methods={"GET"})
  107.      *
  108.      * @SWG\Get (
  109.      *      path="/api/widget/nextcloud/last/created",
  110.      *      tags={"document"},
  111.      *      summary="get last documents from nextcloud",
  112.      *     @SWG\Parameter(
  113.      *         name="currentPage",
  114.      *         in="query",
  115.      *         description="current page",
  116.      *         required=false,
  117.      *         default=1,
  118.      *         type="number"
  119.      *     ),
  120.      *     @SWG\Parameter(
  121.      *         name="itemsPerPage",
  122.      *         in="query",
  123.      *         description="item per page",
  124.      *         required=false,
  125.      *         default=10,
  126.      *         type="number"
  127.      *     ),
  128.      *     @SWG\Response(
  129.      *         response="200",
  130.      *         description="documents from nextcloud"
  131.      *     )
  132.      * )
  133.      */
  134.     public function getNextcloudLastDocuments(Request $request): JsonResponse
  135.     {
  136.         /** @var User $user */
  137.         $user $this->getUser();
  138.         $userHeimdall $this->userManager->findUser($user->getUsername());
  139.         $contractId $user->getCurrentContractId();
  140.         $documents $this->nextcloudManager->getLastCreatedDocuments($userHeimdall$contractId);
  141.         return new JsonResponse($documents);
  142.     }
  143.         /**
  144.      * Get nextcloud document notifications
  145.      *
  146.      * @Route("/api/widget/nextcloud/document/notifications", name="get_nextcloud_document_notification",  methods={"GET"})
  147.      *
  148.      * @SWG\Get (
  149.      *      path="/api/widget/nextcloud/document/notifications",
  150.      *      tags={"document"},
  151.      *      summary="get nextcloud document notifications",
  152.      *     @SWG\Response(
  153.      *         response="200",
  154.      *         description="notifications"
  155.      *     )
  156.      * )
  157.      */
  158.     public function getNextcloudNotifications(): JsonResponse
  159.     {
  160.         /** @var User $user */
  161.         $user $this->getUser();
  162.         $userHeimdall $this->userManager->findUser($user->getUsername());
  163.         $contractId $user->getCurrentContractId();
  164.         $notifications $this->nextcloudManager->getNotifications($userHeimdall$contractId);
  165.         return new JsonResponse($notifications);
  166.     }
  167. }