summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-08-02 14:34:08 +0200
committerBernhard Posselt <nukeawhale@gmail.com>2013-08-02 14:34:08 +0200
commit27c7c7773eaaa0aa15fbf5bffeee501941d0d339 (patch)
tree18b1bcdb4e3d06c509d519cdb1865a626190c930
parent3b3b5b9033b060bc8428a397b34ccb2cad0d8307 (diff)
add api for updating feeds with a seperate cron job, #301
-rw-r--r--appinfo/routes.php12
-rw-r--r--businesslayer/feedbusinesslayer.php9
-rw-r--r--external/feedapi.php43
-rw-r--r--tests/unit/businesslayer/FeedBusinessLayerTest.php35
-rw-r--r--tests/unit/external/FeedAPITest.php62
5 files changed, 150 insertions, 11 deletions
diff --git a/appinfo/routes.php b/appinfo/routes.php
index 7bb3ba40c..25eb04dc2 100644
--- a/appinfo/routes.php
+++ b/appinfo/routes.php
@@ -275,12 +275,24 @@ $this->create('news_api_feeds_get_all', '/api/v1-2/feeds')->get()->action(
}
);
+$this->create('news_api_feeds_get_all_from_all_users', '/api/v1-2/feeds/all')->get()->action(
+ function($params) {
+ return App::main('FeedAPI', 'getAllFromAllUsers', $params, new DIContainer());
+ }
+);
+
$this->create('news_api_feeds_create', '/api/v1-2/feeds')->post()->action(
function($params) {
return App::main('FeedAPI', 'create', $params, new DIContainer());
}
);
+$this->create('news_api_feeds_update', '/api/v1-2/feeds/update')->get()->action(
+ function($params) {
+ return App::main('FeedAPI', 'update', $params, new DIContainer());
+ }
+);
+
$this->create('news_api_feeds_delete', '/api/v1-2/feeds/{feedId}')->delete()->action(
function($params) {
return App::main('FeedAPI', 'delete', $params, new DIContainer());
diff --git a/businesslayer/feedbusinesslayer.php b/businesslayer/feedbusinesslayer.php
index d3b32d1c6..5ee74d2e0 100644
--- a/businesslayer/feedbusinesslayer.php
+++ b/businesslayer/feedbusinesslayer.php
@@ -70,6 +70,15 @@ class FeedBusinessLayer extends BusinessLayer {
/**
+ * Finds all feeds from all users
+ * @return array of feeds
+ */
+ public function findAllFromAllUsers() {
+ return $this->mapper->findAll();
+ }
+
+
+ /**
* Creates a new feed
* @param string $feedUrl the url to the feed
* @param int $folderId the folder where it should be put into, 0 for root folder
diff --git a/external/feedapi.php b/external/feedapi.php
index cc9753eb5..fdb83e682 100644
--- a/external/feedapi.php
+++ b/external/feedapi.php
@@ -182,4 +182,47 @@ class FeedAPI extends Controller {
}
+ /**
+ * @IsAdminExemption
+ * @IsSubAdminExemption
+ * @CSRFExemption
+ * @Ajax
+ * @API
+ */
+ public function getAllFromAllUsers() {
+ $feeds = $this->feedBusinessLayer->findAllFromAllUsers();
+ $result = array('feeds' => array());
+
+ foreach ($feeds as $feed) {
+ array_push($result['feeds'], array(
+ 'id' => $feed->getId(),
+ 'userId' => $feed->getUserId()
+ ));
+ }
+
+ return new JSONResponse($result);
+ }
+
+
+ /**
+ * @IsAdminExemption
+ * @IsSubAdminExemption
+ * @CSRFExemption
+ * @Ajax
+ * @API
+ */
+ public function update() {
+ $userId = $this->params('userId');
+ $feedId = $this->params('feedId');
+
+ try {
+ $this->feedBusinessLayer->update($feedId, $userId);
+ } catch(BusinessLayerException $ex) {
+ return new JSONResponse(array('message' => $ex->getMessage()),
+ Http::STATUS_NOT_FOUND);
+ }
+
+ }
+
+
}
diff --git a/tests/unit/businesslayer/FeedBusinessLayerTest.php b/tests/unit/businesslayer/FeedBusinessLayerTest.php
index 0e3532f16..c16a8c4ae 100644
--- a/tests/unit/businesslayer/FeedBusinessLayerTest.php
+++ b/tests/unit/businesslayer/FeedBusinessLayerTest.php
@@ -72,7 +72,7 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
$this->importParser = $this->getMockBuilder('\OCA\News\Utility\ImportParser')
->disableOriginalConstructor()
->getMock();
- $this->feedBusinessLayer = new FeedBusinessLayer($this->feedMapper,
+ $this->feedBusinessLayer = new FeedBusinessLayer($this->feedMapper,
$this->fetcher, $this->itemMapper, $this->api,
$timeFactory, $this->importParser, $this->autoPurgeMinimumInterval);
$this->user = 'jack';
@@ -159,7 +159,7 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
$this->itemMapper->expects($this->at(3))
->method('insert')
->with($this->equalTo($return[1][0]));
-
+
$feed = $this->feedBusinessLayer->create($url, $folderId, $this->user);
$this->assertEquals($feed->getFolderId(), $folderId);
@@ -210,7 +210,7 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
$this->equalTo($item1->getGuidHash()),
$this->equalTo($item1->getFeedId()),
$this->equalTo($this->user));
-
+
$feed = $this->feedBusinessLayer->create($url, $folderId, $this->user);
$this->assertEquals($feed->getFolderId(), $folderId);
@@ -288,7 +288,7 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
->will($this->returnValue($fetchReturn));
$this->itemMapper->expects($this->once())
->method('findByGuidHash')
- ->with($this->equalTo($item->getGuidHash()),
+ ->with($this->equalTo($item->getGuidHash()),
$this->equalTo($feed->getId()),
$this->equalTo($this->user))
->will($this->returnValue($item));
@@ -296,7 +296,7 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
->method('insert');
$this->itemMapper->expects($this->never())
->method('delete');
-
+
$this->feedMapper->expects($this->at(1))
->method('find')
->with($feed->getId(), $this->user)
@@ -417,7 +417,7 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
->will($this->throwException($ex));
$this->api->expects($this->any())
->method('log');
-
+
$this->feedMapper->expects($this->at(1))
->method('find')
->with($feed->getId(), $this->user)
@@ -433,7 +433,7 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
$feed = new Feed();
$feed->setId(3);
$feed->getUrl('test');
-
+
$ex = new DoesNotExistException('');
$this->feedMapper->expects($this->at(0))
@@ -446,7 +446,7 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
$return = $this->feedBusinessLayer->update($feed->getId(), $this->user);
}
-
+
public function testUpdateDoesNotFindUpdatedEntry() {
$feed = new Feed();
$feed->setId(3);
@@ -476,11 +476,11 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
->will($this->returnValue($fetchReturn));
$this->itemMapper->expects($this->once())
->method('findByGuidHash')
- ->with($this->equalTo($item->getGuidHash()),
+ ->with($this->equalTo($item->getGuidHash()),
$this->equalTo($feed->getId()),
$this->equalTo($this->user))
->will($this->returnValue($item2));;
-
+
$this->feedMapper->expects($this->at(1))
->method('find')
->with($this->equalTo($feed->getId()),
@@ -502,7 +502,7 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
$this->feedMapper->expects($this->once())
->method('find')
- ->with($this->equalTo($feedId),
+ ->with($this->equalTo($feedId),
$this->equalTo($this->user))
->will($this->returnValue($feed));
$this->fetcher->expects($this->never())
@@ -711,4 +711,17 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
$this->feedBusinessLayer->purgeDeleted($this->user, false);
}
+
+
+ public function testfindAllFromAllUsers() {
+ $expected = 'hi';
+ $this->feedMapper->expects($this->once())
+ ->method('findAll')
+ ->will($this->returnValue($expected));
+ $result = $this->feedBusinessLayer->findAllFromAllUsers();
+ $this->assertEquals($expected, $result);
+ }
+
+
}
+
diff --git a/tests/unit/external/FeedAPITest.php b/tests/unit/external/FeedAPITest.php
index a42a1c8c9..6b133610e 100644
--- a/tests/unit/external/FeedAPITest.php
+++ b/tests/unit/external/FeedAPITest.php
@@ -115,6 +115,15 @@ class FeedAPITest extends ControllerTestUtility {
}
+ public function testGetAllFromUsersAnnotations(){
+ $this->assertDefaultAnnotations('getAllFromAllUsers');
+ }
+
+
+ public function testUpdateAnnotations(){
+ $this->assertDefaultAnnotations('update');
+ }
+
public function testGetAll() {
$feeds = array(
new Feed()
@@ -439,4 +448,57 @@ class FeedAPITest extends ControllerTestUtility {
$this->assertEquals($this->msg, $data['message']);
$this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
}
+
+
+ public function testGetAllFromAllUsers(){
+ $feed = new Feed();
+ $feed->setUrl(3);
+ $feed->setId(1);
+ $feed->setUserId('john');
+ $feeds = array($feed);
+ $this->feedBusinessLayer->expects($this->once())
+ ->method('findAllFromAllUsers')
+ ->will($this->returnValue($feeds));
+ $response = $this->feedAPI->getAllFromAllUsers();
+ $this->assertTrue($response instanceof JSONResponse);
+ $this->assertEquals('{"feeds":[{"id":1,"userId":"john"}]}', $response->render());
+ }
+
+
+ public function testUpdate() {
+ $feedId = 3;
+ $userId = 'hi';
+ $request = new Request(array('params' => array(
+ 'feedId' => $feedId,
+ 'userId' => $userId
+ )));
+ $this->feedAPI = new FeedAPI(
+ $this->api,
+ $request,
+ $this->folderBusinessLayer,
+ $this->feedBusinessLayer,
+ $this->itemBusinessLayer
+ );
+ $this->feedBusinessLayer->expects($this->once())
+ ->method('update')
+ ->with($this->equalTo($feedId), $this->equalTo($userId));
+
+ $this->feedAPI->update();
+ }
+
+
+ public function testUpdateNotFound() {
+ $this->feedBusinessLayer->expects($this->once())
+ ->method('update')
+ ->will($this->throwException(new BusinessLayerException($this->msg)));
+
+ $response = $this->feedAPI->update();
+
+ $data = $response->getData();
+ $this->assertEquals($this->msg, $data['message']);
+ $this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
+
+ }
+
+
}