<?php
namespace App\Controller;
use App\Constants\AppConstants;
use App\Manager\UserDocumentManagerInterface;
use Swagger\Annotations as SWG;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class DocumentController extends AbstractController
{
protected UserDocumentManagerInterface $userDocumentManager;
public function __construct(UserDocumentManagerInterface $userDocumentManager)
{
$this->userDocumentManager = $userDocumentManager;
}
/**
* Get document notifications
*
* @Route("/api/widget/document/notifications", name="get_document_notification", methods={"GET"})
*
* @SWG\Get (
* path="/api/widget/document/notifications",
* tags={"document"},
* summary="get document notifications",
* @SWG\Response(
* response="200",
* description="notifications"
* )
* )
*/
public function getNotifications(): JsonResponse
{
$notifications = $this->userDocumentManager->getNotifications($this->getUser()->getUsername());
return new JsonResponse($notifications);
}
/**
* Get last created documents
*
* @Route("/api/widget/document/last/created", name="get_document_last_created", methods={"GET"})
*
* @SWG\Get (
* path="/api/widget/document/last/created",
* tags={"document"},
* summary="get last created document",
* @SWG\Response(
* response="200",
* description="last created documents"
* )
* )
*/
public function getLastCreated(): JsonResponse
{
$documents = $this->userDocumentManager->getLastCreatedDocuments($this->getUser()->getUsername());
return new JsonResponse($documents);
}
/**
* Get documents
*
* @Route("/api/widget/document", name="get_documents", methods={"GET"})
*
* @SWG\Get (
* path="/api/widget/document",
* tags={"document"},
* summary="get documents",
* @SWG\Parameter(
* name="currentPage",
* in="query",
* description="current page",
* required=false,
* default=1,
* type="number"
* ),
* @SWG\Parameter(
* name="itemsPerPage",
* in="query",
* description="item per page",
* required=false,
* default=10,
* type="number"
* ),
* @SWG\Response(
* response="200",
* description="documents"
* )
* )
*/
public function getDocuments(Request $request): JsonResponse
{
$currentPage = $request->query->get('currentPage', AppConstants::DEFAULT_CURRENT_PAGE);
$itemPerPage = $request->query->get('itemsPerPage', AppConstants::DEFAULT_DOCUMENTS_PER_PAGE);
$documents = $this->userDocumentManager->getDocuments($this->getUser()->getUsername(), $currentPage, $itemPerPage);
return new JsonResponse($documents);
}
}