From c179198a0408f6d3edf27d5e3f8ab006da32bf0c Mon Sep 17 00:00:00 2001 From: Davide Saurino Date: Wed, 12 Mar 2014 23:57:55 +0100 Subject: Add feed renaming to the API (FIX #455) --- api/feedapi.php | 22 ++++++++++++++++++++++ appinfo/routes.php | 6 ++++++ 2 files changed, 28 insertions(+) diff --git a/api/feedapi.php b/api/feedapi.php index 4ad9b3307..0880434d8 100644 --- a/api/feedapi.php +++ b/api/feedapi.php @@ -182,6 +182,28 @@ class FeedAPI extends Controller { } + /** + * @IsAdminExemption + * @IsSubAdminExemption + * @CSRFExemption + * @Ajax + * @API + */ + public function rename() { + $userId = $this->api->getUserId(); + $feedId = (int) $this->params('feedId'); + $feedTitle = $this->params('feedTitle'); + + try { + $this->feedBusinessLayer->rename($feedId, $feedTitle, $userId); + return new JSONResponse(); + } catch(BusinessLayerException $ex) { + return new JSONResponse(array('message' => $ex->getMessage()), + Http::STATUS_NOT_FOUND); + } + } + + /** * @CSRFExemption * @Ajax diff --git a/appinfo/routes.php b/appinfo/routes.php index cc697d0a9..fc60a717c 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -354,6 +354,12 @@ $this->create('news_api_feeds_move', '/api/v1-2/feeds/{feedId}/move')->put()->ac } ); +$this->create('news_api_feeds_rename', '/api/v1-2/feeds/{feedId}/rename')->put()->action( + function($params) { + return App::main('FeedAPI', 'rename', $params, new DIContainer()); + } +); + $this->create('news_api_feeds_read', '/api/v1-2/feeds/{feedId}/read')->put()->action( function($params) { return App::main('FeedAPI', 'read', $params, new DIContainer()); -- cgit v1.2.3 From d67b77ac255974d2298bd858b636767e490a4e41 Mon Sep 17 00:00:00 2001 From: Davide Saurino Date: Thu, 13 Mar 2014 00:00:03 +0100 Subject: Test for renaming feed API feature --- tests/unit/api/FeedAPITest.php | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/unit/api/FeedAPITest.php b/tests/unit/api/FeedAPITest.php index e3b5b5587..6b2187657 100644 --- a/tests/unit/api/FeedAPITest.php +++ b/tests/unit/api/FeedAPITest.php @@ -437,6 +437,43 @@ class FeedAPITest extends ControllerTestUtility { } + public function testRename() { + $feedId = 3; + $feedTitle = 'test'; + + $request = new Request(array( + 'urlParams' => array( + 'feedId' => $feedId + ), + 'params' => array( + 'feedTitle' => $feedTitle + ) + )); + $this->feedAPI = new FeedAPI( + $this->api, + $request, + $this->folderBusinessLayer, + $this->feedBusinessLayer, + $this->itemBusinessLayer + ); + + $this->api->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($this->user)); + $this->feedBusinessLayer->expects($this->once()) + ->method('rename') + ->with( + $this->equalTo($feedId), + $this->equalTo($feedTitle), + $this->equalTo($this->user)); + + $response = $this->feedAPI->rename(); + + $this->assertEmpty($response->getData()); + $this->assertEquals(Http::STATUS_OK, $response->getStatus()); + } + + public function testMoveDoesNotExist() { $this->api->expects($this->once()) ->method('getUserId') -- cgit v1.2.3