Skip to content

Commit

Permalink
General: Fix folder query
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Molenaar <[email protected]>
  • Loading branch information
SMillerDev committed Feb 20, 2021
1 parent 87848e7 commit df49f37
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 66 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/api-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,10 @@ jobs:
- name: Functional tests items
working-directory: ../server
run: |
./occ news:item:list-feed "admin" $(./occ news:feed:list 'admin' | grep 'github\.com' -1 | head -1 | grep -oE '[0-9]*') --limit 200 | grep '15.3.2'
./occ news:item:list-folder "admin" --limit 200 | grep '15.3.2'
./occ news:item:list "admin" --limit 200 | grep '15.3.2'
git -C apps/news fetch --tags
./occ news:item:list-feed "admin" $(./occ news:feed:list 'admin' | grep 'github\.com' -1 | head -1 | grep -oE '[0-9]*') --limit 200 | grep $(git -C apps/news describe --tags $(git rev-list --tags --max-count=1))
./occ news:item:list-folder "admin" --limit 200 | grep $(git -C apps/news describe --tags $(git rev-list --tags --max-count=1))
./occ news:item:list "admin" --limit 200 | grep $(git -C apps/news describe --tags $(git rev-list --tags --max-count=1))
- name: Functional tests opml
working-directory: ../server
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The format is almost based on [Keep a Changelog](https://keepachangelog.com/en/1
- Add CI for item lists

### Fixed
- Item list throwing error for folder and "all items"

## [15.3.2] - 2021-02-10
No changes compared to RC2
Expand Down
8 changes: 4 additions & 4 deletions lib/Controller/FeedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
use OCP\IConfig;
use OCP\AppFramework\Http;

use OCA\News\Db\FeedType;
use OCA\News\Db\ListType;
use OCP\IUserSession;

class FeedController extends Controller
Expand Down Expand Up @@ -122,18 +122,18 @@ public function active(): array

$feedType = intval($feedType);
switch ($feedType) {
case FeedType::FOLDER:
case ListType::FOLDER:
$this->folderService->find($this->getUserId(), $feedId);
break;
case FeedType::FEED:
case ListType::FEED:
$this->feedService->find($this->getUserId(), $feedId);
break;
default:
break;
}
} catch (ServiceNotFoundException $ex) {
$feedId = 0;
$feedType = FeedType::SUBSCRIPTIONS;
$feedType = ListType::ALL_ITEMS;
}

