<?php
namespace App\Controller;
use App\Constants\AppConstants;
use App\Manager\UserDocumentManagerInterface;
use App\Manager\UserManagerInterface;
use App\Entity\User;
use App\Manager\NextcloudManager;
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;
protected UserManagerInterface $userManager;
protected NextcloudManager $nextcloudManager;
public function __construct(UserDocumentManagerInterface $userDocumentManager, UserManagerInterface $userManager, NextcloudManager $nextcloudManager)
{
$this->userDocumentManager = $userDocumentManager;
$this->nextcloudManager = $nextcloudManager;
$this->userManager = $userManager;
}
/**
* 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);
}
/**
* Get last documents from Nextcloud
*
* @Route("/api/widget/nextcloud/last/created", name="get_nextcloud_last_documents", methods={"GET"})
*
* @SWG\Get (
* path="/api/widget/nextcloud/last/created",
* tags={"document"},
* summary="get last documents from nextcloud",
* @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 from nextcloud"
* )
* )
*/
public function getNextcloudLastDocuments(Request $request): JsonResponse
{
/** @var User $user */
$user = $this->getUser();
$userHeimdall = $this->userManager->findUser($user->getUsername());
$contractId = $user->getCurrentContractId();
$documents = $this->nextcloudManager->getLastCreatedDocuments($userHeimdall, $contractId);
return new JsonResponse($documents);
}
/**
* Get nextcloud document notifications
*
* @Route("/api/widget/nextcloud/document/notifications", name="get_nextcloud_document_notification", methods={"GET"})
*
* @SWG\Get (
* path="/api/widget/nextcloud/document/notifications",
* tags={"document"},
* summary="get nextcloud document notifications",
* @SWG\Response(
* response="200",
* description="notifications"
* )
* )
*/
public function getNextcloudNotifications(): JsonResponse
{
/** @var User $user */
$user = $this->getUser();
$userHeimdall = $this->userManager->findUser($user->getUsername());
$contractId = $user->getCurrentContractId();
$notifications = $this->nextcloudManager->getNotifications($userHeimdall, $contractId);
return new JsonResponse($notifications);
}
}