X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FController%2FWallabagRestController.php;h=cadd7e755cabf4a815fbe6f03127e37dae84543d;hb=0f00688096645606c7806a619ca27e6f30ce820c;hp=fae633fa4b58725cbe7a027d33e958ca8ba9fe58;hpb=c0284f6182a7421d2352e9288205d70b81185a7d;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php index fae633fa..cadd7e75 100644 --- a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php @@ -5,13 +5,38 @@ 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\Entries; -use Wallabag\CoreBundle\Entity\Tags; +use Wallabag\CoreBundle\Entity\Entry; +use Wallabag\CoreBundle\Entity\Tag; use Wallabag\CoreBundle\Service\Extractor; +use Hateoas\HateoasBuilder; class WallabagRestController extends Controller { + /** + * Retrieve salt for a giver user. + * + * @ApiDoc( + * parameters={ + * {"name"="username", "dataType"="string", "required"=true, "description"="username"} + * } + * ) + * @return array + */ + public function getSaltAction($username) + { + $user = $this + ->getDoctrine() + ->getRepository('WallabagCoreBundle:User') + ->findOneByUsername($username); + + if (is_null($user)) { + throw $this->createNotFoundException(); + } + + return array($user->getSalt() ?: null); + } /** * Retrieve all entries. It could be filtered by many options. * @@ -27,7 +52,7 @@ class WallabagRestController extends Controller * {"name"="tags", "dataType"="string", "required"=false, "format"="api%2Crest", "description"="a list of tags url encoded. Will returns entries that matches ALL tags."}, * } * ) - * @return Entries + * @return Entry */ public function getEntriesAction(Request $request) { @@ -42,13 +67,16 @@ class WallabagRestController extends Controller $entries = $this ->getDoctrine() - ->getRepository('WallabagCoreBundle:Entries') - ->findEntries(1, $isArchived, $isStarred, $isDeleted, $sort, $order); + ->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; } @@ -60,11 +88,14 @@ class WallabagRestController extends Controller * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} * } * ) - * @return Entries + * @return Entry */ - public function getEntryAction(Entries $entry) + public function getEntryAction(Entry $entry) { - return $entry; + $hateoas = HateoasBuilder::create()->build(); + $json = $hateoas->serialize($entry, 'json'); + + return new Response($json, 200, array('application/json')); } /** @@ -77,20 +108,17 @@ class WallabagRestController extends Controller * {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."}, * } * ) + * @return Entry */ public function postEntriesAction(Request $request) { - //TODO la récup ne marche pas - //TODO gérer si on passe le titre //TODO gérer si on passe les tags - //TODO ne pas avoir du code comme ça qui doit se trouver dans le Repository $url = $request->request->get('url'); $content = Extractor::extract($url); - $entry = new Entries(); - $entry->setUserId(1); + $entry = new Entry($this->getUser()); $entry->setUrl($url); - $entry->setTitle($content->getTitle()); + $entry->setTitle($request->request->get('title') ?: $content->getTitle()); $entry->setContent($content->getBody()); $em = $this->getDoctrine()->getManager(); $em->persist($entry); @@ -114,8 +142,9 @@ class WallabagRestController extends Controller * {"name"="delete", "dataType"="boolean", "required"=false, "format"="true or false", "description"="flag as deleted. Default false. In case that you don't want to *really* remove it.."}, * } * ) + * @return Entry */ - public function patchEntriesAction(Entries $entry, Request $request) + public function patchEntriesAction(Entry $entry, Request $request) { $title = $request->request->get("title"); $tags = $request->request->get("tags", array()); @@ -128,7 +157,7 @@ class WallabagRestController extends Controller } if (!is_null($isArchived)) { - $entry->setRead($isArchived); + $entry->setArchived($isArchived); } if (!is_null($isDeleted)) { @@ -136,7 +165,7 @@ class WallabagRestController extends Controller } if (!is_null($isStarred)) { - $entry->setFav($isStarred); + $entry->setStarred($isStarred); } $em = $this->getDoctrine()->getManager(); @@ -153,8 +182,9 @@ class WallabagRestController extends Controller * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} * } * ) + * @return Entry */ - public function deleteEntriesAction(Entries $entry) + public function deleteEntriesAction(Entry $entry) { if ($entry->isDeleted()) { throw new NotFoundHttpException('This entry is already deleted'); @@ -176,7 +206,7 @@ class WallabagRestController extends Controller * } * ) */ - public function getEntriesTagsAction(Entries $entry) + public function getEntriesTagsAction(Entry $entry) { } @@ -192,7 +222,7 @@ class WallabagRestController extends Controller * } * ) */ - public function postEntriesTagsAction(Entries $entry) + public function postEntriesTagsAction(Entry $entry) { } @@ -206,7 +236,7 @@ class WallabagRestController extends Controller * } * ) */ - public function deleteEntriesTagsAction(Entries $entry, Tags $tag) + public function deleteEntriesTagsAction(Entry $entry, Tag $tag) { } @@ -229,7 +259,7 @@ class WallabagRestController extends Controller * } * ) */ - public function getTagAction(Tags $tag) + public function getTagAction(Tag $tag) { } @@ -242,7 +272,7 @@ class WallabagRestController extends Controller * } * ) */ - public function deleteTagAction(Tags $tag) + public function deleteTagAction(Tag $tag) { } }