]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Controller/EntryController.php
WIP
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Controller / EntryController.php
index fafa49f1b0bb69a156db8318a6ab3e9a9c2bba02..ba3db806384e967bb1003ac6dc905e90c12d0e35 100644 (file)
@@ -6,7 +6,9 @@ use Pagerfanta\Adapter\DoctrineORMAdapter;
 use Pagerfanta\Exception\OutOfRangeCurrentPageException;
 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
+use Symfony\Component\HttpFoundation\JsonResponse;
 use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
 use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
 use Wallabag\CoreBundle\Entity\Entry;
 use Wallabag\CoreBundle\Form\Type\EntryFilterType;
@@ -604,4 +606,50 @@ class EntryController extends Controller
     {
         return $this->showEntries('untagged', $request, $page);
     }
+
+    /**
+     * Get the progress of an entry.
+     *
+     * @param Entry $entry
+     *
+     * @Route("/progress/{entry}", name="get_progress")
+     *
+     * @return JsonResponse
+     */
+    public function getEntriesProgressAction(Entry $entry)
+    {
+        $this->checkUserAction($entry);
+
+        $json = $this->get('serializer')->serialize($entry->getProgress(), 'json');
+
+        return (new JsonResponse())->setJson($json);
+    }
+
+    /**
+     * Set the progress of an entry.
+     *
+     * @param Entry $entry
+     * @param int   $progress
+     *
+     * @Route("/set-progress/{entry}", name="set_progress")
+     *
+     * @return JsonResponse
+     */
+    public function setEntriesProgressAction(Entry $entry, $progress)
+    {
+        $this->checkUserAction($entry);
+        $response = new JsonResponse();
+
+        if (is_null($progress)) {
+            $response->setStatusCode(Response::HTTP_BAD_REQUEST);
+        } else {
+            $progress = (int) $progress;
+            if ($progress >= 0 && $progress <= 100) {
+                $entry->setProgress($progress);
+                $response->setStatusCode(Response::HTTP_OK);
+            }
+        }
+
+        return $response;
+    }
 }