summaryrefslogtreecommitdiffstats
path: root/lib/Controller
diff options
context:
space:
mode:
authorSean Molenaar <sean@seanmolenaar.eu>2020-11-03 21:56:37 +0100
committerSean Molenaar <SMillerDev@users.noreply.github.com>2020-11-03 23:12:01 +0100
commitaf2fd96825d6ae2c7802e9f3bac9054e85093396 (patch)
treee95ec3d0524f0153c0510f77aeee34f77c83e95f /lib/Controller
parentab149a7870281d4ed02806575734424849db755c (diff)
Controllers: Use v2 services
Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
Diffstat (limited to 'lib/Controller')
-rw-r--r--lib/Controller/AdminController.php20
-rw-r--r--lib/Controller/ApiController.php2
-rw-r--r--lib/Controller/FeedApiController.php66
-rw-r--r--lib/Controller/FeedController.php3
-rw-r--r--lib/Controller/FolderApiController.php26
-rw-r--r--lib/Controller/FolderController.php3
-rw-r--r--lib/Controller/ItemApiController.php75
7 files changed, 99 insertions, 96 deletions
diff --git a/lib/Controller/AdminController.php b/lib/Controller/AdminController.php
index e3551a2a1..059a0c4a7 100644
--- a/lib/Controller/AdminController.php
+++ b/lib/Controller/AdminController.php
@@ -20,8 +20,6 @@ use OCP\IConfig;
use OCP\IRequest;
use OCP\AppFramework\Controller;
-use OCA\News\Service\ItemService;
-
/**
* Class AdminController
*
@@ -36,27 +34,17 @@ class AdminController extends Controller
private $config;
/**
- * @var ItemService
- */
- private $itemService;
-
- /**
* AdminController constructor.
*
* @param string $appName The name of the app
* @param IRequest $request The request
* @param IConfig $config Config for nextcloud
- * @param ItemService $itemService Service for items
*/
- public function __construct(
- string $appName,
- IRequest $request,
- IConfig $config,
- ItemService $itemService
- ) {
+ public function __construct(string $appName, IRequest $request, IConfig $config)
+ {
parent::__construct($appName, $request);
- $this->config = $config;
- $this->itemService = $itemService;
+
+ $this->config = $config;
}
/**
diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php
index 544b2c23b..de7a0919c 100644
--- a/lib/Controller/ApiController.php
+++ b/lib/Controller/ApiController.php
@@ -41,7 +41,7 @@ class ApiController extends BaseApiController
* @param IRequest $request The request
* @param IUserSession $userSession The user session
*/
- public function __construct($appName, IRequest $request, IUserSession $userSession)
+ public function __construct(string $appName, IRequest $request, IUserSession $userSession)
{
parent::__construct($appName, $request);
$this->userSession = $userSession;
diff --git a/lib/Controller/FeedApiController.php b/lib/Controller/FeedApiController.php
index 400c1a4b2..ae2f8cdaf 100644
--- a/lib/Controller/FeedApiController.php
+++ b/lib/Controller/FeedApiController.php
@@ -15,12 +15,12 @@
namespace OCA\News\Controller;
+use Exception;
use OCA\News\Service\Exceptions\ServiceConflictException;
use OCA\News\Service\Exceptions\ServiceNotFoundException;
-use OCA\News\Utility\PsrLogger;
+use OCA\News\Service\FeedServiceV2;
use OCP\AppFramework\Http\JSONResponse;
use \OCP\IRequest;
-use \OCP\ILogger;
use \OCP\IUserSession;
use \OCP\AppFramework\Http;
@@ -31,19 +31,26 @@ use function GuzzleHttp\Psr7\uri_for;
class FeedApiController extends ApiController
{
- use JSONHttpErrorTrait;
+ use JSONHttpErrorTrait, ApiPayloadTrait;
/**
+ * TODO: Remove
* @var ItemService
*/
- private $itemService;
+ private $oldItemService;
/**
- * @var FeedService
+ * @var FeedServiceV2
*/
private $feedService;
/**
+ * TODO: Remove
+ * @var FeedService
+ */
+ private $oldFeedService;
+
+ /**
* @var LoggerInterface
*/
private $logger;
@@ -57,15 +64,16 @@ class FeedApiController extends ApiController
string $appName,
IRequest $request,
IUserSession $userSession,
- FeedService $feedService,
- ItemService $itemService,
+ FeedService $oldFeedService,
+ FeedServiceV2 $feedService,
+ ItemService $oldItemService,
LoggerInterface $logger
) {
parent::__construct($appName, $request, $userSession);
$this->feedService = $feedService;
- $this->itemService = $itemService;
+ $this->oldFeedService = $oldFeedService;
+ $this->oldItemService = $oldItemService;
$this->logger = $logger;
- $this->serializer = new EntityApiSerializer('feeds');
}
@@ -78,20 +86,17 @@ class FeedApiController extends ApiController
{
$result = [
- 'starredCount' => $this->itemService->starredCount($this->getUserId()),
- 'feeds' => $this->feedService->findAllForUser($this->getUserId())
+ 'starredCount' => $this->oldItemService->starredCount($this->getUserId()),
+ 'feeds' => $this->serialize($this->feedService->findAllForUser($this->getUserId()))
];
-
try {
- $result['newestItemId'] =
- $this->itemService->getNewestItemId($this->getUserId());
-
- // in case there are no items, ignore
+ $result['newestItemId'] = $this->oldItemService->getNewestItemId($this->getUserId());
} catch (ServiceNotFoundException $ex) {
+ // in case there are no items, ignore
}
- return $this->serializer->serialize($result);
+ return $result;
}
@@ -112,20 +117,18 @@ class FeedApiController extends ApiController
}
try {
- $this->feedService->purgeDeleted($this->getUserId(), false);
+ $this->feedService->purgeDeleted();
- $feed = $this->feedService->create($url, $folderId, $this->getUserId());
- $result = ['feeds' => [$feed]];
+ $feed = $this->feedService->create($this->getUserId(), $url, $folderId);
+ $result = ['feeds' => $this->serialize($feed)];
try {
- $result['newestItemId'] =
- $this->itemService->getNewestItemId($this->getUserId());
-
- // in case there are no items, ignore
+ $result['newestItemId'] = $this->oldItemService->getNewestItemId($this->getUserId());
} catch (ServiceNotFoundException $ex) {
+ // in case there are no items, ignore
}
- return $this->serializer->serialize($result);
+ return $result;
} catch (ServiceConflictException $ex) {
return $this->error($ex, Http::STATUS_CONFLICT);
} catch (ServiceNotFoundException $ex) {
@@ -165,7 +168,7 @@ class FeedApiController extends ApiController
*/
public function read(int $feedId, int $newestItemId): void
{
- $this->itemService->readFeed($feedId, $newestItemId, $this->getUserId());
+ $this->oldItemService->readFeed($feedId, $newestItemId, $this->getUserId());
}
@@ -186,7 +189,7 @@ class FeedApiController extends ApiController
}
try {
- $this->feedService->patch(
+ $this->oldFeedService->patch(
$feedId,
$this->getUserId(),
['folderId' => $folderId]
@@ -212,7 +215,7 @@ class FeedApiController extends ApiController
public function rename(int $feedId, string $feedTitle)
{
try {
- $this->feedService->patch(
+ $this->oldFeedService->patch(
$feedId,
$this->getUserId(),
['title' => $feedTitle]
@@ -231,7 +234,7 @@ class FeedApiController extends ApiController
*/
public function fromAllUsers(): array
{
- $feeds = $this->feedService->findAllFromAllUsers();
+ $feeds = $this->feedService->findAll();
$result = ['feeds' => []];
foreach ($feeds as $feed) {
@@ -254,9 +257,10 @@ class FeedApiController extends ApiController
public function update(string $userId, int $feedId): void
{
try {
- $this->feedService->update($userId, $feedId);
+ $feed = $this->feedService->find($userId, $feedId);
+ $this->feedService->fetch($feed);
// ignore update failure
- } catch (\Exception $ex) {
+ } catch (Exception $ex) {
$this->logger->debug('Could not update feed ' . $ex->getMessage());
}
}
diff --git a/lib/Controller/FeedController.php b/lib/Controller/FeedController.php
index 78df7be0c..5e2ba8a96 100644
--- a/lib/Controller/FeedController.php
+++ b/lib/Controller/FeedController.php
@@ -30,8 +30,11 @@ class FeedController extends Controller
{
use JSONHttpErrorTrait;
+ //TODO: Remove
private $feedService;
+ //TODO: Remove
private $folderService;
+ //TODO: Remove
private $itemService;
private $userId;
private $settings;
diff --git a/lib/Controller/FolderApiController.php b/lib/Controller/FolderApiController.php
index 691c67139..c9a6b67b7 100644
--- a/lib/Controller/FolderApiController.php
+++ b/lib/Controller/FolderApiController.php
@@ -20,31 +20,31 @@ use \OCP\IRequest;
use \OCP\IUserSession;
use \OCP\AppFramework\Http;
-use \OCA\News\Service\FolderService;
use \OCA\News\Service\ItemService;
+use \OCA\News\Service\FolderServiceV2;
use \OCA\News\Service\Exceptions\ServiceNotFoundException;
use \OCA\News\Service\Exceptions\ServiceConflictException;
use \OCA\News\Service\Exceptions\ServiceValidationException;
class FolderApiController extends ApiController
{
- use JSONHttpErrorTrait;
+ use JSONHttpErrorTrait, ApiPayloadTrait;
private $folderService;
+ //TODO: Remove
private $itemService;
- private $serializer;
public function __construct(
string $appName,
IRequest $request,
IUserSession $userSession,
- FolderService $folderService,
+ FolderServiceV2 $folderService,
ItemService $itemService
) {
parent::__construct($appName, $request, $userSession);
+
$this->folderService = $folderService;
$this->itemService = $itemService;
- $this->serializer = new EntityApiSerializer('folders');
}
@@ -55,9 +55,8 @@ class FolderApiController extends ApiController
*/
public function index()
{
- return $this->serializer->serialize(
- $this->folderService->findAllForUser($this->getUserId())
- );
+ $folders = $this->folderService->findAllForUser($this->getUserId());
+ return ['folders' => $this->serialize($folders)];
}
@@ -73,10 +72,9 @@ class FolderApiController extends ApiController
public function create(string $name)
{
try {
- $this->folderService->purgeDeleted($this->getUserId(), false);
- return $this->serializer->serialize(
- $this->folderService->create($name, $this->getUserId())
- );
+ $this->folderService->purgeDeleted();
+ $folder = $this->folderService->create($this->getUserId(), $name);
+ return ['folders' => $this->serialize($folder)];
} catch (ServiceValidationException $ex) {
return $this->error($ex, Http::STATUS_UNPROCESSABLE_ENTITY);
} catch (ServiceConflictException $ex) {
@@ -101,7 +99,7 @@ class FolderApiController extends ApiController
}
try {
- $this->folderService->delete($folderId, $this->getUserId());
+ $this->folderService->delete($this->getUserId(), $folderId);
} catch (ServiceNotFoundException $ex) {
return $this->error($ex, Http::STATUS_NOT_FOUND);
}
@@ -127,7 +125,7 @@ class FolderApiController extends ApiController
}
try {
- $this->folderService->rename($folderId, $name, $this->getUserId());
+ $this->folderService->rename($this->getUserId(), $folderId, $name);
} catch (ServiceValidationException $ex) {
return $this->error($ex, Http::STATUS_UNPROCESSABLE_ENTITY);
} catch (ServiceConflictException $ex) {
diff --git a/lib/Controller/FolderController.php b/lib/Controller/FolderController.php
index 09900f5b2..e67299c6d 100644
--- a/lib/Controller/FolderController.php
+++ b/lib/Controller/FolderController.php
@@ -30,8 +30,11 @@ class FolderController extends Controller
{
use JSONHttpErrorTrait;
+ //TODO: Remove
private $folderService;
+ //TODO: Remove
private $feedService;
+ //TODO: Remove
private $itemService;
private $userId;
diff --git a/lib/Controller/ItemApiController.php b/lib/Controller/ItemApiController.php
index 0ac0a890a..3e31d2fdd 100644
--- a/lib/Controller/ItemApiController.php
+++ b/lib/Controller/ItemApiController.php
@@ -15,30 +15,33 @@
namespace OCA\News\Controller;
+use OCA\News\Service\ItemService;
+use OCA\News\Service\ItemServiceV2;
use OCP\AppFramework\Http\JSONResponse;
use \OCP\IRequest;
use \OCP\IUserSession;
use \OCP\AppFramework\Http;
-use \OCA\News\Service\ItemService;
use \OCA\News\Service\Exceptions\ServiceNotFoundException;
class ItemApiController extends ApiController
{
- use JSONHttpErrorTrait;
+ use JSONHttpErrorTrait, ApiPayloadTrait;
+ private $oldItemService;
private $itemService;
- private $serializer;
public function __construct(
string $appName,
IRequest $request,
IUserSession $userSession,
- ItemService $itemService
+ ItemService $oldItemService,
+ ItemServiceV2 $itemService
) {
parent::__construct($appName, $request, $userSession);
+
+ $this->oldItemService = $oldItemService;
$this->itemService = $itemService;
- $this->serializer = new EntityApiSerializer('items');
}
@@ -63,17 +66,17 @@ class ItemApiController extends ApiController
int $offset = 0,
bool $oldestFirst = false
) {
- return $this->serializer->serialize(
- $this->itemService->findAllItems(
- $id,
- $type,
- $batchSize,
- $offset,
- $getRead,
- $oldestFirst,
- $this->getUserId()
- )
+ $items = $this->oldItemService->findAllItems(
+ $id,
+ $type,
+ $batchSize,
+ $offset,
+ $getRead,
+ $oldestFirst,
+ $this->getUserId()
);
+
+ return ['items' => $this->serialize($items)];
}
@@ -87,7 +90,7 @@ class ItemApiController extends ApiController
* @param int $lastModified
* @return array|mixed
*/
- public function updated($type = 3, $id = 0, $lastModified = 0)
+ public function updated(int $type = 3, int $id = 0, int $lastModified = 0)
{
// needs to be turned into a millisecond timestamp to work properly
if (strlen((string) $lastModified) <= 10) {
@@ -95,22 +98,22 @@ class ItemApiController extends ApiController
} else {
$paddedLastModified = $lastModified;
}
- return $this->serializer->serialize(
- $this->itemService->findAllNew(
- $id,
- $type,
- $paddedLastModified,
- true,
- $this->getUserId()
- )
+ $items = $this->oldItemService->findAllNew(
+ $id,
+ $type,
+ $paddedLastModified,
+ true,
+ $this->getUserId()
);
+
+ return ['items' => $this->serialize($items)];
}
- private function setRead($isRead, $itemId)
+ private function setRead(bool $isRead, int $itemId)
{
try {
- $this->itemService->read($itemId, $isRead, $this->getUserId());
+ $this->oldItemService->read($itemId, $isRead, $this->getUserId());
} catch (ServiceNotFoundException $ex) {
return $this->error($ex, Http::STATUS_NOT_FOUND);
}
@@ -149,10 +152,10 @@ class ItemApiController extends ApiController
}
- private function setStarred($isStarred, $feedId, $guidHash)
+ private function setStarred(bool $isStarred, int $feedId, string $guidHash)
{
try {
- $this->itemService->star(
+ $this->oldItemService->star(
$feedId,
$guidHash,
$isStarred,
@@ -207,15 +210,15 @@ class ItemApiController extends ApiController
*/
public function readAll(int $newestItemId)
{
- $this->itemService->readAll($newestItemId, $this->getUserId());
+ $this->oldItemService->readAll($newestItemId, $this->getUserId());
}
- private function setMultipleRead($isRead, $items)
+ private function setMultipleRead(bool $isRead, array $items)
{
foreach ($items as $id) {
try {
- $this->itemService->read($id, $isRead, $this->getUserId());
+ $this->oldItemService->read($id, $isRead, $this->getUserId());
} catch (ServiceNotFoundException $ex) {
continue;
}
@@ -249,11 +252,15 @@ class ItemApiController extends ApiController
}
- private function setMultipleStarred($isStarred, $items)
+ /**
+ * @param bool $isStarred
+ * @param array $items
+ */
+ private function setMultipleStarred(bool $isStarred, array $items)
{
foreach ($items as $item) {
try {
- $this->itemService->star(
+ $this->oldItemService->star(
$item['feedId'],
$item['guidHash'],
$isStarred,
@@ -284,7 +291,7 @@ class ItemApiController extends ApiController
* @NoCSRFRequired
* @CORS
*
- * @param int[] $items item ids
+ * @param array $items item ids
*/
public function unstarMultiple(array $items)
{