diff options
author | Thomas Citharel <tcit@tcit.fr> | 2016-03-16 20:41:29 +0100 |
---|---|---|
committer | Thomas Citharel <tcit@tcit.fr> | 2016-03-16 22:22:12 +0100 |
commit | 189ef6342a3f9befec379c406821ed10730cacd2 (patch) | |
tree | 2def34d5dfb903889c457c85a686726fc6911ec1 /src/Wallabag | |
parent | 0d3043a29c4aba541d6a18c2d5cc7ebffc6ddc78 (diff) | |
download | wallabag-189ef6342a3f9befec379c406821ed10730cacd2.tar.gz wallabag-189ef6342a3f9befec379c406821ed10730cacd2.tar.zst wallabag-189ef6342a3f9befec379c406821ed10730cacd2.zip |
use integers for archived/starred status
Diffstat (limited to 'src/Wallabag')
3 files changed, 46 insertions, 22 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index 3265ba38..d0a35013 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php | |||
@@ -27,13 +27,13 @@ class WallabagRestController extends FOSRestController | |||
27 | * | 27 | * |
28 | * @ApiDoc( | 28 | * @ApiDoc( |
29 | * parameters={ | 29 | * parameters={ |
30 | * {"name"="archive", "dataType"="boolean", "required"=false, "format"="true or false, all entries by default", "description"="filter by archived status."}, | 30 | * {"name"="archive", "dataType"="integer", "required"=false, "format"="1 or 0, all entries by default", "description"="filter by archived status."}, |
31 | * {"name"="star", "dataType"="boolean", "required"=false, "format"="true or false, all entries by default", "description"="filter by starred status."}, | 31 | * {"name"="starred", "dataType"="integer", "required"=false, "format"="1 or 0, all entries by default", "description"="filter by starred status."}, |
32 | * {"name"="sort", "dataType"="string", "required"=false, "format"="'created' or 'updated', default 'created'", "description"="sort entries by date."}, | 32 | * {"name"="sort", "dataType"="string", "required"=false, "format"="'created' or 'updated', default 'created'", "description"="sort entries by date."}, |
33 | * {"name"="order", "dataType"="string", "required"=false, "format"="'asc' or 'desc', default 'desc'", "description"="order of sort."}, | 33 | * {"name"="order", "dataType"="string", "required"=false, "format"="'asc' or 'desc', default 'desc'", "description"="order of sort."}, |
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%2Crest", "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 | * } | 37 | * } |
38 | * ) | 38 | * ) |
39 | * | 39 | * |
@@ -43,8 +43,8 @@ class WallabagRestController extends FOSRestController | |||
43 | { | 43 | { |
44 | $this->validateAuthentication(); | 44 | $this->validateAuthentication(); |
45 | 45 | ||
46 | $isArchived = $request->query->get('archive'); | 46 | $isArchived = (int) $request->query->get('archive'); |
47 | $isStarred = $request->query->get('star'); | 47 | $isStarred = (int) $request->query->get('starred'); |
48 | $sort = $request->query->get('sort', 'created'); | 48 | $sort = $request->query->get('sort', 'created'); |
49 | $order = $request->query->get('order', 'desc'); | 49 | $order = $request->query->get('order', 'desc'); |
50 | $page = (int) $request->query->get('page', 1); | 50 | $page = (int) $request->query->get('page', 1); |
@@ -52,7 +52,7 @@ class WallabagRestController extends FOSRestController | |||
52 | 52 | ||
53 | $pager = $this->getDoctrine() | 53 | $pager = $this->getDoctrine() |
54 | ->getRepository('WallabagCoreBundle:Entry') | 54 | ->getRepository('WallabagCoreBundle:Entry') |
55 | ->findEntries($this->getUser()->getId(), $isArchived, $isStarred, $sort, $order); | 55 | ->findEntries($this->getUser()->getId(), (bool) $isArchived, (bool) $isStarred, $sort, $order); |
56 | 56 | ||
57 | $pager->setCurrentPage($page); | 57 | $pager->setCurrentPage($page); |
58 | $pager->setMaxPerPage($perPage); | 58 | $pager->setMaxPerPage($perPage); |
@@ -97,8 +97,8 @@ class WallabagRestController extends FOSRestController | |||
97 | * {"name"="url", "dataType"="string", "required"=true, "format"="http://www.test.com/article.html", "description"="Url for the entry."}, | 97 | * {"name"="url", "dataType"="string", "required"=true, "format"="http://www.test.com/article.html", "description"="Url for the entry."}, |
98 | * {"name"="title", "dataType"="string", "required"=false, "description"="Optional, we'll get the title from the page."}, | 98 | * {"name"="title", "dataType"="string", "required"=false, "description"="Optional, we'll get the title from the page."}, |
99 | * {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."}, | 99 | * {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."}, |
100 | * {"name"="starred", "dataType"="boolean", "required"=false, "format"="true or false", "description"="entry already starred"}, | 100 | * {"name"="starred", "dataType"="integer", "required"=false, "format"="1 or 0", "description"="entry already starred"}, |
101 | * {"name"="archive", "dataType"="boolean", "required"=false, "format"="true or false", "description"="entry already archived"}, | 101 | * {"name"="archive", "dataType"="integer", "required"=false, "format"="1 or 0", "description"="entry already archived"}, |
102 | * } | 102 | * } |
103 | * ) | 103 | * ) |
104 | * | 104 | * |
@@ -109,8 +109,8 @@ class WallabagRestController extends FOSRestController | |||
109 | $this->validateAuthentication(); | 109 | $this->validateAuthentication(); |
110 | 110 | ||
111 | $url = $request->request->get('url'); | 111 | $url = $request->request->get('url'); |
112 | $isArchived = $request->request->get('archive'); | 112 | $isArchived = (int) $request->request->get('archive'); |
113 | $isStarred = $request->request->get('starred'); | 113 | $isStarred = (int) $request->request->get('starred'); |
114 | 114 | ||
115 | $entry = $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($url, $this->getUser()->getId()); | 115 | $entry = $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($url, $this->getUser()->getId()); |
116 | 116 | ||
@@ -126,11 +126,11 @@ class WallabagRestController extends FOSRestController | |||
126 | $this->get('wallabag_core.content_proxy')->assignTagsToEntry($entry, $tags); | 126 | $this->get('wallabag_core.content_proxy')->assignTagsToEntry($entry, $tags); |
127 | } | 127 | } |
128 | 128 | ||
129 | if ($isStarred === 'true') { | 129 | if (true === (bool) $isStarred) { |
130 | $entry->setStarred(true); | 130 | $entry->setStarred(true); |
131 | } | 131 | } |
132 | 132 | ||
133 | if ($isArchived === 'true') { | 133 | if (true === (bool) $isArchived) { |
134 | $entry->setArchived(true); | 134 | $entry->setArchived(true); |
135 | } | 135 | } |
136 | 136 | ||
@@ -154,8 +154,8 @@ class WallabagRestController extends FOSRestController | |||
154 | * parameters={ | 154 | * parameters={ |
155 | * {"name"="title", "dataType"="string", "required"=false}, | 155 | * {"name"="title", "dataType"="string", "required"=false}, |
156 | * {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."}, | 156 | * {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."}, |
157 | * {"name"="archive", "dataType"="boolean", "required"=false, "format"="true or false", "description"="archived the entry."}, | 157 | * {"name"="archive", "dataType"="integer", "required"=false, "format"="1 or 0", "description"="archived the entry."}, |
158 | * {"name"="star", "dataType"="boolean", "required"=false, "format"="true or false", "description"="starred the entry."}, | 158 | * {"name"="starred", "dataType"="integer", "required"=false, "format"="1 or 0", "description"="starred the entry."}, |
159 | * } | 159 | * } |
160 | * ) | 160 | * ) |
161 | * | 161 | * |
@@ -167,19 +167,19 @@ class WallabagRestController extends FOSRestController | |||
167 | $this->validateUserAccess($entry->getUser()->getId()); | 167 | $this->validateUserAccess($entry->getUser()->getId()); |
168 | 168 | ||
169 | $title = $request->request->get('title'); | 169 | $title = $request->request->get('title'); |
170 | $isArchived = $request->request->get('archive'); | 170 | $isArchived = (int) $request->request->get('archive'); |
171 | $isStarred = $request->request->get('star'); | 171 | $isStarred = (int) $request->request->get('starred'); |
172 | 172 | ||
173 | if (!is_null($title)) { | 173 | if (!is_null($title)) { |
174 | $entry->setTitle($title); | 174 | $entry->setTitle($title); |
175 | } | 175 | } |
176 | 176 | ||
177 | if (!is_null($isArchived)) { | 177 | if (!is_null($isArchived)) { |
178 | $entry->setArchived($isArchived); | 178 | $entry->setArchived((bool) $isArchived); |
179 | } | 179 | } |
180 | 180 | ||
181 | if (!is_null($isStarred)) { | 181 | if (!is_null($isStarred)) { |
182 | $entry->setStarred($isStarred); | 182 | $entry->setStarred((bool) $isStarred); |
183 | } | 183 | } |
184 | 184 | ||
185 | $tags = $request->request->get('tags', ''); | 185 | $tags = $request->request->get('tags', ''); |
diff --git a/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php index f5a9748c..6bc7afa6 100644 --- a/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php +++ b/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php | |||
@@ -188,8 +188,8 @@ class WallabagRestControllerTest extends WallabagApiTestCase | |||
188 | { | 188 | { |
189 | $this->client->request('POST', '/api/entries.json', array( | 189 | $this->client->request('POST', '/api/entries.json', array( |
190 | 'url' => 'http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', | 190 | 'url' => 'http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', |
191 | 'archive' => 'true', | 191 | 'archive' => '1', |
192 | 'starred' => 'true', | 192 | 'starred' => '1', |
193 | )); | 193 | )); |
194 | 194 | ||
195 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | 195 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
@@ -220,8 +220,8 @@ class WallabagRestControllerTest extends WallabagApiTestCase | |||
220 | $this->client->request('PATCH', '/api/entries/'.$entry->getId().'.json', array( | 220 | $this->client->request('PATCH', '/api/entries/'.$entry->getId().'.json', array( |
221 | 'title' => 'New awesome title', | 221 | 'title' => 'New awesome title', |
222 | 'tags' => 'new tag '.uniqid(), | 222 | 'tags' => 'new tag '.uniqid(), |
223 | 'star' => true, | 223 | 'starred' => '1', |
224 | 'archive' => false, | 224 | 'archive' => '0', |
225 | )); | 225 | )); |
226 | 226 | ||
227 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | 227 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index 5e608f05..8f4ddf61 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php | |||
@@ -59,6 +59,8 @@ class Entry | |||
59 | /** | 59 | /** |
60 | * @var bool | 60 | * @var bool |
61 | * | 61 | * |
62 | * @Exclude | ||
63 | * | ||
62 | * @ORM\Column(name="is_archived", type="boolean") | 64 | * @ORM\Column(name="is_archived", type="boolean") |
63 | * | 65 | * |
64 | * @Groups({"entries_for_user", "export_all"}) | 66 | * @Groups({"entries_for_user", "export_all"}) |
@@ -68,6 +70,8 @@ class Entry | |||
68 | /** | 70 | /** |
69 | * @var bool | 71 | * @var bool |
70 | * | 72 | * |
73 | * @Exclude | ||
74 | * | ||
71 | * @ORM\Column(name="is_starred", type="boolean") | 75 | * @ORM\Column(name="is_starred", type="boolean") |
72 | * | 76 | * |
73 | * @Groups({"entries_for_user", "export_all"}) | 77 | * @Groups({"entries_for_user", "export_all"}) |
@@ -271,6 +275,16 @@ class Entry | |||
271 | return $this->isArchived; | 275 | return $this->isArchived; |
272 | } | 276 | } |
273 | 277 | ||
278 | /** | ||
279 | * @VirtualProperty | ||
280 | * @SerializedName("is_archived") | ||
281 | * @Groups({"entries_for_user", "export_all"}) | ||
282 | */ | ||
283 | public function is_Archived() | ||
284 | { | ||
285 | return (int) $this->isArchived(); | ||
286 | } | ||
287 | |||
274 | public function toggleArchive() | 288 | public function toggleArchive() |
275 | { | 289 | { |
276 | $this->isArchived = $this->isArchived() ^ 1; | 290 | $this->isArchived = $this->isArchived() ^ 1; |
@@ -302,6 +316,16 @@ class Entry | |||
302 | return $this->isStarred; | 316 | return $this->isStarred; |
303 | } | 317 | } |
304 | 318 | ||
319 | /** | ||
320 | * @VirtualProperty | ||
321 | * @SerializedName("is_starred") | ||
322 | * @Groups({"entries_for_user", "export_all"}) | ||
323 | */ | ||
324 | public function is_Starred() | ||
325 | { | ||
326 | return (int) $this->isStarred(); | ||
327 | } | ||
328 | |||
305 | public function toggleStar() | 329 | public function toggleStar() |
306 | { | 330 | { |
307 | $this->isStarred = $this->isStarred() ^ 1; | 331 | $this->isStarred = $this->isStarred() ^ 1; |