diff options
author | Sean Molenaar <sean@seanmolenaar.eu> | 2020-10-04 20:45:33 +0200 |
---|---|---|
committer | Benjamin Brahmer <info@b-brahmer.de> | 2020-11-03 19:58:37 +0100 |
commit | 10e8c28feaf6d858948285a291231f651ef74728 (patch) | |
tree | 5c48216dc1ce6a6dd8f292d489bb4a7d03cb5595 /lib/Controller | |
parent | 361cfa55b7302b29e158647060085550b9a3dfe1 (diff) |
Add migration with foreign keys
Closes #829
Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
Diffstat (limited to 'lib/Controller')
-rw-r--r-- | lib/Controller/FeedApiController.php | 21 | ||||
-rw-r--r-- | lib/Controller/FeedController.php | 32 | ||||
-rw-r--r-- | lib/Controller/FolderApiController.php | 27 | ||||
-rw-r--r-- | lib/Controller/FolderController.php | 39 | ||||
-rw-r--r-- | lib/Controller/UserApiController.php | 74 |
5 files changed, 79 insertions, 114 deletions
diff --git a/lib/Controller/FeedApiController.php b/lib/Controller/FeedApiController.php index cb3d5e645..2c96bbc6e 100644 --- a/lib/Controller/FeedApiController.php +++ b/lib/Controller/FeedApiController.php @@ -27,6 +27,7 @@ use \OCP\AppFramework\Http; use \OCA\News\Service\FeedService; use \OCA\News\Service\ItemService; use Psr\Log\LoggerInterface; +use function GuzzleHttp\Psr7\uri_for; class FeedApiController extends ApiController { @@ -99,13 +100,17 @@ class FeedApiController extends ApiController * @NoCSRFRequired * @CORS * - * @param string $url - * @param int $folderId + * @param string $url + * @param int|null $folderId * * @return array|mixed|JSONResponse */ - public function create(string $url, int $folderId = 0) + public function create(string $url, ?int $folderId = null) { + if ($folderId === 0) { + $folderId = null; + } + try { $this->feedService->purgeDeleted($this->getUserId(), false); @@ -169,13 +174,17 @@ class FeedApiController extends ApiController * @NoCSRFRequired * @CORS * - * @param int $feedId - * @param int $folderId + * @param int $feedId + * @param int|null $folderId * * @return array|JSONResponse */ - public function move(int $feedId, int $folderId) + public function move(int $feedId, ?int $folderId) { + if ($folderId === 0) { + $folderId = null; + } + try { $this->feedService->patch( $feedId, diff --git a/lib/Controller/FeedController.php b/lib/Controller/FeedController.php index c09096bd9..78df7be0c 100644 --- a/lib/Controller/FeedController.php +++ b/lib/Controller/FeedController.php @@ -105,6 +105,9 @@ class FeedController extends Controller // check if feed or folder exists try { if ($feedType === FeedType::FOLDER) { + if ($feedId === 0) { + $feedId = null; + } $this->folderService->find($this->userId, $feedId); } elseif ($feedType === FeedType::FEED) { $this->feedService->find($this->userId, $feedId); @@ -131,20 +134,23 @@ class FeedController extends Controller * @NoAdminRequired * * @param string $url - * @param int $parentFolderId - * @param string $title - * @param string $user - * @param string $password + * @param int|null $parentFolderId + * @param string|null $title + * @param string|null $user + * @param string|null $password * * @return array|JSONResponse */ public function create( string $url, - int $parentFolderId, + ?int $parentFolderId, ?string $title = null, ?string $user = null, ?string $password = null ) { + if ($parentFolderId === 0) { + $parentFolderId = null; + } try { // we need to purge deleted feeds if a feed is created to // prevent already exists exceptions @@ -290,13 +296,13 @@ class FeedController extends Controller /** * @NoAdminRequired * - * @param int $feedId - * @param bool $pinned - * @param bool $fullTextEnabled - * @param int $updateMode - * @param int $ordering - * @param int $folderId - * @param string $title + * @param int $feedId + * @param bool $pinned + * @param bool $fullTextEnabled + * @param int|null $updateMode + * @param int|null $ordering + * @param int|null $folderId + * @param string|null $title * * @return array|JSONResponse */ @@ -315,7 +321,7 @@ class FeedController extends Controller 'updateMode' => $updateMode, 'ordering' => $ordering, 'title' => $title, - 'folderId' => $folderId + 'folderId' => $folderId === 0 ? null : $folderId ]; $diff = array_filter( diff --git a/lib/Controller/FolderApiController.php b/lib/Controller/FolderApiController.php index 1f79d7cf9..691c67139 100644 --- a/lib/Controller/FolderApiController.php +++ b/lib/Controller/FolderApiController.php @@ -90,12 +90,16 @@ class FolderApiController extends ApiController * @NoCSRFRequired * @CORS * - * @param int $folderId + * @param int|null $folderId * * @return array|JSONResponse */ - public function delete(int $folderId) + public function delete(?int $folderId) { + if (empty($folderId)) { + return new JSONResponse([], Http::STATUS_BAD_REQUEST); + } + try { $this->folderService->delete($folderId, $this->getUserId()); } catch (ServiceNotFoundException $ex) { @@ -111,13 +115,17 @@ class FolderApiController extends ApiController * @NoCSRFRequired * @CORS * - * @param int $folderId - * @param string $name + * @param int|null $folderId + * @param string $name * * @return array|JSONResponse */ - public function update(int $folderId, string $name) + public function update(?int $folderId, string $name) { + if (empty($folderId)) { + return new JSONResponse([], Http::STATUS_BAD_REQUEST); + } + try { $this->folderService->rename($folderId, $name, $this->getUserId()); } catch (ServiceValidationException $ex) { @@ -137,11 +145,14 @@ class FolderApiController extends ApiController * @NoCSRFRequired * @CORS * - * @param int $folderId - * @param int $newestItemId + * @param int|null $folderId + * @param int $newestItemId */ - public function read(int $folderId, int $newestItemId): void + public function read(?int $folderId, int $newestItemId): void { + if ($folderId === 0) { + $folderId = null; + } $this->itemService->readFolder($folderId, $newestItemId, $this->getUserId()); } } diff --git a/lib/Controller/FolderController.php b/lib/Controller/FolderController.php index d19726963..09900f5b2 100644 --- a/lib/Controller/FolderController.php +++ b/lib/Controller/FolderController.php @@ -64,13 +64,15 @@ class FolderController extends Controller /** * @NoAdminRequired * - * @param int $folderId - * @param bool $open + * @param int|null $folderId + * @param bool $open * * @return array|JSONResponse */ - public function open(int $folderId, bool $open) + public function open(?int $folderId, bool $open) { + $folderId = $folderId === 0 ? null : $folderId; + try { $this->folderService->open($folderId, $open, $this->userId); } catch (ServiceException $ex) { @@ -108,12 +110,15 @@ class FolderController extends Controller /** * @NoAdminRequired * - * @param int $folderId + * @param int|null $folderId * * @return array|JSONResponse */ - public function delete(int $folderId) + public function delete(?int $folderId) { + if (empty($folderId)) { + return new JSONResponse([], Http::STATUS_BAD_REQUEST); + } try { $this->folderService->markDeleted($folderId, $this->userId); } catch (ServiceNotFoundException $ex) { @@ -127,13 +132,16 @@ class FolderController extends Controller /** * @NoAdminRequired * - * @param string $folderName - * @param int $folderId + * @param string $folderName + * @param int|null $folderId * * @return array|JSONResponse */ - public function rename(string $folderName, int $folderId) + public function rename(string $folderName, ?int $folderId) { + if (empty($folderId)) { + return new JSONResponse([], Http::STATUS_BAD_REQUEST); + } try { $folder = $this->folderService->rename( $folderId, @@ -154,12 +162,15 @@ class FolderController extends Controller /** * @NoAdminRequired * - * @param int $folderId - * @param int $highestItemId + * @param int|null $folderId + * @param int $highestItemId + * * @return array */ - public function read(int $folderId, int $highestItemId): array + public function read(?int $folderId, int $highestItemId): array { + $folderId = $folderId === 0 ? null : $folderId; + $this->itemService->readFolder( $folderId, $highestItemId, @@ -173,12 +184,14 @@ class FolderController extends Controller /** * @NoAdminRequired * - * @param int $folderId + * @param int|null $folderId * * @return array|JSONResponse */ - public function restore(int $folderId) + public function restore(?int $folderId) { + $folderId = $folderId === 0 ? null : $folderId; + try { $this->folderService->unmarkDeleted($folderId, $this->userId); } catch (ServiceNotFoundException $ex) { diff --git a/lib/Controller/UserApiController.php b/lib/Controller/UserApiController.php deleted file mode 100644 index b644ba1f0..000000000 --- a/lib/Controller/UserApiController.php +++ /dev/null @@ -1,74 +0,0 @@ -<?php -/** - * Nextcloud - News - * - * This file is licensed under the Affero General Public License version 3 or - * later. See the COPYING file. - * - * @author Alessandro Cosentino <cosenal@gmail.com> - * @author Bernhard Posselt <dev@bernhard-posselt.com> - * @author David Guillot <david@guillot.me> - * @copyright 2012 Alessandro Cosentino - * @copyright 2012-2014 Bernhard Posselt - * @copyright 2018 David Guillot - */ - -namespace OCA\News\Controller; - -use \OCP\IRequest; -use \OCP\IUserSession; -use \OCP\IURLGenerator; -use \OCP\Files\IRootFolder; -use \OCP\AppFramework\Http; - -class UserApiController extends ApiController -{ - - private $rootFolder; - - public function __construct( - string $appName, - IRequest $request, - IUserSession $userSession, - IRootFolder $rootFolder - ) { - parent::__construct($appName, $request, $userSession); - $this->rootFolder = $rootFolder; - } - - /** - * @NoAdminRequired - * @NoCSRFRequired - * @CORS - */ - public function index(): array - { - $user = $this->getUser(); - - // find the avatar - $jpgAvatar = '/' . $user->getUID() . '/avatar.jpg'; - $pngAvatar = '/' . $user->getUID() . '/avatar.png'; - $avatar = null; - - if ($this->rootFolder->nodeExists($jpgAvatar)) { - $file = $this->rootFolder->get($jpgAvatar); - $avatar = [ - 'data' => base64_encode($file->getContent()), - 'mime' => 'image/jpeg' - ]; - } elseif ($this->rootFolder->nodeExists($pngAvatar)) { - $file = $this->rootFolder->get($pngAvatar); - $avatar = [ - 'data' => base64_encode($file->getContent()), - 'mime' => 'image/png' - ]; - } - - return [ - 'userId' => $user->getUID(), - 'displayName' => $user->getDisplayName(), - 'lastLoginTimestamp' => $user->getLastLogin(), - 'avatar' => $avatar - ]; - } -} |