From 004fcbbcc7609ca83807f2e38967ef54f469bf72 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Sat, 23 Jul 2016 21:24:54 +0200 Subject: Move to new directory structure --- lib/Controller/FolderApiController.php | 139 +++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 lib/Controller/FolderApiController.php (limited to 'lib/Controller/FolderApiController.php') diff --git a/lib/Controller/FolderApiController.php b/lib/Controller/FolderApiController.php new file mode 100644 index 000000000..53693e84f --- /dev/null +++ b/lib/Controller/FolderApiController.php @@ -0,0 +1,139 @@ + + * @author Bernhard Posselt + * @copyright Alessandro Cosentino 2012 + * @copyright Bernhard Posselt 2012, 2014 + */ + +namespace OCA\News\Controller; + +use \OCP\IRequest; +use \OCP\AppFramework\ApiController; +use \OCP\AppFramework\Http; + +use \OCA\News\Service\FolderService; +use \OCA\News\Service\ItemService; +use \OCA\News\Service\ServiceNotFoundException; +use \OCA\News\Service\ServiceConflictException; +use \OCA\News\Service\ServiceValidationException; + + +class FolderApiController extends ApiController { + + use JSONHttpError; + + private $folderService; + private $itemService; + private $userId; + private $serializer; + + public function __construct($AppName, + IRequest $request, + FolderService $folderService, + ItemService $itemService, + $UserId){ + parent::__construct($AppName, $request); + $this->folderService = $folderService; + $this->itemService = $itemService; + $this->userId = $UserId; + $this->serializer = new EntityApiSerializer('folders'); + } + + + /** + * @NoAdminRequired + * @NoCSRFRequired + * @CORS + */ + public function index() { + return $this->serializer->serialize( + $this->folderService->findAll($this->userId) + ); + } + + + /** + * @NoAdminRequired + * @NoCSRFRequired + * @CORS + * + * @param string $name + * @return array|mixed|\OCP\AppFramework\Http\JSONResponse + */ + public function create($name) { + try { + $this->folderService->purgeDeleted($this->userId, false); + return $this->serializer->serialize( + $this->folderService->create($name, $this->userId) + ); + } catch(ServiceValidationException $ex) { + return $this->error($ex, Http::STATUS_UNPROCESSABLE_ENTITY); + } catch(ServiceConflictException $ex) { + return $this->error($ex, Http::STATUS_CONFLICT); + } + } + + + /** + * @NoAdminRequired + * @NoCSRFRequired + * @CORS + * + * @param int $folderId + * @return array|\OCP\AppFramework\Http\JSONResponse + */ + public function delete($folderId) { + try { + $this->folderService->delete($folderId, $this->userId); + } catch(ServiceNotFoundException $ex) { + return $this->error($ex, Http::STATUS_NOT_FOUND); + } + + return []; + } + + + /** + * @NoAdminRequired + * @NoCSRFRequired + * @CORS + * @param int $folderId + * @param string $name + * @return array|\OCP\AppFramework\Http\JSONResponse + */ + public function update($folderId, $name) { + try { + $this->folderService->rename($folderId, $name, $this->userId); + + } catch(ServiceValidationException $ex) { + return $this->error($ex, Http::STATUS_UNPROCESSABLE_ENTITY); + } catch(ServiceConflictException $ex) { + return $this->error($ex, Http::STATUS_CONFLICT); + } catch(ServiceNotFoundException $ex) { + return $this->error($ex, Http::STATUS_NOT_FOUND); + } + + return []; + } + + + /** + * @NoAdminRequired + * @NoCSRFRequired + * @CORS + * + * @param int $folderId + * @param int $newestItemId + */ + public function read($folderId, $newestItemId) { + $this->itemService->readFolder($folderId, $newestItemId, $this->userId); + } + + +} -- cgit v1.2.3