return [
Expand Down
10 changes: 5 additions & 5 deletions lib/Controller/ItemApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace OCA\News\Controller;

use OCA\News\Db\FeedType;
use OCA\News\Db\ListType;
use OCA\News\Service\Exceptions\ServiceConflictException;
use OCA\News\Service\Exceptions\ServiceValidationException;
use OCA\News\Service\ItemServiceV2;
Expand Down Expand Up @@ -73,7 +73,7 @@ public function index(
bool $oldestFirst = false
): array {
switch ($type) {
case FeedType::FEED:
case ListType::FEED:
$items = $this->itemService->findAllInFeedWithFilters(
$this->getUserId(),
$id,
Expand All @@ -83,7 +83,7 @@ public function index(
$oldestFirst
);
break;
case FeedType::FOLDER:
case ListType::FOLDER:
$items = $this->itemService->findAllInFolderWithFilters(
$this->getUserId(),
$id,
Expand Down Expand Up @@ -130,10 +130,10 @@ public function updated(int $type = 3, int $id = 0, int $lastModified = 0): arra
}

switch ($type) {
case FeedType::FEED:
case ListType::FEED:
$items = $this->itemService->findAllInFeedAfter($this->getUserId(), $id, $paddedLastModified, false);
break;
case FeedType::FOLDER:
case ListType::FOLDER:
$items = $this->itemService->findAllInFolderAfter($this->getUserId(), $id, $paddedLastModified, false);
break;
default:
Expand Down
10 changes: 5 additions & 5 deletions lib/Controller/ItemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace OCA\News\Controller;

use OCA\News\Db\FeedType;
use OCA\News\Db\ListType;
use OCA\News\Service\Exceptions\ServiceConflictException;
use OCA\News\Service\FeedServiceV2;
use OCP\AppFramework\Http\JSONResponse;
Expand Down Expand Up @@ -136,7 +136,7 @@ public function index(
}

switch ($type) {
case FeedType::FEED:
case ListType::FEED:
$items = $this->itemService->findAllInFeedWithFilters(
$this->getUserId(),
$id,
Expand All @@ -147,7 +147,7 @@ public function index(
$search_items
);
break;
case FeedType::FOLDER:
case ListType::FOLDER:
$items = $this->itemService->findAllInFolderWithFilters(
$this->getUserId(),
$id,
Expand Down Expand Up @@ -201,15 +201,15 @@ public function newItems(int $type, int $id, $lastModified = 0): array

try {
switch ($type) {
case FeedType::FEED:
case ListType::FEED:
$items = $this->itemService->findAllInFeedAfter(
$this->getUserId(),
$id,
$lastModified,
!$showAll
);
break;
case FeedType::FOLDER:
case ListType::FOLDER:
$items = $this->itemService->findAllInFolderAfter(
$this->getUserId(),
$id,
Expand Down
4 changes: 2 additions & 2 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

use OCA\News\Service\StatusService;
use OCA\News\Explore\RecommendedSites;
use OCA\News\Db\FeedType;
use OCA\News\Db\ListType;
use OCP\IUserSession;

class PageController extends Controller
Expand Down Expand Up @@ -204,7 +204,7 @@ public function explore(string $lang)
$this->getUserId(),
$this->appName,
'lastViewedFeedType',
FeedType::EXPLORE
ListType::EXPLORE
);

try {
Expand Down
15 changes: 10 additions & 5 deletions lib/Db/ItemMapperV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace OCA\News\Db;

use OC\DB\QueryBuilder\Literal;
use OCA\News\Service\Exceptions\ServiceValidationException;
use Doctrine\DBAL\FetchMode;
use OCA\News\Utility\Time;
Expand Down Expand Up @@ -386,12 +387,14 @@ public function findAllAfter(string $userId, int $feedType, int $updatedSince):
->addOrderBy('items.id', 'DESC');

switch ($feedType) {
case FeedType::STARRED:
case ListType::STARRED:
$builder->andWhere('items.starred = 1');
break;
case FeedType::UNREAD:
case ListType::UNREAD:
$builder->andWhere('items.unread = 1');
break;
case ListType::ALL_ITEMS:
break;
default:
throw new ServiceValidationException('Unexpected Feed type in call');
}
Expand Down Expand Up @@ -473,7 +476,7 @@ public function findAllFolder(
if ($folderId === null) {
$folderWhere = $builder->expr()->isNull('feeds.folder_id');
} else {
$folderWhere = $builder->expr()->eq('feeds.folder_id', $folderId);
$folderWhere = $builder->expr()->eq('feeds.folder_id', new Literal($folderId), IQueryBuilder::PARAM_INT);
}

$builder->select('items.*')
Expand Down Expand Up @@ -542,12 +545,14 @@ public function findAllItems(
}

switch ($type) {
case FeedType::STARRED:
case ListType::STARRED:
$builder->andWhere('items.starred = 1');
break;
case FeedType::UNREAD:
case ListType::UNREAD:
$builder->andWhere('items.unread = 1');
break;
case ListType::ALL_ITEMS:
break;
default:
throw new ServiceValidationException('Unexpected Feed type in call');
}
Expand Down
16 changes: 8 additions & 8 deletions lib/Db/ListType.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
*
* @package OCA\News\Db
*/
class FeedType
class ListType
{
const FEED = 0;
const FOLDER = 1;
const STARRED = 2;
const SUBSCRIPTIONS = 3;
const SHARED = 4;
const EXPLORE = 5;
const UNREAD = 6;
const FEED = 0;
const FOLDER = 1;
const STARRED = 2;
const ALL_ITEMS = 3;
const SHARED = 4;
const EXPLORE = 5;
const UNREAD = 6;
}
4 changes: 2 additions & 2 deletions lib/Service/ItemServiceV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use OCA\News\AppInfo\Application;
use OCA\News\Db\Feed;
use OCA\News\Db\FeedType;
use OCA\News\Db\ListType;
use OCA\News\Db\Item;
use OCA\News\Db\ItemMapperV2;
use OCA\News\Service\Exceptions\ServiceConflictException;
Expand Down Expand Up @@ -307,7 +307,7 @@ public function findAllInFolderAfter(string $userId, ?int $folderId, int $update
*/
public function findAllAfter(string $userId, int $feedType, int $updatedSince): array
{
if (!in_array($feedType, [FeedType::STARRED, FeedType::UNREAD])) {
if (!in_array($feedType, [ListType::STARRED, ListType::UNREAD, ListType::ALL_ITEMS])) {
throw new ServiceValidationException('Trying to find in unknown type');
}

Expand Down
14 changes: 7 additions & 7 deletions tests/Unit/Controller/FeedControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use OCP\AppFramework\Http;

use OCA\News\Db\Feed;
use OCA\News\Db\FeedType;
use OCA\News\Db\ListType;
use OCA\News\Service\Exceptions\ServiceNotFoundException;
use OCA\News\Service\Exceptions\ServiceConflictException;
use OCP\IConfig;
Expand Down Expand Up @@ -125,7 +125,7 @@ public function setUp(): void
$this->exampleResult = [
'activeFeed' => [
'id' => 0,
'type' => FeedType::SUBSCRIPTIONS
'type' => ListType::ALL_ITEMS
]
];
}
Expand Down Expand Up @@ -207,7 +207,7 @@ private function activeInitMocks($id, $type): void
public function testActive()
{
$id = 3;
$type = FeedType::STARRED;
$type = ListType::STARRED;
$result = [
'activeFeed' => [
'id' => $id,
Expand All @@ -226,7 +226,7 @@ public function testActive()
public function testActiveFeed()
{
$id = 3;
$type = FeedType::FEED;
$type = ListType::FEED;
$result = [
'activeFeed' => [
'id' => $id,
Expand All @@ -250,7 +250,7 @@ public function testActiveFeed()
public function testActiveFeedDoesNotExist()
{
$id = 3;
$type = FeedType::FEED;
$type = ListType::FEED;
$ex = new ServiceNotFoundException('hiu');
$result = $this->exampleResult;

Expand All @@ -269,7 +269,7 @@ public function testActiveFeedDoesNotExist()

public function testActiveFolder()
{
$type = FeedType::FOLDER;
$type = ListType::FOLDER;
$folder = new Folder();
$folder->setId(3);

Expand All @@ -296,7 +296,7 @@ public function testActiveFolder()
public function testActiveFolderDoesNotExist()
{
$id = 3;
$type = FeedType::FOLDER;
$type = ListType::FOLDER;
$ex = new ServiceNotFoundException('hiu');
$result = $this->exampleResult;

Expand Down
Loading

0 comments on commit df49f37

Please sign in to comment.