General: Fix folder query

Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
This commit is contained in:
Sean Molenaar 2021-02-16 21:17:10 +01:00 committed by Sean Molenaar
parent 01e1db329c
commit 4a107b3d53
14 changed files with 74 additions and 66 deletions

View File

@ -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'
TAG=$(curl --silent "https://api.github.com/repos/nextcloud/news/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
./occ news:item:list-feed "admin" $(./occ news:feed:list 'admin' | grep 'github\.com' -1 | head -1 | grep -oE '[0-9]*') --limit 200 | grep "$TAG"
./occ news:item:list-folder "admin" --limit 200 | grep "$TAG"
./occ news:item:list "admin" --limit 200 | grep "$TAG"
- name: Functional tests opml
working-directory: ../server

View File

@ -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

View File

@ -24,7 +24,7 @@ use OCP\IRequest;
use OCP\IConfig;
use OCP\AppFramework\Http;
use OCA\News\Db\FeedType;
use OCA\News\Db\ListType;
use OCP\IUserSession;
class FeedController extends Controller
@ -122,10 +122,10 @@ class FeedController extends Controller
$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:
@ -133,7 +133,7 @@ class FeedController extends Controller
}
} catch (ServiceNotFoundException $ex) {
$feedId = 0;
$feedType = FeedType::SUBSCRIPTIONS;
$feedType = ListType::ALL_ITEMS;
}
return [

View File

@ -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;
@ -73,7 +73,7 @@ class ItemApiController extends ApiController
bool $oldestFirst = false
): array {
switch ($type) {
case FeedType::FEED:
case ListType::FEED:
$items = $this->itemService->findAllInFeedWithFilters(
$this->getUserId(),
$id,
@ -83,7 +83,7 @@ class ItemApiController extends ApiController
$oldestFirst
);
break;
case FeedType::FOLDER:
case ListType::FOLDER:
$items = $this->itemService->findAllInFolderWithFilters(
$this->getUserId(),
$id,
@ -130,10 +130,10 @@ class ItemApiController extends ApiController
}
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:

View File

@ -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;
@ -136,7 +136,7 @@ class ItemController extends Controller
}
switch ($type) {
case FeedType::FEED:
case ListType::FEED:
$items = $this->itemService->findAllInFeedWithFilters(
$this->getUserId(),
$id,
@ -147,7 +147,7 @@ class ItemController extends Controller
$search_items
);
break;
case FeedType::FOLDER:
case ListType::FOLDER:
$items = $this->itemService->findAllInFolderWithFilters(
$this->getUserId(),
$id,
@ -201,7 +201,7 @@ class ItemController extends Controller
try {
switch ($type) {
case FeedType::FEED:
case ListType::FEED:
$items = $this->itemService->findAllInFeedAfter(
$this->getUserId(),
$id,
@ -209,7 +209,7 @@ class ItemController extends Controller
!$showAll
);
break;
case FeedType::FOLDER:
case ListType::FOLDER:
$items = $this->itemService->findAllInFolderAfter(
$this->getUserId(),
$id,

View File

@ -25,7 +25,7 @@ use OCP\AppFramework\Http\ContentSecurityPolicy;
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
@ -204,7 +204,7 @@ class PageController extends Controller
$this->getUserId(),
$this->appName,
'lastViewedFeedType',
FeedType::EXPLORE
ListType::EXPLORE
);
try {

View File

@ -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;
@ -386,12 +387,14 @@ class ItemMapperV2 extends NewsMapperV2
->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');
}
@ -473,7 +476,7 @@ class ItemMapperV2 extends NewsMapperV2
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.*')
@ -542,12 +545,14 @@ class ItemMapperV2 extends NewsMapperV2
}
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');
}

View File

@ -18,13 +18,13 @@ namespace OCA\News\Db;
*
* @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;
}

View File

@ -14,7 +14,7 @@ namespace OCA\News\Service;
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;
@ -307,7 +307,7 @@ class ItemServiceV2 extends Service
*/
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');
}

View File

@ -22,7 +22,7 @@ use OCA\News\Service\ItemServiceV2;
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;
@ -125,7 +125,7 @@ class FeedControllerTest extends TestCase
$this->exampleResult = [
'activeFeed' => [
'id' => 0,
'type' => FeedType::SUBSCRIPTIONS
'type' => ListType::ALL_ITEMS
]
];
}
@ -207,7 +207,7 @@ class FeedControllerTest extends TestCase
public function testActive()
{
$id = 3;
$type = FeedType::STARRED;
$type = ListType::STARRED;
$result = [
'activeFeed' => [
'id' => $id,
@ -226,7 +226,7 @@ class FeedControllerTest extends TestCase
public function testActiveFeed()
{
$id = 3;
$type = FeedType::FEED;
$type = ListType::FEED;
$result = [
'activeFeed' => [
'id' => $id,
@ -250,7 +250,7 @@ class FeedControllerTest extends TestCase
public function testActiveFeedDoesNotExist()
{
$id = 3;
$type = FeedType::FEED;
$type = ListType::FEED;
$ex = new ServiceNotFoundException('hiu');
$result = $this->exampleResult;
@ -269,7 +269,7 @@ class FeedControllerTest extends TestCase
public function testActiveFolder()
{
$type = FeedType::FOLDER;
$type = ListType::FOLDER;
$folder = new Folder();
$folder->setId(3);
@ -296,7 +296,7 @@ class FeedControllerTest extends TestCase
public function testActiveFolderDoesNotExist()
{
$id = 3;
$type = FeedType::FOLDER;
$type = ListType::FOLDER;
$ex = new ServiceNotFoundException('hiu');
$result = $this->exampleResult;

View File

@ -20,7 +20,7 @@ use \OCP\AppFramework\Http;
use \OCA\News\Db\Item;
use \OCA\News\Db\Feed;
use \OCA\News\Db\FeedType;
use \OCA\News\Db\ListType;
use \OCA\News\Service\Exceptions\ServiceNotFoundException;
use OCP\IConfig;
use OCP\IRequest;
@ -234,7 +234,7 @@ class ItemControllerTest extends TestCase
'starred' => 3
];
$this->itemsApiExpects(2, FeedType::FEED, '0');
$this->itemsApiExpects(2, ListType::FEED, '0');
$this->feedService->expects($this->once())
->method('findAllForUser')
@ -256,7 +256,7 @@ class ItemControllerTest extends TestCase
->with('user', 2, 3, 0, false, false, [])
->will($this->returnValue($result['items']));
$response = $this->controller->index(FeedType::FEED, 2, 3);
$response = $this->controller->index(ListType::FEED, 2, 3);
$this->assertEquals($result, $response);
}
@ -271,7 +271,7 @@ class ItemControllerTest extends TestCase
'starred' => 3
];
$this->itemsApiExpects(2, FeedType::FOLDER, '0');
$this->itemsApiExpects(2, ListType::FOLDER, '0');
$this->feedService->expects($this->once())
->method('findAllForUser')
@ -293,7 +293,7 @@ class ItemControllerTest extends TestCase
->with('user', 2, 3, 0, false, false, [])
->will($this->returnValue($result['items']));
$response = $this->controller->index(FeedType::FOLDER, 2, 3);
$response = $this->controller->index(ListType::FOLDER, 2, 3);
$this->assertEquals($result, $response);
}
@ -308,7 +308,7 @@ class ItemControllerTest extends TestCase
'starred' => 3
];
$this->itemsApiExpects(2, FeedType::STARRED, '0');
$this->itemsApiExpects(2, ListType::STARRED, '0');
$this->feedService->expects($this->once())
->method('findAllForUser')
@ -330,7 +330,7 @@ class ItemControllerTest extends TestCase
->with('user', 2, 3, 0, false, [])
->will($this->returnValue($result['items']));
$response = $this->controller->index(FeedType::STARRED, 2, 3);
$response = $this->controller->index(ListType::STARRED, 2, 3);
$this->assertEquals($result, $response);
}
@ -345,7 +345,7 @@ class ItemControllerTest extends TestCase
'starred' => 3
];
$this->itemsApiExpects(2, FeedType::FEED, '0');
$this->itemsApiExpects(2, ListType::FEED, '0');
$this->feedService->expects($this->once())
->method('findAllForUser')
@ -367,7 +367,7 @@ class ItemControllerTest extends TestCase
->with('user', 2, 3, 0, false, false, ['test', 'search'])
->will($this->returnValue($result['items']));
$response = $this->controller->index(FeedType::FEED, 2, 3, 0, null, null, 'test%20%20search%20');
$response = $this->controller->index(ListType::FEED, 2, 3, 0, null, null, 'test%20%20search%20');
$this->assertEquals($result, $response);
}
@ -376,7 +376,7 @@ class ItemControllerTest extends TestCase
{
$result = ['items' => [new Item()]];
$this->itemsApiExpects(2, FeedType::FEED);
$this->itemsApiExpects(2, ListType::FEED);
$this->itemService->expects($this->once())
->method('findAllInFeedWithFilters')
@ -386,21 +386,21 @@ class ItemControllerTest extends TestCase
$this->feedService->expects($this->never())
->method('findAllForUser');
$response = $this->controller->index(FeedType::FEED, 2, 3, 10);
$response = $this->controller->index(ListType::FEED, 2, 3, 10);
$this->assertEquals($result, $response);
}
public function testGetItemsNoNewestItemsId()
{
$this->itemsApiExpects(2, FeedType::FEED);
$this->itemsApiExpects(2, ListType::FEED);
$this->itemService->expects($this->once())
->method('newest')
->with('user')
->will($this->throwException(new ServiceNotFoundException('')));
$response = $this->controller->index(FeedType::FEED, 2, 3);
$response = $this->controller->index(ListType::FEED, 2, 3);
$this->assertEquals([], $response);
}
@ -440,7 +440,7 @@ class ItemControllerTest extends TestCase
->with('user', 2, 3, false)
->will($this->returnValue($result['items']));
$response = $this->controller->newItems(FeedType::FEED, 2, 3);
$response = $this->controller->newItems(ListType::FEED, 2, 3);
$this->assertEquals($result, $response);
}
@ -480,7 +480,7 @@ class ItemControllerTest extends TestCase
->with('user', 2, 3, false)
->will($this->returnValue($result['items']));
$response = $this->controller->newItems(FeedType::FOLDER, 2, 3);
$response = $this->controller->newItems(ListType::FOLDER, 2, 3);
$this->assertEquals($result, $response);
}
@ -520,7 +520,7 @@ class ItemControllerTest extends TestCase
->with('user', 6, 3)
->will($this->returnValue($result['items']));
$response = $this->controller->newItems(FeedType::UNREAD, 2, 3);
$response = $this->controller->newItems(ListType::UNREAD, 2, 3);
$this->assertEquals($result, $response);
}
@ -537,7 +537,7 @@ class ItemControllerTest extends TestCase
->with('user')
->will($this->throwException(new ServiceNotFoundException('')));
$response = $this->controller->newItems(FeedType::FEED, 2, 3);
$response = $this->controller->newItems(ListType::FEED, 2, 3);
$this->assertEquals([], $response);
}

