aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ApiBundle
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2017-06-10 15:31:57 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2017-06-10 15:31:57 +0200
commit1112e54772c9308ee3d7417869b5b8ef9b2b9812 (patch)
tree1d4341b1a4889baf5c934dc2064a4f4e982f9947 /src/Wallabag/ApiBundle
parente8911f7c09fa9d8009d7c7ee9fb0c181d2ffbc31 (diff)
downloadwallabag-1112e54772c9308ee3d7417869b5b8ef9b2b9812.tar.gz
wallabag-1112e54772c9308ee3d7417869b5b8ef9b2b9812.tar.zst
wallabag-1112e54772c9308ee3d7417869b5b8ef9b2b9812.zip
Add public filter/field in the API
Listing entries can now be filtered by “public”. Creating or patching an entry can now set is to public or remove the public. Entry response now include “is_public” boolean field
Diffstat (limited to 'src/Wallabag/ApiBundle')
-rw-r--r--src/Wallabag/ApiBundle/Controller/EntryRestController.php27
1 files changed, 24 insertions, 3 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
index 09b73ccb..ae9a93aa 100644
--- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
@@ -77,6 +77,7 @@ class EntryRestController extends WallabagRestController
77 * {"name"="perPage", "dataType"="integer", "required"=false, "format"="default'30'", "description"="results per page."}, 77 * {"name"="perPage", "dataType"="integer", "required"=false, "format"="default'30'", "description"="results per page."},
78 * {"name"="tags", "dataType"="string", "required"=false, "format"="api,rest", "description"="a list of tags url encoded. Will returns entries that matches ALL tags."}, 78 * {"name"="tags", "dataType"="string", "required"=false, "format"="api,rest", "description"="a list of tags url encoded. Will returns entries that matches ALL tags."},
79 * {"name"="since", "dataType"="integer", "required"=false, "format"="default '0'", "description"="The timestamp since when you want entries updated."}, 79 * {"name"="since", "dataType"="integer", "required"=false, "format"="default '0'", "description"="The timestamp since when you want entries updated."},
80 * {"name"="public", "dataType"="integer", "required"=false, "format"="1 or 0, all entries by default", "description"="filter by entries with a public link"},
80 * } 81 * }
81 * ) 82 * )
82 * 83 *
@@ -88,6 +89,7 @@ class EntryRestController extends WallabagRestController
88 89
89 $isArchived = (null === $request->query->get('archive')) ? null : (bool) $request->query->get('archive'); 90 $isArchived = (null === $request->query->get('archive')) ? null : (bool) $request->query->get('archive');
90 $isStarred = (null === $request->query->get('starred')) ? null : (bool) $request->query->get('starred'); 91 $isStarred = (null === $request->query->get('starred')) ? null : (bool) $request->query->get('starred');
92 $isPublic = (null === $request->query->get('public')) ? null : (bool) $request->query->get('public');
91 $sort = $request->query->get('sort', 'created'); 93 $sort = $request->query->get('sort', 'created');
92 $order = $request->query->get('order', 'desc'); 94 $order = $request->query->get('order', 'desc');
93 $page = (int) $request->query->get('page', 1); 95 $page = (int) $request->query->get('page', 1);
@@ -96,9 +98,16 @@ class EntryRestController extends WallabagRestController
96 $since = $request->query->get('since', 0); 98 $since = $request->query->get('since', 0);
97 99
98 /** @var \Pagerfanta\Pagerfanta $pager */ 100 /** @var \Pagerfanta\Pagerfanta $pager */
99 $pager = $this->getDoctrine() 101 $pager = $this->get('wallabag_core.entry_repository')->findEntries(
100 ->getRepository('WallabagCoreBundle:Entry') 102 $this->getUser()->getId(),
101 ->findEntries($this->getUser()->getId(), $isArchived, $isStarred, $sort, $order, $since, $tags); 103 $isArchived,
104 $isStarred,
105 $isPublic,
106 $sort,
107 $order,
108 $since,
109 $tags
110 );
102 111
103 $pager->setMaxPerPage($perPage); 112 $pager->setMaxPerPage($perPage);
104 $pager->setCurrentPage($page); 113 $pager->setCurrentPage($page);
@@ -111,6 +120,7 @@ class EntryRestController extends WallabagRestController
111 [ 120 [
112 'archive' => $isArchived, 121 'archive' => $isArchived,
113 'starred' => $isStarred, 122 'starred' => $isStarred,
123 'public' => $isPublic,
114 'sort' => $sort, 124 'sort' => $sort,
115 'order' => $order, 125 'order' => $order,
116 'page' => $page, 126 'page' => $page,
@@ -289,6 +299,7 @@ class EntryRestController extends WallabagRestController
289 * {"name"="preview_picture", "dataType"="string", "required"=false, "description"="Preview picture of the entry"}, 299 * {"name"="preview_picture", "dataType"="string", "required"=false, "description"="Preview picture of the entry"},
290 * {"name"="published_at", "dataType"="datetime|integer", "format"="YYYY-MM-DDTHH:II:SS+TZ or a timestamp", "required"=false, "description"="Published date of the entry"}, 300 * {"name"="published_at", "dataType"="datetime|integer", "format"="YYYY-MM-DDTHH:II:SS+TZ or a timestamp", "required"=false, "description"="Published date of the entry"},
291 * {"name"="authors", "dataType"="string", "format"="Name Firstname,author2,author3", "required"=false, "description"="Authors of the entry"}, 301 * {"name"="authors", "dataType"="string", "format"="Name Firstname,author2,author3", "required"=false, "description"="Authors of the entry"},
302 * {"name"="public", "dataType"="integer", "required"=false, "format"="1 or 0", "description"="will generate a public link for the entry"},
292 * } 303 * }
293 * ) 304 * )
294 * 305 *
@@ -332,6 +343,7 @@ class EntryRestController extends WallabagRestController
332 * {"name"="preview_picture", "dataType"="string", "required"=false, "description"="Preview picture of the entry"}, 343 * {"name"="preview_picture", "dataType"="string", "required"=false, "description"="Preview picture of the entry"},
333 * {"name"="published_at", "dataType"="datetime|integer", "format"="YYYY-MM-DDTHH:II:SS+TZ or a timestamp", "required"=false, "description"="Published date of the entry"}, 344 * {"name"="published_at", "dataType"="datetime|integer", "format"="YYYY-MM-DDTHH:II:SS+TZ or a timestamp", "required"=false, "description"="Published date of the entry"},
334 * {"name"="authors", "dataType"="string", "format"="Name Firstname,author2,author3", "required"=false, "description"="Authors of the entry"}, 345 * {"name"="authors", "dataType"="string", "format"="Name Firstname,author2,author3", "required"=false, "description"="Authors of the entry"},
346 * {"name"="public", "dataType"="integer", "required"=false, "format"="1 or 0", "description"="will generate a public link for the entry"},
335 * } 347 * }
336 * ) 348 * )
337 * 349 *
@@ -623,6 +635,7 @@ class EntryRestController extends WallabagRestController
623 $tags = $request->request->get('tags', []); 635 $tags = $request->request->get('tags', []);
624 $isArchived = $request->request->get('archive'); 636 $isArchived = $request->request->get('archive');
625 $isStarred = $request->request->get('starred'); 637 $isStarred = $request->request->get('starred');
638 $isPublic = $request->request->get('public');
626 $content = $request->request->get('content'); 639 $content = $request->request->get('content');
627 $language = $request->request->get('language'); 640 $language = $request->request->get('language');
628 $picture = $request->request->get('preview_picture'); 641 $picture = $request->request->get('preview_picture');
@@ -666,6 +679,14 @@ class EntryRestController extends WallabagRestController
666 $this->get('wallabag_core.tags_assigner')->assignTagsToEntry($entry, $tags); 679 $this->get('wallabag_core.tags_assigner')->assignTagsToEntry($entry, $tags);
667 } 680 }
668 681
682 if (!is_null($isPublic)) {
683 $entry->cleanUid();
684
685 if (true === (bool) $isPublic && null === $entry->getUid()) {
686 $entry->generateUid();
687 }
688 }
689
669 $em = $this->getDoctrine()->getManager(); 690 $em = $this->getDoctrine()->getManager();
670 $em->persist($entry); 691 $em->persist($entry);
671 $em->flush(); 692 $em->flush();