diff options
Diffstat (limited to 'src/Wallabag/ApiBundle')
-rw-r--r-- | src/Wallabag/ApiBundle/Controller/WallabagRestController.php | 77 | ||||
-rw-r--r-- | src/Wallabag/ApiBundle/Entity/Client.php | 31 |
2 files changed, 107 insertions, 1 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index af24e498..869fdc56 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php | |||
@@ -34,6 +34,7 @@ class WallabagRestController extends FOSRestController | |||
34 | * {"name"="page", "dataType"="integer", "required"=false, "format"="default '1'", "description"="what page you want."}, | 34 | * {"name"="page", "dataType"="integer", "required"=false, "format"="default '1'", "description"="what page you want."}, |
35 | * {"name"="perPage", "dataType"="integer", "required"=false, "format"="default'30'", "description"="results per page."}, | 35 | * {"name"="perPage", "dataType"="integer", "required"=false, "format"="default'30'", "description"="results per page."}, |
36 | * {"name"="tags", "dataType"="string", "required"=false, "format"="api,rest", "description"="a list of tags url encoded. Will returns entries that matches ALL tags."}, | 36 | * {"name"="tags", "dataType"="string", "required"=false, "format"="api,rest", "description"="a list of tags url encoded. Will returns entries that matches ALL tags."}, |
37 | * {"name"="since", "dataType"="integer", "required"=false, "format"="default '0'", "description"="The timestamp since when you want entries updated."}, | ||
37 | * } | 38 | * } |
38 | * ) | 39 | * ) |
39 | * | 40 | * |
@@ -49,10 +50,12 @@ class WallabagRestController extends FOSRestController | |||
49 | $order = $request->query->get('order', 'desc'); | 50 | $order = $request->query->get('order', 'desc'); |
50 | $page = (int) $request->query->get('page', 1); | 51 | $page = (int) $request->query->get('page', 1); |
51 | $perPage = (int) $request->query->get('perPage', 30); | 52 | $perPage = (int) $request->query->get('perPage', 30); |
53 | $since = $request->query->get('since', 0); | ||
54 | $tags = $request->query->get('tags', ''); | ||
52 | 55 | ||
53 | $pager = $this->getDoctrine() | 56 | $pager = $this->getDoctrine() |
54 | ->getRepository('WallabagCoreBundle:Entry') | 57 | ->getRepository('WallabagCoreBundle:Entry') |
55 | ->findEntries($this->getUser()->getId(), $isArchived, $isStarred, $sort, $order); | 58 | ->findEntries($this->getUser()->getId(), $isArchived, $isStarred, $sort, $order, $since, $tags); |
56 | 59 | ||
57 | $pager->setCurrentPage($page); | 60 | $pager->setCurrentPage($page); |
58 | $pager->setMaxPerPage($perPage); | 61 | $pager->setMaxPerPage($perPage); |
@@ -331,6 +334,77 @@ class WallabagRestController extends FOSRestController | |||
331 | * | 334 | * |
332 | * @ApiDoc( | 335 | * @ApiDoc( |
333 | * requirements={ | 336 | * requirements={ |
337 | * {"name"="tag", "dataType"="string", "required"=true, "requirement"="\w+", "description"="Tag as a string"} | ||
338 | * } | ||
339 | * ) | ||
340 | * | ||
341 | * @return Response | ||
342 | */ | ||
343 | public function deleteTagLabelAction(Request $request) | ||
344 | { | ||
345 | $this->validateAuthentication(); | ||
346 | $label = $request->request->get('tag', ''); | ||
347 | |||
348 | $tag = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findOneByLabel($label); | ||
349 | |||
350 | if (empty($tag)) { | ||
351 | throw $this->createNotFoundException('Tag not found'); | ||
352 | } | ||
353 | |||
354 | $this->getDoctrine() | ||
355 | ->getRepository('WallabagCoreBundle:Entry') | ||
356 | ->removeTag($this->getUser()->getId(), $tag); | ||
357 | |||
358 | $json = $this->get('serializer')->serialize($tag, 'json'); | ||
359 | |||
360 | return $this->renderJsonResponse($json); | ||
361 | } | ||
362 | |||
363 | /** | ||
364 | * Permanently remove some tags from **every** entry. | ||
365 | * | ||
366 | * @ApiDoc( | ||
367 | * requirements={ | ||
368 | * {"name"="tags", "dataType"="string", "required"=true, "format"="tag1,tag2", "description"="Tags as strings (comma splitted)"} | ||
369 | * } | ||
370 | * ) | ||
371 | * | ||
372 | * @return Response | ||
373 | */ | ||
374 | public function deleteTagsLabelAction(Request $request) | ||
375 | { | ||
376 | $this->validateAuthentication(); | ||
377 | |||
378 | $tagsLabels = $request->request->get('tags', ''); | ||
379 | |||
380 | $tags = []; | ||
381 | |||
382 | foreach (explode(',', $tagsLabels) as $tagLabel) { | ||
383 | $tagEntity = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findOneByLabel($tagLabel); | ||
384 | |||
385 | if (!empty($tagEntity)) { | ||
386 | $tags[] = $tagEntity; | ||
387 | } | ||
388 | } | ||
389 | |||
390 | if (empty($tags)) { | ||
391 | throw $this->createNotFoundException('Tags not found'); | ||
392 | } | ||
393 | |||
394 | $this->getDoctrine() | ||
395 | ->getRepository('WallabagCoreBundle:Entry') | ||
396 | ->removeTags($this->getUser()->getId(), $tags); | ||
397 | |||
398 | $json = $this->get('serializer')->serialize($tags, 'json'); | ||
399 | |||
400 | return $this->renderJsonResponse($json); | ||
401 | } | ||
402 | |||
403 | /** | ||
404 | * Permanently remove one tag from **every** entry. | ||
405 | * | ||
406 | * @ApiDoc( | ||
407 | * requirements={ | ||
334 | * {"name"="tag", "dataType"="integer", "requirement"="\w+", "description"="The tag"} | 408 | * {"name"="tag", "dataType"="integer", "requirement"="\w+", "description"="The tag"} |
335 | * } | 409 | * } |
336 | * ) | 410 | * ) |
@@ -349,6 +423,7 @@ class WallabagRestController extends FOSRestController | |||
349 | 423 | ||
350 | return $this->renderJsonResponse($json); | 424 | return $this->renderJsonResponse($json); |
351 | } | 425 | } |
426 | |||
352 | /** | 427 | /** |
353 | * Retrieve version number. | 428 | * Retrieve version number. |
354 | * | 429 | * |
diff --git a/src/Wallabag/ApiBundle/Entity/Client.php b/src/Wallabag/ApiBundle/Entity/Client.php index c04ed0f6..3e2f491c 100644 --- a/src/Wallabag/ApiBundle/Entity/Client.php +++ b/src/Wallabag/ApiBundle/Entity/Client.php | |||
@@ -18,8 +18,39 @@ class Client extends BaseClient | |||
18 | */ | 18 | */ |
19 | protected $id; | 19 | protected $id; |
20 | 20 | ||
21 | /** | ||
22 | * @var string | ||
23 | * | ||
24 | * @ORM\Column(name="name", type="text", nullable=true) | ||
25 | */ | ||
26 | protected $name; | ||
27 | |||
21 | public function __construct() | 28 | public function __construct() |
22 | { | 29 | { |
23 | parent::__construct(); | 30 | parent::__construct(); |
24 | } | 31 | } |
32 | |||
33 | /** | ||
34 | * Get name. | ||
35 | * | ||
36 | * @return string | ||
37 | */ | ||
38 | public function getName() | ||
39 | { | ||
40 | return $this->name; | ||
41 | } | ||
42 | |||
43 | /** | ||
44 | * Set name. | ||
45 | * | ||
46 | * @param string $name | ||
47 | * | ||
48 | * @return Client | ||
49 | */ | ||
50 | public function setName($name) | ||
51 | { | ||
52 | $this->name = $name; | ||
53 | |||
54 | return $this; | ||
55 | } | ||
25 | } | 56 | } |