View File

@ -15,7 +15,7 @@ namespace OCA\News\Tests\Unit\Controller;
use OC\L10N\L10N;
use OCA\News\Controller\PageController;
use \OCA\News\Db\FeedType;
use \OCA\News\Db\ListType;
use OCA\News\Explore\Exceptions\RecommendedSiteNotFoundException;
use OCA\News\Explore\RecommendedSites;
use OCA\News\Service\StatusService;
@ -264,7 +264,7 @@ class PageControllerTest extends TestCase
->method('setUserValue')
->withConsecutive(
['becka', 'news', 'lastViewedFeedId', 0],
['becka', 'news', 'lastViewedFeedType', FeedType::EXPLORE]
['becka', 'news', 'lastViewedFeedType', ListType::EXPLORE]
);
$this->recommended->expects($this->once())
@ -284,7 +284,7 @@ class PageControllerTest extends TestCase
->method('setUserValue')
->withConsecutive(
['becka', 'news', 'lastViewedFeedId', 0],
['becka', 'news', 'lastViewedFeedType', FeedType::EXPLORE]
['becka', 'news', 'lastViewedFeedType', ListType::EXPLORE]
);
$this->recommended->expects($this->once())

View File

@ -13,6 +13,7 @@
namespace OCA\News\Tests\Unit\Db;
use OC\DB\QueryBuilder\Literal;
use OCA\News\Db\Feed;
use OCA\News\Db\FeedMapperV2;
use OCA\News\Db\Folder;
@ -1691,7 +1692,7 @@ class ItemMapperTest extends MapperTestUtility
$expr->expects($this->once())
->method('eq')
->with('feeds.folder_id', 2)
->with('feeds.folder_id', new Literal(2))
->will($this->returnValue('x = y'));
$this->db->expects($this->once())

View File

@ -21,7 +21,7 @@ use OCA\News\Service\ItemServiceV2;
use \OCP\AppFramework\Db\DoesNotExistException;
use \OCA\News\Db\Item;
use \OCA\News\Db\FeedType;
use \OCA\News\Db\ListType;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\IConfig;
@ -133,7 +133,7 @@ class ItemServiceTest extends TestCase
$this->mapper->expects($this->never())
->method('findAllAfter');
$result = $this->class->findAllAfter($this->user, 3, 20333);
$result = $this->class->findAllAfter($this->user, 5, 20333);
$this->assertEquals([], $result);
}
@ -176,7 +176,7 @@ class ItemServiceTest extends TestCase
public function testFindAllItems()
{
$type = FeedType::STARRED;
$type = ListType::STARRED;
$this->mapper->expects($this->once())
->method('findAllItems')
->with('jack', $type, 20, 5, true, [])
@ -188,7 +188,7 @@ class ItemServiceTest extends TestCase
public function testFindAllSearch()
{
$type = FeedType::STARRED;
$type = ListType::STARRED;
$search = ['test'];