aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/Wallabag/CoreBundle/Controller/EntryController.php6
-rw-r--r--src/Wallabag/CoreBundle/Controller/WallabagRestController.php99
-rw-r--r--src/Wallabag/CoreBundle/Repository/EntriesRepository.php13
3 files changed, 86 insertions, 32 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php
index c6c94462..25f18711 100644
--- a/src/Wallabag/CoreBundle/Controller/EntryController.php
+++ b/src/Wallabag/CoreBundle/Controller/EntryController.php
@@ -64,6 +64,8 @@ class EntryController extends Controller
64 public function showUnreadAction() 64 public function showUnreadAction()
65 { 65 {
66 $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entries'); 66 $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entries');
67 // TODO don't give the user ID like this
68 // TODO change pagination
67 $entries = $repository->findUnreadByUser(1, 0); 69 $entries = $repository->findUnreadByUser(1, 0);
68 70
69 return $this->render( 71 return $this->render(
@@ -81,6 +83,8 @@ class EntryController extends Controller
81 public function showArchiveAction() 83 public function showArchiveAction()
82 { 84 {
83 $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entries'); 85 $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entries');
86 // TODO don't give the user ID like this
87 // TODO change pagination
84 $entries = $repository->findArchiveByUser(1, 0); 88 $entries = $repository->findArchiveByUser(1, 0);
85 89
86 return $this->render( 90 return $this->render(
@@ -98,6 +102,8 @@ class EntryController extends Controller
98 public function showStarredAction() 102 public function showStarredAction()
99 { 103 {
100 $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entries'); 104 $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entries');
105 // TODO don't give the user ID like this
106 // TODO change pagination
101 $entries = $repository->findStarredByUser(1, 0); 107 $entries = $repository->findStarredByUser(1, 0);
102 108
103 return $this->render( 109 return $this->render(
diff --git a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php
index eb41d011..eec8d32c 100644
--- a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php
+++ b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php
@@ -6,38 +6,55 @@ use Nelmio\ApiDocBundle\Annotation\ApiDoc;
6use FOS\RestBundle\Controller\Annotations\View; 6use FOS\RestBundle\Controller\Annotations\View;
7use Symfony\Bundle\FrameworkBundle\Controller\Controller; 7use Symfony\Bundle\FrameworkBundle\Controller\Controller;
8use Symfony\Component\HttpFoundation\Request; 8use Symfony\Component\HttpFoundation\Request;
9use Symfony\Component\Security\Core\Exception\AccessDeniedException;
10use Wallabag\CoreBundle\Entity\Entries; 9use Wallabag\CoreBundle\Entity\Entries;
11use Wallabag\CoreBundle\Entity\Tags; 10use Wallabag\CoreBundle\Entity\Tags;
12use Wallabag\CoreBundle\Entity\Users;
13 11
14class WallabagRestController 12class WallabagRestController extends Controller
15{ 13{
16 14
17 /** 15 /**
18 * Fetches all entries 16 * Retrieve all entries. It could be filtered by many options.
19 * 17 *
20 * @ApiDoc( 18 * @ApiDoc(
19 * parameters={
20 * {"name"="archive", "dataType"="integer", "required"=false, "format"="'0' or '1', default '0'", "description"="filter by archived status."},
21 * {"name"="star", "dataType"="integer", "required"=false, "format"="'0' or '1', default '0'", "description"="filter by starred status."},
22 * {"name"="delete", "dataType"="integer", "required"=false, "format"="'0' or '1', default '0'", "description"="filter by deleted status."},
23 * {"name"="sort", "dataType"="string", "required"=false, "format"="'created' or 'updated', default 'created'", "description"="sort entries by date."},
24 * {"name"="order", "dataType"="string", "required"=false, "format"="'asc' or 'desc', default 'desc'", "description"="order of sort."},
25 * {"name"="page", "dataType"="integer", "required"=false, "format"="default '1'", "description"="what page you want."},
26 * {"name"="perPage", "dataType"="integer", "required"=false, "format"="default'30'", "description"="results per page."},
27 * {"name"="tags", "dataType"="string", "required"=false, "format"="api%2Crest", "description"="a list of tags url encoded. Will returns entries that matches ALL tags."},
28 * }
21 * ) 29 * )
22 * @return Entries 30 * @return Entries
23 */ 31 */
24 public function getEntriesAction(Request $request) 32 public function getEntriesAction(Request $request)
25 { 33 {
26 $isArchive = $request->query->get('archive'); 34 $isArchived = $request->query->get('archive', 0);
27 var_dump($isArchive); 35 $isStarred = $request->query->get('star', 0);
28 $isStarred = $request->query->get('star'); 36 $isDeleted = $request->query->get('delete', 0);
29 $isDeleted = $request->query->get('delete'); 37 $sort = $request->query->get('sort', 'created');
30 $sort = $request->query->get('sort'); 38 $order = $request->query->get('order', 'desc');
31 $order = $request->query->get('order'); 39 $page = $request->query->get('page', 1);
32 $page = $request->query->get('page'); 40 $perPage = $request->query->get('perPage', 30);
33 $perPage = $request->query->get('perPage'); 41 $tags = $request->query->get('tags', array());
34 $tags = $request->query->get('tags', array()); 42
35 43 $entries = $this
36 return 'plop'; 44 ->getDoctrine()
45 ->getRepository('WallabagCoreBundle:Entries')
46 ->findEntries(1, (int)$isArchived, (int)$isStarred, (int)$isDeleted, $sort, $order);
47
48 if(!is_array($entries)) {
49 throw $this->createNotFoundException();
50 }
51
52 return $entries;
53
37 } 54 }
38 55
39 /** 56 /**
40 * Fetches an entry 57 * Retrieve a single entry
41 * 58 *
42 * @ApiDoc( 59 * @ApiDoc(
43 * requirements={ 60 * requirements={
@@ -52,26 +69,35 @@ class WallabagRestController
52 } 69 }
53 70
54 /** 71 /**
55 * Deletes an entry 72 * Create an entry
56 * 73 *
57 * @ApiDoc( 74 * @ApiDoc(
58 * requirements={ 75 * parameters={
59 * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} 76 * {"name"="url", "dataType"="string", "required"=true, "format"="http://www.test.com/article.html", "description"="Url for the entry."},
60 * } 77 * {"name"="title", "dataType"="string", "required"=false, "description"="Optional, we'll get the title from the page."},
78 * {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."},
79 * }
61 * ) 80 * )
62 */ 81 */
63 public function deleteEntriesAction(Entries $entry) 82 public function postEntriesAction()
64 { 83 {
65 84
66 } 85 }
67 86
68 /** 87 /**
69 * Changes several properties of an entry. I.E tags, archived, starred and deleted status 88 * Change several properties of an entry
70 * 89 *
71 * @ApiDoc( 90 * @ApiDoc(
72 * requirements={ 91 * requirements={
73 * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} 92 * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"}
74 * } 93 * },
94 * parameters={
95 * {"name"="title", "dataType"="string", "required"=false},
96 * {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."},
97 * {"name"="archive", "dataType"="integer", "required"=false, "format"="'0' or '1', default '0'", "description"="archived the entry."},
98 * {"name"="star", "dataType"="integer", "required"=false, "format"="'0' or '1', default '0'", "description"="starred the entry."},
99 * {"name"="delete", "dataType"="integer", "required"=false, "format"="'0' or '1', default '0'", "description"="flag as deleted. Default false. In case that you don't want to *really* remove it.."},
100 * }
75 * ) 101 * )
76 */ 102 */
77 public function patchEntriesAction(Entries $entry) 103 public function patchEntriesAction(Entries $entry)
@@ -80,18 +106,22 @@ class WallabagRestController
80 } 106 }
81 107
82 /** 108 /**
83 * Saves a new entry 109 * Delete **permanently** an entry
84 * 110 *
85 * @ApiDoc( 111 * @ApiDoc(
112 * requirements={
113 * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"}
114 * }
86 * ) 115 * )
87 */ 116 */
88 public function postEntriesAction() 117 public function deleteEntriesAction(Entries $entry)
89 { 118 {
90 119
91 } 120 }
92 121
122
93 /** 123 /**
94 * Gets tags for an entry 124 * Retrieve all tags for an entry
95 * 125 *
96 * @ApiDoc( 126 * @ApiDoc(
97 * requirements={ 127 * requirements={
@@ -104,12 +134,15 @@ class WallabagRestController
104 } 134 }
105 135
106 /** 136 /**
107 * Saves new tag for an entry 137 * Add one or more tags to an entry
108 * 138 *
109 * @ApiDoc( 139 * @ApiDoc(
110 * requirements={ 140 * requirements={
111 * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} 141 * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"}
112 * } 142 * },
143 * parameters={
144 * {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."},
145 * }
113 * ) 146 * )
114 */ 147 */
115 public function postEntriesTagsAction(Entries $entry) { 148 public function postEntriesTagsAction(Entries $entry) {
@@ -117,7 +150,7 @@ class WallabagRestController
117 } 150 }
118 151
119 /** 152 /**
120 * Remove tag for an entry 153 * Permanently remove one tag for an entry
121 * 154 *
122 * @ApiDoc( 155 * @ApiDoc(
123 * requirements={ 156 * requirements={
@@ -132,7 +165,7 @@ class WallabagRestController
132 } 165 }
133 166
134 /** 167 /**
135 * Gets tags for a user 168 * Retrieve all tags
136 * 169 *
137 * @ApiDoc( 170 * @ApiDoc(
138 * ) 171 * )
@@ -142,10 +175,12 @@ class WallabagRestController
142 } 175 }
143 176
144 /** 177 /**
145 * Gets one tag 178 * Retrieve a single tag
146 * 179 *
147 * @ApiDoc( 180 * @ApiDoc(
181 * requirements={
148 * {"name"="tag", "dataType"="string", "requirement"="\w+", "description"="The tag"} 182 * {"name"="tag", "dataType"="string", "requirement"="\w+", "description"="The tag"}
183 * }
149 * ) 184 * )
150 */ 185 */
151 public function getTagAction(Tags $tag) { 186 public function getTagAction(Tags $tag) {
@@ -153,7 +188,7 @@ class WallabagRestController
153 } 188 }
154 189
155 /** 190 /**
156 * Delete tag 191 * Permanently remove one tag from **every** entry
157 * 192 *
158 * @ApiDoc( 193 * @ApiDoc(
159 * requirements={ 194 * requirements={
diff --git a/src/Wallabag/CoreBundle/Repository/EntriesRepository.php b/src/Wallabag/CoreBundle/Repository/EntriesRepository.php
index 5a71b9ef..edbb96b4 100644
--- a/src/Wallabag/CoreBundle/Repository/EntriesRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/EntriesRepository.php
@@ -76,4 +76,17 @@ class EntriesRepository extends EntityRepository
76 76
77 return $paginator; 77 return $paginator;
78 } 78 }
79
80 public function findEntries($userId, $isArchived, $isStarred, $isDeleted, $sort, $order)
81 {
82 $qb = $this->createQueryBuilder('e')
83 ->select('e')
84 ->where('e.isFav =:isStarred')->setParameter('isStarred', $isStarred)
85 ->andWhere('e.isRead =:isArchived')->setParameter('isArchived', $isArchived)
86 ->andWhere('e.userId =:userId')->setParameter('userId', $userId)
87 ->getQuery()
88 ->getResult(Query::HYDRATE_ARRAY);
89
90 return $qb;
91 }
79} 92}