From acc2df1251a1c1b9ec5ede13bdf46d516dc64b0d Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Wed, 14 May 2014 02:16:31 +0200 Subject: use more flexible serializer that ignores nulls, non entity values and responses --- controller/feedapicontroller.php | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) (limited to 'controller/feedapicontroller.php') diff --git a/controller/feedapicontroller.php b/controller/feedapicontroller.php index 7d68e5f56..a6f52f9ea 100644 --- a/controller/feedapicontroller.php +++ b/controller/feedapicontroller.php @@ -51,6 +51,7 @@ class FeedApiController extends ApiController { $this->userId = $userId; $this->logger = $logger; $this->loggerParams = $loggerParams; + $this->registerSerializer(new EntityApiSerializer('feeds')); } @@ -63,22 +64,15 @@ class FeedApiController extends ApiController { $result = array( 'feeds' => array(), - 'starredCount' => $this->itemBusinessLayer->starredCount($this->userId) + 'starredCount' => $this->itemBusinessLayer->starredCount($this->userId), + 'feeds' => $this->feedBusinessLayer->findAll($this->userId) ); - $feeds = $this->feedBusinessLayer->findAll($this->userId); - - foreach ($feeds as $feed) { - array_push($result['feeds'], $feed->toAPI()); - } - - // check case when there are no items + try { - $result['newestItemId'] = $this->itemBusinessLayer - ->getNewestItemId($this->userId); - - // An exception occurs if there is a newest item. If there is none, - // simply ignore it and do not add the newestItemId + $result['newestItemId'] = $this->itemBusinessLayer->getNewestItemId($this->userId); + + // in case there are no items, ignore } catch(BusinessLayerException $ex) {} return $result; @@ -97,18 +91,15 @@ class FeedApiController extends ApiController { try { $this->feedBusinessLayer->purgeDeleted($this->userId, false); - $feed = $this->feedBusinessLayer->create($url, $folderId, - $this->userId); + $feed = $this->feedBusinessLayer->create($url, $folderId, $this->userId); $result = array( - 'feeds' => array($feed->toAPI()) + 'feeds' => array($feed) ); try { - $result['newestItemId'] = $this->itemBusinessLayer - ->getNewestItemId($this->userId); + $result['newestItemId'] = $this->itemBusinessLayer->getNewestItemId($this->userId); - // An exception occurs if there is a newest item. If there is none, - // simply ignore it and do not add the newestItemId + // in case there are no items, ignore } catch(BusinessLayerException $ex) {} return $result; @@ -193,10 +184,10 @@ class FeedApiController extends ApiController { $result = array('feeds' => array()); foreach ($feeds as $feed) { - array_push($result['feeds'], array( - 'id' => $feed->getId(), + $result['feeds'][] = array( + 'id' => $feed->getId(), 'userId' => $feed->getUserId() - )); + ); } return $result; -- cgit v1.2.3