summaryrefslogtreecommitdiffstats
path: root/lib/Controller
diff options
context:
space:
mode:
authorSean Molenaar <sean@seanmolenaar.eu>2020-08-29 23:39:35 +0200
committerBenjamin Brahmer <info@b-brahmer.de>2020-09-27 15:35:31 +0200
commitd00d1ab2a28f428223e52b17052c072c64784016 (patch)
treec019f85fb7ac67147dd43ca64b4ac3cda99832f7 /lib/Controller
parent5687baca75d47dbdffd3de74e865ad2f71ef0cb7 (diff)
Create V2 mapper, Service and management commands
Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
Diffstat (limited to 'lib/Controller')
-rw-r--r--lib/Controller/ApiPayloadTrait.php36
-rw-r--r--lib/Controller/EntityApiSerializer.php6
-rw-r--r--lib/Controller/FeedApiController.php35
-rw-r--r--lib/Controller/FeedController.php12
-rw-r--r--lib/Controller/FolderApiController.php6
-rw-r--r--lib/Controller/FolderController.php6
-rw-r--r--lib/Controller/ItemApiController.php10
-rw-r--r--lib/Controller/ItemController.php6
-rw-r--r--lib/Controller/JSONHttpError.php7
-rw-r--r--lib/Controller/UtilityApiController.php21
10 files changed, 98 insertions, 47 deletions
diff --git a/lib/Controller/ApiPayloadTrait.php b/lib/Controller/ApiPayloadTrait.php
new file mode 100644
index 000000000..2bb31784e
--- /dev/null
+++ b/lib/Controller/ApiPayloadTrait.php
@@ -0,0 +1,36 @@
+<?php
+
+
+namespace OCA\News\Controller;
+
+use OCA\News\Db\IAPI;
+
+trait ApiPayloadTrait
+{
+ /**
+ * Serialize all data
+ *
+ * @param mixed $data IAPI or array,
+ * anything else will return an empty array
+ *
+ * @return array
+ */
+ public function serialize($data): array
+ {
+ $return = [];
+ if ($data instanceof IAPI) {
+ return [$data->toAPI()];
+ }
+
+ if (!is_array($data)) {
+ return $return;
+ }
+
+ foreach ($data as $entity) {
+ if ($entity instanceof IAPI) {
+ $return[] = $entity->toAPI();
+ }
+ }
+ return $return;
+ }
+}
diff --git a/lib/Controller/EntityApiSerializer.php b/lib/Controller/EntityApiSerializer.php
index 78a9b1031..c7fdb84e5 100644
--- a/lib/Controller/EntityApiSerializer.php
+++ b/lib/Controller/EntityApiSerializer.php
@@ -13,6 +13,12 @@ namespace OCA\News\Controller;
use \OCA\News\Db\IAPI;
+/**
+ * Class EntityApiSerializer
+ *
+ * @package OCA\News\Controller
+ * @deprecated use ApiPayloadTrait
+ */
class EntityApiSerializer
{
diff --git a/lib/Controller/FeedApiController.php b/lib/Controller/FeedApiController.php
index 160a8bcd6..f2b77c72b 100644
--- a/lib/Controller/FeedApiController.php
+++ b/lib/Controller/FeedApiController.php
@@ -15,6 +15,9 @@
namespace OCA\News\Controller;
+use OCA\News\Service\Exceptions\ServiceConflictException;
+use OCA\News\Service\Exceptions\ServiceNotFoundException;
+use OCA\News\Utility\PsrLogger;
use \OCP\IRequest;
use \OCP\ILogger;
use \OCP\IUserSession;
@@ -22,17 +25,30 @@ use \OCP\AppFramework\Http;
use \OCA\News\Service\FeedService;
use \OCA\News\Service\ItemService;
-use \OCA\News\Service\ServiceNotFoundException;
-use \OCA\News\Service\ServiceConflictException;
+use Psr\Log\LoggerInterface;
class FeedApiController extends ApiController
{
use JSONHttpError;
+ /**
+ * @var ItemService
+ */
private $itemService;
+
+ /**
+ * @var FeedService
+ */
private $feedService;
+
+ /**
+ * @var LoggerInterface
+ */
private $logger;
- private $loggerParams;
+
+ /**
+ * @var EntityApiSerializer
+ */
private $serializer;
public function __construct(
@@ -41,14 +57,12 @@ class FeedApiController extends ApiController
IUserSession $userSession,
FeedService $feedService,
ItemService $itemService,
- ILogger $logger,
- $LoggerParameters
+ LoggerInterface $logger
) {
parent::__construct($appName, $request, $userSession);
$this->feedService = $feedService;
$this->itemService = $itemService;
$this->logger = $logger;
- $this->loggerParams = $LoggerParameters;
$this->serializer = new EntityApiSerializer('feeds');
}
@@ -63,7 +77,7 @@ class FeedApiController extends ApiController
$result = [
'starredCount' => $this->itemService->starredCount($this->getUserId()),
- 'feeds' => $this->feedService->findAll($this->getUserId())
+ 'feeds' => $this->feedService->findAllForUser($this->getUserId())
];
@@ -226,13 +240,10 @@ class FeedApiController extends ApiController
public function update($userId, $feedId)
{
try {
- $this->feedService->update($feedId, $userId);
+ $this->feedService->update($userId, $feedId);
// ignore update failure
} catch (\Exception $ex) {
- $this->logger->debug(
- 'Could not update feed ' . $ex->getMessage(),
- $this->loggerParams
- );
+ $this->logger->debug('Could not update feed ' . $ex->getMessage());
}
}
}
diff --git a/lib/Controller/FeedController.php b/lib/Controller/FeedController.php
index 32e9bd232..40aef909a 100644
--- a/lib/Controller/FeedController.php
+++ b/lib/Controller/FeedController.php
@@ -13,6 +13,8 @@
namespace OCA\News\Controller;
+use OCA\News\Service\Exceptions\ServiceConflictException;
+use OCA\News\Service\Exceptions\ServiceNotFoundException;
use OCP\IRequest;
use OCP\IConfig;
use OCP\AppFramework\Controller;
@@ -21,8 +23,6 @@ use OCP\AppFramework\Http;
use OCA\News\Service\ItemService;
use OCA\News\Service\FeedService;
use OCA\News\Service\FolderService;
-use OCA\News\Service\ServiceNotFoundException;
-use OCA\News\Service\ServiceConflictException;
use OCA\News\Db\FeedType;
class FeedController extends Controller
@@ -63,7 +63,7 @@ class FeedController extends Controller
// because of this we also pass the starred count and the newest
// item id which will be used for marking feeds read
$params = [
- 'feeds' => $this->feedService->findAll($this->userId),
+ 'feeds' => $this->feedService->findAllForUser($this->userId),
'starred' => $this->itemService->starredCount($this->userId)
];
@@ -104,9 +104,9 @@ class FeedController extends Controller
// check if feed or folder exists
try {
if ($feedType === FeedType::FOLDER) {
- $this->folderService->find($feedId, $this->userId);
+ $this->folderService->find($this->userId, $feedId);
} elseif ($feedType === FeedType::FEED) {
- $this->feedService->find($feedId, $this->userId);
+ $this->feedService->find($this->userId, $feedId);
// if its the first launch, those values will be null
} elseif ($feedType === null) {
@@ -203,7 +203,7 @@ class FeedController extends Controller
public function update($feedId)
{
try {
- $feed = $this->feedService->update($feedId, $this->userId);
+ $feed = $this->feedService->update($this->userId, $feedId);
return [
'feeds' => [
diff --git a/lib/Controller/FolderApiController.php b/lib/Controller/FolderApiController.php
index eb98b8107..3bafd81a0 100644
--- a/lib/Controller/FolderApiController.php
+++ b/lib/Controller/FolderApiController.php
@@ -21,9 +21,9 @@ 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;
+use \OCA\News\Service\Exceptions\ServiceNotFoundException;
+use \OCA\News\Service\Exceptions\ServiceConflictException;
+use \OCA\News\Service\Exceptions\ServiceValidationException;
class FolderApiController extends ApiController
{
diff --git a/lib/Controller/FolderController.php b/lib/Controller/FolderController.php
index d3089178d..22baf8db6 100644
--- a/lib/Controller/FolderController.php
+++ b/lib/Controller/FolderController.php
@@ -20,9 +20,9 @@ use \OCP\AppFramework\Http;
use \OCA\News\Service\FolderService;
use \OCA\News\Service\FeedService;
use \OCA\News\Service\ItemService;
-use \OCA\News\Service\ServiceNotFoundException;
-use \OCA\News\Service\ServiceConflictException;
-use \OCA\News\Service\ServiceValidationException;
+use \OCA\News\Service\Exceptions\ServiceNotFoundException;
+use \OCA\News\Service\Exceptions\ServiceConflictException;
+use \OCA\News\Service\Exceptions\ServiceValidationException;
class FolderController extends Controller
{
diff --git a/lib/Controller/ItemApiController.php b/lib/Controller/ItemApiController.php
index cf4c7c730..d5b1de680 100644
--- a/lib/Controller/ItemApiController.php
+++ b/lib/Controller/ItemApiController.php
@@ -20,7 +20,7 @@ use \OCP\IUserSession;
use \OCP\AppFramework\Http;
use \OCA\News\Service\ItemService;
-use \OCA\News\Service\ServiceNotFoundException;
+use \OCA\News\Service\Exceptions\ServiceNotFoundException;
class ItemApiController extends ApiController
{
@@ -223,7 +223,7 @@ class ItemApiController extends ApiController
* @NoCSRFRequired
* @CORS
*
- * @param int[] item ids
+ * @param int[] $items item ids
*/
public function readMultiple($items)
{
@@ -236,7 +236,7 @@ class ItemApiController extends ApiController
* @NoCSRFRequired
* @CORS
*
- * @param int[] item ids
+ * @param int[] $items item ids
*/
public function unreadMultiple($items)
{
@@ -266,7 +266,7 @@ class ItemApiController extends ApiController
* @NoCSRFRequired
* @CORS
*
- * @param int[] item ids
+ * @param int[] $items item ids
*/
public function starMultiple($items)
{
@@ -279,7 +279,7 @@ class ItemApiController extends ApiController
* @NoCSRFRequired
* @CORS
*
- * @param int[] item ids
+ * @param int[] $items item ids
*/
public function unstarMultiple($items)
{
diff --git a/lib/Controller/ItemController.php b/lib/Controller/ItemController.php
index 156f4d1d4..658e92883 100644
--- a/lib/Controller/ItemController.php
+++ b/lib/Controller/ItemController.php
@@ -18,8 +18,8 @@ use \OCP\IConfig;
use \OCP\AppFramework\Controller;
use \OCP\AppFramework\Http;
-use \OCA\News\Service\ServiceException;
-use \OCA\News\Service\ServiceNotFoundException;
+use \OCA\News\Service\Exceptions\ServiceException;
+use \OCA\News\Service\Exceptions\ServiceNotFoundException;
use \OCA\News\Service\ItemService;
use \OCA\News\Service\FeedService;
@@ -245,7 +245,7 @@ class ItemController extends Controller
/**
* @NoAdminRequired
*
- * @param int[] item ids
+ * @param int[] $itemIds item ids
*/
public function readMultiple($itemIds)
{
diff --git a/lib/Controller/JSONHttpError.php b/lib/Controller/JSONHttpError.php
index 16d80f857..6a66f9c29 100644
--- a/lib/Controller/JSONHttpError.php
+++ b/lib/Controller/JSONHttpError.php
@@ -18,10 +18,9 @@ trait JSONHttpError
/**
- * @param \Exception $exception the message that is returned taken from the
- * exception
- * @param int $code the http error code
- * @return \OCP\AppFramework\Http\JSONResponse
+ * @param \Exception $exception The exception to report
+ * @param int $code The http error code
+ * @return JSONResponse
*/
public function error(\Exception $exception, $code)
{
diff --git a/lib/Controller/UtilityApiController.php b/lib/Controller/UtilityApiController.php
index ee9ca0900..23956f149 100644
--- a/lib/Controller/UtilityApiController.php
+++ b/lib/Controller/UtilityApiController.php
@@ -15,18 +15,17 @@
namespace OCA\News\Controller;
+use OCA\News\Service\UpdaterService;
use \OCP\IRequest;
use \OCP\IConfig;
use \OCP\IUserSession;
-use \OCP\AppFramework\Http;
-use \OCA\News\Utility\Updater;
use \OCA\News\Service\StatusService;
class UtilityApiController extends ApiController
{
- private $updater;
+ private $updaterService;
private $settings;
private $statusService;
@@ -34,12 +33,12 @@ class UtilityApiController extends ApiController
$appName,
IRequest $request,
IUserSession $userSession,
- Updater $updater,
+ UpdaterService $updater,
IConfig $settings,
StatusService $statusService
) {
parent::__construct($appName, $request, $userSession);
- $this->updater = $updater;
+ $this->updaterService = $updater;
$this->settings = $settings;
$this->statusService = $statusService;
}
@@ -50,7 +49,7 @@ class UtilityApiController extends ApiController
* @NoCSRFRequired
* @CORS
*/
- public function version()
+ public function version(): array
{
$version = $this->settings->getAppValue(
$this->appName,
@@ -64,9 +63,9 @@ class UtilityApiController extends ApiController
* @NoCSRFRequired
* @CORS
*/
- public function beforeUpdate()
+ public function beforeUpdate(): void
{
- $this->updater->beforeUpdate();
+ $this->updaterService->beforeUpdate();
}
@@ -74,9 +73,9 @@ class UtilityApiController extends ApiController
* @NoCSRFRequired
* @CORS
*/
- public function afterUpdate()
+ public function afterUpdate(): void
{
- $this->updater->afterUpdate();
+ $this->updaterService->afterUpdate();
}
@@ -85,7 +84,7 @@ class UtilityApiController extends ApiController
* @NoCSRFRequired
* @NoAdminRequired
*/
- public function status()
+ public function status(): array
{
return $this->statusService->getStatus();
}