]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Controller/WallabagRestController.php
first draft of hypermedia implementation
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Controller / WallabagRestController.php
index 27d11da5ec158c931f614186d51777a75f73fa3b..cadd7e755cabf4a815fbe6f03127e37dae84543d 100644 (file)
@@ -5,10 +5,12 @@ namespace Wallabag\CoreBundle\Controller;
 use Nelmio\ApiDocBundle\Annotation\ApiDoc;
 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
 use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
 use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
 use Wallabag\CoreBundle\Entity\Entry;
 use Wallabag\CoreBundle\Entity\Tag;
 use Wallabag\CoreBundle\Service\Extractor;
+use Hateoas\HateoasBuilder;
 
 class WallabagRestController extends Controller
 {
@@ -20,7 +22,7 @@ class WallabagRestController extends Controller
      *          {"name"="username", "dataType"="string", "required"=true, "description"="username"}
      *       }
      * )
-     * @return string
+     * @return array
      */
     public function getSaltAction($username)
     {
@@ -33,7 +35,7 @@ class WallabagRestController extends Controller
             throw $this->createNotFoundException();
         }
 
-        return $user->getSalt();
+        return array($user->getSalt() ?: null);
     }
     /**
      * Retrieve all entries. It could be filtered by many options.
@@ -72,6 +74,9 @@ class WallabagRestController extends Controller
             throw $this->createNotFoundException();
         }
 
+        $hateoas = HateoasBuilder::create()->build();
+        $json = $hateoas->serialize($entries, 'json');
+
         return $entries;
     }
 
@@ -87,7 +92,10 @@ class WallabagRestController extends Controller
      */
     public function getEntryAction(Entry $entry)
     {
-        return $entry;
+        $hateoas = HateoasBuilder::create()->build();
+        $json = $hateoas->serialize($entry, 'json');
+
+        return new Response($json, 200, array('application/json'));
     }
 
     /**