summaryrefslogtreecommitdiffstats
path: root/lib/Controller
diff options
context:
space:
mode:
authorSean Molenaar <sean@seanmolenaar.eu>2021-01-02 17:57:17 +0100
committerSean Molenaar <SMillerDev@users.noreply.github.com>2021-02-13 13:22:57 +0100
commitb4fa772bc5f23f84fc292f5d6bf884543d2bfe51 (patch)
tree8576ad3ea145f3644804e2fd93de462cfc2c2578 /lib/Controller
parentceba81060303e49b2617397397f2804516052ec9 (diff)
Remove V1 item API
Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
Diffstat (limited to 'lib/Controller')
-rw-r--r--lib/Controller/ApiController.php2
-rw-r--r--lib/Controller/FeedApiController.php27
-rw-r--r--lib/Controller/FeedController.php18
-rw-r--r--lib/Controller/FolderApiController.php25
-rw-r--r--lib/Controller/FolderController.php35
-rw-r--r--lib/Controller/ItemApiController.php157
-rw-r--r--lib/Controller/ItemController.php164
-rw-r--r--lib/Controller/PageController.php2
8 files changed, 256 insertions, 174 deletions
diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php
index a434f8de7..e6a83b21a 100644
--- a/lib/Controller/ApiController.php
+++ b/lib/Controller/ApiController.php
@@ -77,7 +77,7 @@ class ApiController extends BaseApiController
*
* @return array
*/
- public function index()
+ public function index(): array
{
return [
'apiLevels' => ['v1-2']
diff --git a/lib/Controller/FeedApiController.php b/lib/Controller/FeedApiController.php
index f247a4e66..43d92b7ca 100644
--- a/lib/Controller/FeedApiController.php
+++ b/lib/Controller/FeedApiController.php
@@ -19,12 +19,12 @@ use Exception;
use OCA\News\Service\Exceptions\ServiceConflictException;
use OCA\News\Service\Exceptions\ServiceNotFoundException;
use OCA\News\Service\FeedServiceV2;
+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 Psr\Log\LoggerInterface;
class FeedApiController extends ApiController
@@ -32,10 +32,9 @@ class FeedApiController extends ApiController
use JSONHttpErrorTrait, ApiPayloadTrait;
/**
- * TODO: Remove
- * @var ItemService
+ * @var ItemServiceV2
*/
- private $oldItemService;
+ private $itemService;
/**
* @var FeedServiceV2
@@ -51,12 +50,12 @@ class FeedApiController extends ApiController
IRequest $request,
?IUserSession $userSession,
FeedServiceV2 $feedService,
- ItemService $oldItemService,
+ ItemServiceV2 $itemService,
LoggerInterface $logger
) {
parent::__construct($request, $userSession);
$this->feedService = $feedService;
- $this->oldItemService = $oldItemService;
+ $this->itemService = $itemService;
$this->logger = $logger;
}
@@ -70,12 +69,12 @@ class FeedApiController extends ApiController
{
$result = [
- 'starredCount' => $this->oldItemService->starredCount($this->getUserId()),
+ 'starredCount' => count($this->itemService->starred($this->getUserId())),
'feeds' => $this->serialize($this->feedService->findAllForUser($this->getUserId()))
];
try {
- $result['newestItemId'] = $this->oldItemService->getNewestItemId($this->getUserId());
+ $result['newestItemId'] = $this->itemService->newest($this->getUserId())->getId();
} catch (ServiceNotFoundException $ex) {
// in case there are no items, ignore
}
@@ -96,9 +95,7 @@ class FeedApiController extends ApiController
*/
public function create(string $url, ?int $folderId = null)
{
- if ($folderId === 0) {
- $folderId = null;
- }
+ $folderId = $folderId === 0 ? null : $folderId;
try {
$this->feedService->purgeDeleted($this->getUserId(), time() - 600);
@@ -109,7 +106,7 @@ class FeedApiController extends ApiController
$this->feedService->fetch($feed);
try {
- $result['newestItemId'] = $this->oldItemService->getNewestItemId($this->getUserId());
+ $result['newestItemId'] = $this->itemService->newest($this->getUserId())->getId();
} catch (ServiceNotFoundException $ex) {
// in case there are no items, ignore
}
@@ -154,7 +151,7 @@ class FeedApiController extends ApiController
*/
public function read(int $feedId, int $newestItemId): void
{
- $this->oldItemService->readFeed($feedId, $newestItemId, $this->getUserId());
+ $this->itemService->read($this->getUserId(), $feedId, $newestItemId);
}
@@ -170,9 +167,7 @@ class FeedApiController extends ApiController
*/
public function move(int $feedId, ?int $folderId)
{
- if ($folderId === 0) {
- $folderId = null;
- }
+ $folderId = $folderId === 0 ? null : $folderId;
try {
$feed = $this->feedService->find($this->getUserId(), $feedId);
diff --git a/lib/Controller/FeedController.php b/lib/Controller/FeedController.php
index 9f7c9b0d6..681dda4bc 100644
--- a/lib/Controller/FeedController.php
+++ b/lib/Controller/FeedController.php
@@ -18,12 +18,12 @@ use OCA\News\Service\Exceptions\ServiceNotFoundException;
use OCA\News\Service\FeedServiceV2;
use OCA\News\Service\FolderServiceV2;
use OCA\News\Service\ImportService;
+use OCA\News\Service\ItemServiceV2;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;
use OCP\IConfig;
use OCP\AppFramework\Http;
-use OCA\News\Service\ItemService;
use OCA\News\Db\FeedType;
use OCP\IUserSession;
@@ -35,7 +35,9 @@ class FeedController extends Controller
* @var FeedServiceV2
*/
private $feedService;
- //TODO: Remove
+ /**
+ * @var ItemServiceV2
+ */
private $itemService;
/**
* @var FolderServiceV2
@@ -54,7 +56,7 @@ class FeedController extends Controller
IRequest $request,
FolderServiceV2 $folderService,
FeedServiceV2 $feedService,
- ItemService $itemService,
+ ItemServiceV2 $itemService,
ImportService $importService,
IConfig $settings,
?IUserSession $userSession
@@ -79,11 +81,11 @@ class FeedController extends Controller
// item id which will be used for marking feeds read
$params = [
'feeds' => $this->feedService->findAllForUser($this->getUserId()),
- 'starred' => $this->itemService->starredCount($this->getUserId())
+ 'starred' => count($this->itemService->starred($this->getUserId()))
];
try {
- $id = $this->itemService->getNewestItemId($this->getUserId());
+ $id = $this->itemService->newest($this->getUserId())->getId();
// An exception occurs if there is a newest item. If there is none,
// simply ignore it and do not add the newestItemId
@@ -183,7 +185,7 @@ class FeedController extends Controller
$this->feedService->fetch($feed);
try {
- $id = $this->itemService->getNewestItemId($this->getUserId());
+ $id = $this->itemService->newest($this->getUserId())->getId();
// An exception occurs if there is a newest item. If there is none,
// simply ignore it and do not add the newestItemId
$params['newestItemId'] = $id;
@@ -261,7 +263,7 @@ class FeedController extends Controller
$feed = $this->importService->importArticles($this->getUserId(), $json);
$params = [
- 'starred' => $this->itemService->starredCount($this->getUserId())
+ 'starred' => count($this->itemService->starred($this->getUserId()))
];
if ($feed) {
@@ -281,7 +283,7 @@ class FeedController extends Controller
*/
public function read(int $feedId, int $highestItemId): array
{
- $this->itemService->readFeed($feedId, $highestItemId, $this->getUserId());
+ $this->feedService->read($this->getUserId(), $feedId, $highestItemId);
return [
'feeds' => [
diff --git a/lib/Controller/FolderApiController.php b/lib/Controller/FolderApiController.php
index 8de4b9e69..71fc503e2 100644
--- a/lib/Controller/FolderApiController.php
+++ b/lib/Controller/FolderApiController.php
@@ -20,7 +20,6 @@ use \OCP\IRequest;
use \OCP\IUserSession;
use \OCP\AppFramework\Http;
-use \OCA\News\Service\ItemService;
use \OCA\News\Service\FolderServiceV2;
use \OCA\News\Service\Exceptions\ServiceNotFoundException;
use \OCA\News\Service\Exceptions\ServiceConflictException;
@@ -30,20 +29,19 @@ class FolderApiController extends ApiController
{
use JSONHttpErrorTrait, ApiPayloadTrait;
+ /**
+ * @var FolderServiceV2
+ */
private $folderService;
- //TODO: Remove
- private $itemService;
public function __construct(
IRequest $request,
?IUserSession $userSession,
- FolderServiceV2 $folderService,
- ItemService $itemService
+ FolderServiceV2 $folderService
) {
parent::__construct($request, $userSession);
$this->folderService = $folderService;
- $this->itemService = $itemService;
}
@@ -52,7 +50,7 @@ class FolderApiController extends ApiController
* @NoCSRFRequired
* @CORS
*/
- public function index()
+ public function index(): array
{
$folders = $this->folderService->findAllForUser($this->getUserId());
return ['folders' => $this->serialize($folders)];
@@ -142,14 +140,13 @@ class FolderApiController extends ApiController
* @NoCSRFRequired
* @CORS
*
- * @param int|null $folderId
- * @param int $newestItemId
+ * @param int|null $folderId ID of the folder
+ * @param int $maxItemId The newest read item
*/
- public function read(?int $folderId, int $newestItemId): void
+ public function read(?int $folderId, int $maxItemId): void
{
- if ($folderId === 0) {
- $folderId = null;
- }
- $this->itemService->readFolder($folderId, $newestItemId, $this->getUserId());
+ $folderId = $folderId === 0 ? null : $folderId;
+
+ $this->folderService->read($this->getUserId(), $folderId, $maxItemId);
}
}
diff --git a/lib/Controller/FolderController.php b/lib/Controller/FolderController.php
index 9dc13b309..da03f9863 100644
--- a/lib/Controller/FolderController.php
+++ b/lib/Controller/FolderController.php
@@ -14,13 +14,11 @@
namespace OCA\News\Controller;
use OCA\News\Service\Exceptions\ServiceException;
-use OCA\News\Service\FeedServiceV2;
use OCP\AppFramework\Http\JSONResponse;
use \OCP\IRequest;
use \OCP\AppFramework\Http;
use \OCA\News\Service\FolderServiceV2;
-use \OCA\News\Service\ItemService;
use \OCA\News\Service\Exceptions\ServiceNotFoundException;
use \OCA\News\Service\Exceptions\ServiceConflictException;
use OCP\IUserSession;
@@ -33,24 +31,14 @@ class FolderController extends Controller
* @var FolderServiceV2
*/
private $folderService;
- /**
- * @var FeedServiceV2
- */
- private $feedService;
- //TODO: Remove
- private $itemService;
public function __construct(
IRequest $request,
FolderServiceV2 $folderService,
- FeedServiceV2 $feedService,
- ItemService $itemService,
?IUserSession $userSession
) {
parent::__construct($request, $userSession);
$this->folderService = $folderService;
- $this->feedService = $feedService;
- $this->itemService = $itemService;
}
@@ -134,12 +122,12 @@ class FolderController extends Controller
/**
* @NoAdminRequired
*
- * @param string $folderName
- * @param int|null $folderId
+ * @param int|null $folderId The ID of the folder
+ * @param string $folderName The new name of the folder
*
* @return array|JSONResponse
*/
- public function rename(string $folderName, ?int $folderId)
+ public function rename(?int $folderId, string $folderName)
{
if (empty($folderId)) {
return new JSONResponse([], Http::STATUS_BAD_REQUEST);
@@ -159,21 +147,18 @@ class FolderController extends Controller
* @NoAdminRequired
*
* @param int|null $folderId
- * @param int $highestItemId
+ * @param int $maxItemId
+ *
+ * @return void
*
- * @return array
+ * @throws ServiceConflictException
+ * @throws ServiceNotFoundException
*/
- public function read(?int $folderId, int $highestItemId): array
+ public function read(?int $folderId, int $maxItemId): void
{
$folderId = $folderId === 0 ? null : $folderId;
- $this->itemService->readFolder(
- $folderId,
- $highestItemId,
- $this->getUserId()
- );
- $feeds = $this->feedService->findAllForUser($this->getUserId());
- return ['feeds' => $this->serialize($feeds)];
+ $this->folderService->read($this->getUserId(), $folderId, $maxItemId);
}
diff --git a/lib/Controller/ItemApiController.php b/lib/Controller/ItemApiController.php
index 7ec43bc5c..003c61fa2 100644
--- a/lib/Controller/ItemApiController.php
+++ b/lib/Controller/ItemApiController.php
@@ -15,7 +15,9 @@
namespace OCA\News\Controller;
-use OCA\News\Service\ItemService;
+use OCA\News\Db\FeedType;
+use OCA\News\Service\Exceptions\ServiceConflictException;
+use OCA\News\Service\Exceptions\ServiceValidationException;
use OCA\News\Service\ItemServiceV2;
use OCP\AppFramework\Http\JSONResponse;
use \OCP\IRequest;
@@ -24,22 +26,27 @@ use \OCP\AppFramework\Http;
use \OCA\News\Service\Exceptions\ServiceNotFoundException;
+/**
+ * Class ItemApiController
+ *
+ * @package OCA\News\Controller
+ */
class ItemApiController extends ApiController
{
use JSONHttpErrorTrait, ApiPayloadTrait;
- private $oldItemService;
+ /**
+ * @var ItemServiceV2
+ */
private $itemService;
public function __construct(
IRequest $request,
?IUserSession $userSession,
- ItemService $oldItemService,
ItemServiceV2 $itemService
) {
parent::__construct($request, $userSession);
- $this->oldItemService = $oldItemService;
$this->itemService = $itemService;
}
@@ -64,16 +71,38 @@ class ItemApiController extends ApiController
int $batchSize = -1,
int $offset = 0,
bool $oldestFirst = false
- ) {
- $items = $this->oldItemService->findAllItems(
- $id,
- $type,
- $batchSize,
- $offset,
- $getRead,
- $oldestFirst,
- $this->getUserId()
- );
+ ): array {
+ switch ($type) {
+ case FeedType::FEED:
+ $items = $this->itemService->findAllInFeedWithFilters(
+ $this->getUserId(),
+ $id,
+ $batchSize,
+ $offset,
+ !$getRead,
+ $oldestFirst
+ );
+ break;
+ case FeedType::FOLDER:
+ $items = $this->itemService->findAllInFolderWithFilters(
+ $this->getUserId(),
+ $id,
+ $batchSize,
+ $offset,
+ !$getRead,
+ $oldestFirst
+ );
+ break;
+ default:
+ $items = $this->itemService->findAllWithFilters(
+ $this->getUserId(),
+ $type,
+ $batchSize,
+ $offset,
+ $oldestFirst
+ );
+ break;
+ }
return ['items' => $this->serialize($items)];
}
@@ -88,8 +117,10 @@ class ItemApiController extends ApiController
* @param int $id
* @param int $lastModified
* @return array|JSONResponse
+ *
+ * @throws ServiceValidationException
*/
- public function updated(int $type = 3, int $id = 0, int $lastModified = 0)
+ public function updated(int $type = 3, int $id = 0, int $lastModified = 0): array
{
// needs to be turned into a millisecond timestamp to work properly
if (strlen((string) $lastModified) <= 10) {
@@ -97,27 +128,33 @@ class ItemApiController extends ApiController
} else {
$paddedLastModified = $lastModified;
}
- $items = $this->oldItemService->findAllNew(
- $id,
- $type,
- (int) $paddedLastModified,
- true,
- $this->getUserId()
- );
+
+ switch ($type) {
+ case FeedType::FEED:
+ $items = $this->itemService->findAllInFeedAfter($this->getUserId(), $id, $paddedLastModified, false);
+ break;
+ case FeedType::FOLDER:
+ $items = $this->itemService->findAllInFolderAfter($this->getUserId(), $id, $paddedLastModified, false);
+ break;
+ default:
+ $items = $this->itemService->findAllAfter($this->getUserId(), $type, $paddedLastModified);
+ break;
+ }
return ['items' => $this->serialize($items)];
}
-
/**
- * @return JSONResponse|array
+ * @param int $itemId
+ * @param bool $isRead
*
- * @psalm-return JSONResponse|array<empty, empty>
+ * @return array|JSONResponse
+ * @throws ServiceConflictException
*/
- private function setRead(bool $isRead, int $itemId)
+ private function setRead(int $itemId, bool $isRead)
{
try {
- $this->oldItemService->read($itemId, $isRead, $this->getUserId());
+ $this->itemService->read($this->getUserId(), $itemId, $isRead);
} catch (ServiceNotFoundException $ex) {
return $this->error($ex, Http::STATUS_NOT_FOUND);
}
@@ -134,10 +171,11 @@ class ItemApiController extends ApiController
* @param int $itemId
*
* @return array|JSONResponse
+ * @throws ServiceConflictException
*/
public function read(int $itemId)
{
- return $this->setRead(true, $itemId);
+ return $this->setRead($itemId, true);
}
@@ -149,27 +187,25 @@ class ItemApiController extends ApiController
* @param int $itemId
*
* @return array|JSONResponse
+ * @throws ServiceConflictException
*/
public function unread(int $itemId)
{
- return $this->setRead(false, $itemId);
+ return $this->setRead($itemId, false);
}
-
/**
- * @return JSONResponse|array
+ * @param int $feedId
+ * @param string $guidHash
+ * @param bool $isStarred
*
- * @psalm-return JSONResponse|array<empty, empty>
+ * @return array|JSONResponse
+ * @throws ServiceConflictException
*/
- private function setStarred(bool $isStarred, int $feedId, string $guidHash)
+ private function setStarred(int $feedId, string $guidHash, bool $isStarred)
{
try {
- $this->oldItemService->star(
- $feedId,
- $guidHash,
- $isStarred,
- $this->getUserId()
- );
+ $this->itemService->starByGuid($this->getUserId(), $feedId, $guidHash, $isStarred);
} catch (ServiceNotFoundException $ex) {
return $this->error($ex, Http::STATUS_NOT_FOUND);
}
@@ -187,10 +223,11 @@ class ItemApiController extends ApiController
* @param string $guidHash
*
* @return array|JSONResponse
+ * @throws ServiceConflictException
*/
public function star(int $feedId, string $guidHash)
{
- return $this->setStarred(true, $feedId, $guidHash);
+ return $this->setStarred($feedId, $guidHash, true);
}
@@ -203,10 +240,11 @@ class ItemApiController extends ApiController
* @param string $guidHash
*
* @return array|JSONResponse
+ * @throws ServiceConflictException
*/
public function unstar(int $feedId, string $guidHash)
{
- return $this->setStarred(false, $feedId, $guidHash);
+ return $this->setStarred($feedId, $guidHash, false);
}
@@ -223,15 +261,20 @@ class ItemApiController extends ApiController
*/
public function readAll(int $newestItemId): void
{
- $this->oldItemService->readAll($newestItemId, $this->getUserId());
+ $this->itemService->readAll($this->getUserId(), $newestItemId);
}
-
- private function setMultipleRead(bool $isRead, array $items): void
+ /**
+ * @param array $items
+ * @param bool $isRead
+ *
+ * @throws ServiceConflictException
+ */
+ private function setMultipleRead(array $items, bool $isRead): void
{
foreach ($items as $id) {
try {
- $this->oldItemService->read($id, $isRead, $this->getUserId());
+ $this->itemService->read($this->getUserId(), $id, $isRead);
} catch (ServiceNotFoundException $ex) {
continue;
}
@@ -249,10 +292,12 @@ class ItemApiController extends ApiController
* @param int[] $items item ids
*
* @return void
+ *
+ * @throws ServiceConflictException
*/
public function readMultiple(array $items): void
{
- $this->setMultipleRead(true, $items);
+ $this->setMultipleRead($items, true);
}
@@ -266,30 +311,32 @@ class ItemApiController extends ApiController
* @param int[] $items item ids
*
* @return void
+ *
+ * @throws ServiceConflictException
*/
public function unreadMultiple(array $items): void
{
- $this->setMultipleRead(false, $items);
+ $this->setMultipleRead($items, false);
}
/**
- * @param bool $isStarred
* @param array $items
+ * @param bool $isStarred
*
* @return void
*/
- private function setMultipleStarred(bool $isStarred, array $items): void
+ private function setMultipleStarred(array $items, bool $isStarred): void
{
foreach ($items as $item) {
try {
- $this->oldItemService->star(
+ $this->itemService->starByGuid(
+ $this->getUserId(),
$item['feedId'],
$item['guidHash'],
- $isStarred,
- $this->getUserId()
+ $isStarred
);
- } catch (ServiceNotFoundException $ex) {
+ } catch (ServiceNotFoundException | ServiceConflictException $ex) {
continue;
}
}
@@ -309,7 +356,7 @@ class ItemApiController extends ApiController
*/
public function starMultiple(array $items): void
{
- $this->setMultipleStarred(true, $items);
+ $this->setMultipleStarred($items, true);
}
@@ -326,6 +373,6 @@ class ItemApiController extends ApiController
*/
public function unstarMultiple(array $items): void
{
- $this->setMultipleStarred(false, $items);
+ $this->setMultipleStarred($items, false);
}
}
diff --git a/lib/Controller/ItemController.php b/lib/Controller/ItemController.php
index 96ebcbaec..02a308d87 100644
--- a/lib/Controller/ItemController.php
+++ b/lib/Controller/ItemController.php
@@ -13,20 +13,31 @@
namespace OCA\News\Controller;
+use OCA\News\Db\FeedType;
+use OCA\News\Service\Exceptions\ServiceConflictException;
use OCA\News\Service\FeedServiceV2;
+use OCP\AppFramework\Http\JSONResponse;
use \OCP\IRequest;
use \OCP\IConfig;
use \OCP\AppFramework\Http;
use \OCA\News\Service\Exceptions\ServiceException;
use \OCA\News\Service\Exceptions\ServiceNotFoundException;
-use \OCA\News\Service\ItemService;
+use \OCA\News\Service\ItemServiceV2;
use OCP\IUserSession;
+/**
+ * Class ItemController
+ *
+ * @package OCA\News\Controller
+ */
class ItemController extends Controller
{
use JSONHttpErrorTrait;
+ /**
+ * @var ItemServiceV2
+ */
private $itemService;
/**
* @var FeedServiceV2
@@ -40,7 +51,7 @@ class ItemController extends Controller
public function __construct(
IRequest $request,
FeedServiceV2 $feedService,
- ItemService $itemService,
+ ItemServiceV2 $itemService,
IConfig $settings,
?IUserSession $userSession
) {
@@ -71,7 +82,7 @@ class ItemController extends Controller
?bool $showAll = null,
?bool $oldestFirst = null,
string $search = ''
- ) {
+ ): array {
// in case this is called directly and not from the website use the
// internal state
@@ -104,15 +115,14 @@ class ItemController extends Controller
$type
);
- $params = [];
+ $return = [];
// split search parameter on url space
- $search = trim(urldecode($search));
- $search = preg_replace('/\s+/', ' ', $search); // remove multiple ws
- if ($search === '') {
- $search = [];
- } else {
- $search = explode(' ', $search);
+ $search_string = trim(urldecode($search));
+ $search_string = preg_replace('/\s+/', ' ', $search_string); // remove multiple ws
+ $search_items = [];
+ if ($search !== '') {
+ $search_items = explode(' ', $search_string);
}
try {
@@ -120,30 +130,54 @@ class ItemController extends Controller
// we need to pass the newest feeds to not let the unread count get
// out of sync
if ($offset === 0) {
- $params['newestItemId'] =
- $this->itemService->getNewestItemId($this->getUserId());
- $params['feeds'] = $this->feedService->findAllForUser($this->getUserId());
- $params['starred'] =
- $this->itemService->starredCount($this->getUserId());
+ $return['newestItemId'] = $this->itemService->newest($this->getUserId())->getId();
+ $return['feeds'] = $this->feedService->findAllForUser($this->getUserId());
+ $return['starred'] = count($this->itemService->starred($this->getUserId()));
}
- $params['items'] = $this->itemService->findAllItems(
- $id,
- $type,
- $limit,
- $offset,
- $showAll,
- $oldestFirst,
- $this->getUserId(),
- $search
- );
+ switch ($type) {
+ case FeedType::FEED:
+ $items = $this->itemService->findAllInFeedWithFilters(
+ $this->getUserId(),
+ $id,
+ $limit,
+ $offset,
+ !$showAll,
+ $oldestFirst,
+ $search_items
+ );
+ break;
+ case FeedType::FOLDER:
+ $items = $this->itemService->findAllInFolderWithFilters(
+ $this->getUserId(),
+ $id,
+ $limit,
+ $offset,
+ !$showAll,
+ $oldestFirst,
+ $search_items
+ );
+ break;
+ default:
+ $items = $this->itemService->findAllWithFilters(
+ $this->getUserId(),
+ $type,
+ $limit,
+ $offset,
+ $oldestFirst,
+ $search_items
+ );
+ break;
+ }
+ $return['items'] = $items;
// this gets thrown if there are no items
// in that case just return an empty array
} catch (ServiceException $ex) {
+ //NO-OP
}
- return $params;
+ return $return;
}
@@ -155,7 +189,7 @@ class ItemController extends Controller
* @param int $lastModified
* @return array
*/
- public function newItems($type, $id, $lastModified = 0)
+ public function newItems(int $type, int $id, $lastModified = 0): array
{
$showAll = $this->settings->getUserValue(
$this->getUserId(),
@@ -163,28 +197,47 @@ class ItemController extends Controller
'showAll'
) === '1';
- $params = [];
+ $return = [];
try {
- $params['newestItemId'] =
- $this->itemService->getNewestItemId($this->getUserId());
- $params['feeds'] = $this->feedService->findAllForUser($this->getUserId());
- $params['starred'] =
- $this->itemService->starredCount($this->getUserId());
- $params['items'] = $this->itemService->findAllNew(
- $id,
- $type,
- $lastModified,
- $showAll,
- $this->getUserId()
- );
+ switch ($type) {
+ case FeedType::FEED:
+ $items = $this->itemService->findAllInFeedAfter(
+ $this->getUserId(),
+ $id,
+ $lastModified,
+ !$showAll
+ );
+ break;
+ case FeedType::FOLDER:
+ $items = $this->itemService->findAllInFolderAfter(
+ $this->getUserId(),
+ $id,
+ $lastModified,
+ !$showAll
+ );
+ break;
+ default:
+ $items = $this->itemService->findAllAfter(
+ $this->getUserId(),
+ $type,
+ $lastModified
+ );
+ break;
+ }
+
+ $return['newestItemId'] = $this->itemService->newest($this->getUserId())->getId();
+ $return['feeds'] = $this->feedService->findAllForUser($this->getUserId());
+ $return['starred'] = count($this->itemService->starred($this->getUserId()));
+ $return['items'] = $items;
// this gets thrown if there are no items
// in that case just return an empty array
} catch (ServiceException $ex) {
+ //NO-OP
}
- return $params;
+ return $return;
}
@@ -194,16 +247,17 @@ class ItemController extends Controller
* @param int $feedId
* @param string $guidHash
* @param bool $isStarred
- * @return array|\OCP\AppFramework\Http\JSONResponse
+ *
+ * @return array|JSONResponse
*/
- public function star($feedId, $guidHash, $isStarred)
+ public function star(int $feedId, string $guidHash, bool $isStarred)
{
try {
- $this->itemService->star(
+ $this->itemService->starByGuid(
+ $this->getUserId(),