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.
*
*/
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);
$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;
-
}
/**
*/
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();
*/
public function patchEntriesAction(Entries $entry)
{
-
}
/**
*/
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
* }
* )
*/
- public function getEntriesTagsAction(Entries $entry) {
-
+ public function getEntriesTagsAction(Entries $entry)
+ {
}
/**
* }
* )
*/
- public function postEntriesTagsAction(Entries $entry) {
-
+ public function postEntriesTagsAction(Entries $entry)
+ {
}
/**
*/
public function deleteEntriesTagsAction(Entries $entry, Tags $tag)
{
-
}
/**
* @ApiDoc(
* )
*/
- public function getTagsAction() {
-
+ public function getTagsAction()
+ {
}
/**
* }
* )
*/
- public function getTagAction(Tags $tag) {
-
+ public function getTagAction(Tags $tag)
+ {
}
/**
*/
public function deleteTagAction(Tags $tag)
{
-
}
-}
\ No newline at end of file
+}