X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FController%2FWallabagRestController.php;h=fc13b1a8d867c961f84d7b6213cef0b561eec8ea;hb=42a9064620eb73eaa42928a22eeec86299d4a883;hp=a6c0db37a672a7683b370079566d832ccc984904;hpb=843dbe5195d157d4c3094aed5f63d960dd789060;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php index a6c0db37..fc13b1a8 100644 --- a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php @@ -3,16 +3,15 @@ namespace Wallabag\CoreBundle\Controller; use Nelmio\ApiDocBundle\Annotation\ApiDoc; -use FOS\RestBundle\Controller\Annotations\View; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Wallabag\CoreBundle\Entity\Entries; use Wallabag\CoreBundle\Entity\Tags; use Wallabag\CoreBundle\Service\Extractor; class WallabagRestController extends Controller { - /** * Retrieve all entries. It could be filtered by many options. * @@ -32,6 +31,8 @@ class WallabagRestController extends Controller */ public function getEntriesAction(Request $request) { + // TODO isArchived, isStarred et isDeleted ne doivent pas avoir de valeur par défaut + // TODO Si on ne passe rien, on ne filtre pas sur le statut. $isArchived = $request->query->get('archive', 0); $isStarred = $request->query->get('star', 0); $isDeleted = $request->query->get('delete', 0); @@ -44,14 +45,13 @@ class WallabagRestController extends Controller $entries = $this ->getDoctrine() ->getRepository('WallabagCoreBundle:Entries') - ->findEntries(1, (int)$isArchived, (int)$isStarred, (int)$isDeleted, $sort, $order); + ->findEntries(1, (int) $isArchived, (int) $isStarred, (int) $isDeleted, $sort, $order); - if(!is_array($entries)) { + if (!is_array($entries)) { throw $this->createNotFoundException(); } return $entries; - } /** @@ -82,17 +82,18 @@ class WallabagRestController extends Controller */ public function postEntriesAction(Request $request) { - //TODO la récup ne marche + //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); - $content = Extractor::extract($request->request->get('url')); - + $entry->setUrl($url); $entry->setTitle($content->getTitle()); $entry->setContent($content->getBody()); - $em = $this->getDoctrine()->getManager(); $em->persist($entry); $em->flush(); @@ -118,7 +119,6 @@ class WallabagRestController extends Controller */ public function patchEntriesAction(Entries $entry) { - } /** @@ -132,9 +132,17 @@ class WallabagRestController extends Controller */ public function deleteEntriesAction(Entries $entry) { + if ($entry->isDeleted()) { + throw new NotFoundHttpException('This entry is already deleted'); + } - } + $em = $this->getDoctrine()->getManager(); + $entry->setDeleted(1); + $em->persist($entry); + $em->flush(); + return $entry; + } /** * Retrieve all tags for an entry @@ -145,8 +153,8 @@ class WallabagRestController extends Controller * } * ) */ - public function getEntriesTagsAction(Entries $entry) { - + public function getEntriesTagsAction(Entries $entry) + { } /** @@ -161,8 +169,8 @@ class WallabagRestController extends Controller * } * ) */ - public function postEntriesTagsAction(Entries $entry) { - + public function postEntriesTagsAction(Entries $entry) + { } /** @@ -177,7 +185,6 @@ class WallabagRestController extends Controller */ public function deleteEntriesTagsAction(Entries $entry, Tags $tag) { - } /** @@ -186,8 +193,8 @@ class WallabagRestController extends Controller * @ApiDoc( * ) */ - public function getTagsAction() { - + public function getTagsAction() + { } /** @@ -199,8 +206,8 @@ class WallabagRestController extends Controller * } * ) */ - public function getTagAction(Tags $tag) { - + public function getTagAction(Tags $tag) + { } /** @@ -214,6 +221,5 @@ class WallabagRestController extends Controller */ public function deleteTagAction(Tags $tag) { - } -} \ No newline at end of file +}