]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | namespace Wallabag\CoreBundle\Controller; | |
4 | ||
5 | use Nelmio\ApiDocBundle\Annotation\ApiDoc; | |
6 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |
7 | use Symfony\Component\HttpFoundation\Request; | |
8 | use Wallabag\CoreBundle\Entity\Entries; | |
9 | use Wallabag\CoreBundle\Entity\Tags; | |
10 | use Wallabag\CoreBundle\Service\Extractor; | |
11 | ||
12 | class WallabagRestController extends Controller | |
13 | { | |
14 | /** | |
15 | * Retrieve all entries. It could be filtered by many options. | |
16 | * | |
17 | * @ApiDoc( | |
18 | * parameters={ | |
19 | * {"name"="archive", "dataType"="integer", "required"=false, "format"="'0' or '1', default '0'", "description"="filter by archived status."}, | |
20 | * {"name"="star", "dataType"="integer", "required"=false, "format"="'0' or '1', default '0'", "description"="filter by starred status."}, | |
21 | * {"name"="delete", "dataType"="integer", "required"=false, "format"="'0' or '1', default '0'", "description"="filter by deleted status."}, | |
22 | * {"name"="sort", "dataType"="string", "required"=false, "format"="'created' or 'updated', default 'created'", "description"="sort entries by date."}, | |
23 | * {"name"="order", "dataType"="string", "required"=false, "format"="'asc' or 'desc', default 'desc'", "description"="order of sort."}, | |
24 | * {"name"="page", "dataType"="integer", "required"=false, "format"="default '1'", "description"="what page you want."}, | |
25 | * {"name"="perPage", "dataType"="integer", "required"=false, "format"="default'30'", "description"="results per page."}, | |
26 | * {"name"="tags", "dataType"="string", "required"=false, "format"="api%2Crest", "description"="a list of tags url encoded. Will returns entries that matches ALL tags."}, | |
27 | * } | |
28 | * ) | |
29 | * @return Entries | |
30 | */ | |
31 | public function getEntriesAction(Request $request) | |
32 | { | |
33 | $isArchived = $request->query->get('archive', 0); | |
34 | $isStarred = $request->query->get('star', 0); | |
35 | $isDeleted = $request->query->get('delete', 0); | |
36 | $sort = $request->query->get('sort', 'created'); | |
37 | $order = $request->query->get('order', 'desc'); | |
38 | $page = $request->query->get('page', 1); | |
39 | $perPage = $request->query->get('perPage', 30); | |
40 | $tags = $request->query->get('tags', array()); | |
41 | ||
42 | $entries = $this | |
43 | ->getDoctrine() | |
44 | ->getRepository('WallabagCoreBundle:Entries') | |
45 | ->findEntries(1, (int) $isArchived, (int) $isStarred, (int) $isDeleted, $sort, $order); | |
46 | ||
47 | if (!is_array($entries)) { | |
48 | throw $this->createNotFoundException(); | |
49 | } | |
50 | ||
51 | return $entries; | |
52 | } | |
53 | ||
54 | /** | |
55 | * Retrieve a single entry | |
56 | * | |
57 | * @ApiDoc( | |
58 | * requirements={ | |
59 | * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} | |
60 | * } | |
61 | * ) | |
62 | * @return Entries | |
63 | */ | |
64 | public function getEntryAction(Entries $entry) | |
65 | { | |
66 | return $entry; | |
67 | } | |
68 | ||
69 | /** | |
70 | * Create an entry | |
71 | * | |
72 | * @ApiDoc( | |
73 | * parameters={ | |
74 | * {"name"="url", "dataType"="string", "required"=true, "format"="http://www.test.com/article.html", "description"="Url for the entry."}, | |
75 | * {"name"="title", "dataType"="string", "required"=false, "description"="Optional, we'll get the title from the page."}, | |
76 | * {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."}, | |
77 | * } | |
78 | * ) | |
79 | */ | |
80 | public function postEntriesAction(Request $request) | |
81 | { | |
82 | //TODO la récup ne marche pas | |
83 | //TODO gérer si on passe le titre | |
84 | //TODO gérer si on passe les tags | |
85 | //TODO ne pas avoir du code comme ça qui doit se trouver dans le Repository | |
86 | $url = $request->request->get('url'); | |
87 | ||
88 | $content = Extractor::extract($url); | |
89 | $entry = new Entries(); | |
90 | $entry->setUserId(1); | |
91 | $entry->setUrl($url); | |
92 | $entry->setTitle($content->getTitle()); | |
93 | $entry->setContent($content->getBody()); | |
94 | $em = $this->getDoctrine()->getManager(); | |
95 | $em->persist($entry); | |
96 | $em->flush(); | |
97 | ||
98 | return $entry; | |
99 | } | |
100 | ||
101 | /** | |
102 | * Change several properties of an entry | |
103 | * | |
104 | * @ApiDoc( | |
105 | * requirements={ | |
106 | * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} | |
107 | * }, | |
108 | * parameters={ | |
109 | * {"name"="title", "dataType"="string", "required"=false}, | |
110 | * {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."}, | |
111 | * {"name"="archive", "dataType"="integer", "required"=false, "format"="'0' or '1', default '0'", "description"="archived the entry."}, | |
112 | * {"name"="star", "dataType"="integer", "required"=false, "format"="'0' or '1', default '0'", "description"="starred the entry."}, | |
113 | * {"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.."}, | |
114 | * } | |
115 | * ) | |
116 | */ | |
117 | public function patchEntriesAction(Entries $entry) | |
118 | { | |
119 | } | |
120 | ||
121 | /** | |
122 | * Delete **permanently** an entry | |
123 | * | |
124 | * @ApiDoc( | |
125 | * requirements={ | |
126 | * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} | |
127 | * } | |
128 | * ) | |
129 | */ | |
130 | public function deleteEntriesAction(Entries $entry) | |
131 | { | |
132 | } | |
133 | ||
134 | /** | |
135 | * Retrieve all tags for an entry | |
136 | * | |
137 | * @ApiDoc( | |
138 | * requirements={ | |
139 | * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} | |
140 | * } | |
141 | * ) | |
142 | */ | |
143 | public function getEntriesTagsAction(Entries $entry) | |
144 | { | |
145 | } | |
146 | ||
147 | /** | |
148 | * Add one or more tags to an entry | |
149 | * | |
150 | * @ApiDoc( | |
151 | * requirements={ | |
152 | * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} | |
153 | * }, | |
154 | * parameters={ | |
155 | * {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."}, | |
156 | * } | |
157 | * ) | |
158 | */ | |
159 | public function postEntriesTagsAction(Entries $entry) | |
160 | { | |
161 | } | |
162 | ||
163 | /** | |
164 | * Permanently remove one tag for an entry | |
165 | * | |
166 | * @ApiDoc( | |
167 | * requirements={ | |
168 | * {"name"="tag", "dataType"="string", "requirement"="\w+", "description"="The tag"}, | |
169 | * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} | |
170 | * } | |
171 | * ) | |
172 | */ | |
173 | public function deleteEntriesTagsAction(Entries $entry, Tags $tag) | |
174 | { | |
175 | } | |
176 | ||
177 | /** | |
178 | * Retrieve all tags | |
179 | * | |
180 | * @ApiDoc( | |
181 | * ) | |
182 | */ | |
183 | public function getTagsAction() | |
184 | { | |
185 | } | |
186 | ||
187 | /** | |
188 | * Retrieve a single tag | |
189 | * | |
190 | * @ApiDoc( | |
191 | * requirements={ | |
192 | * {"name"="tag", "dataType"="string", "requirement"="\w+", "description"="The tag"} | |
193 | * } | |
194 | * ) | |
195 | */ | |
196 | public function getTagAction(Tags $tag) | |
197 | { | |
198 | } | |
199 | ||
200 | /** | |
201 | * Permanently remove one tag from **every** entry | |
202 | * | |
203 | * @ApiDoc( | |
204 | * requirements={ | |
205 | * {"name"="tag", "dataType"="string", "requirement"="\w+", "description"="The tag"} | |
206 | * } | |
207 | * ) | |
208 | */ | |
209 | public function deleteTagAction(Tags $tag) | |
210 | { | |
211 | } | |
212 | } |