]> 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 96d2529a43c7251c0c1d0dd0ba04b6644ef4a740..cadd7e755cabf4a815fbe6f03127e37dae84543d 100644 (file)
@@ -5,11 +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\Tags;
-use Wallabag\CoreBundle\Entity\User;
+use Wallabag\CoreBundle\Entity\Tag;
 use Wallabag\CoreBundle\Service\Extractor;
+use Hateoas\HateoasBuilder;
 
 class WallabagRestController extends Controller
 {
@@ -21,7 +22,7 @@ class WallabagRestController extends Controller
      *          {"name"="username", "dataType"="string", "required"=true, "description"="username"}
      *       }
      * )
-     * @return string
+     * @return array
      */
     public function getSaltAction($username)
     {
@@ -34,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.
@@ -69,10 +70,13 @@ class WallabagRestController extends Controller
             ->getRepository('WallabagCoreBundle:Entry')
             ->findEntries($this->getUser()->getId(), $isArchived, $isStarred, $isDeleted, $sort, $order);
 
-        if (!is_array($entries)) {
+        if (!($entries)) {
             throw $this->createNotFoundException();
         }
 
+        $hateoas = HateoasBuilder::create()->build();
+        $json = $hateoas->serialize($entries, 'json');
+
         return $entries;
     }
 
@@ -88,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'));
     }
 
     /**
@@ -109,7 +116,7 @@ class WallabagRestController extends Controller
         $url = $request->request->get('url');
 
         $content = Extractor::extract($url);
-        $entry = new Entry($this->getUser()->getId());
+        $entry = new Entry($this->getUser());
         $entry->setUrl($url);
         $entry->setTitle($request->request->get('title') ?: $content->getTitle());
         $entry->setContent($content->getBody());
@@ -229,7 +236,7 @@ class WallabagRestController extends Controller
      *      }
      * )
      */
-    public function deleteEntriesTagsAction(Entry $entry, Tags $tag)
+    public function deleteEntriesTagsAction(Entry $entry, Tag $tag)
     {
     }
 
@@ -252,7 +259,7 @@ class WallabagRestController extends Controller
      *       }
      * )
      */
-    public function getTagAction(Tags $tag)
+    public function getTagAction(Tag $tag)
     {
     }
 
@@ -265,7 +272,7 @@ class WallabagRestController extends Controller
      *      }
      * )
      */
-    public function deleteTagAction(Tags $tag)
+    public function deleteTagAction(Tag $tag)
     {
     }
 }