@@ -44,25 +44,36 @@ public function __construct(
4444
4545 /**
4646 * Get list of polls
47+ * psalm-return JSONResponse<array{
48+ * polls: array<int, Poll>,
49+ * permissions: array{
50+ * pollCreationAllowed: bool,
51+ * comboAllowed: bool
52+ * },
53+ * pollGroups: array<int, PollGroup>
54+ * }>
4755 */
4856 #[NoAdminRequired]
4957 #[FrontpageRoute(verb: 'GET ' , url: '/polls ' )]
50- public function list (): JSONResponse {
58+ public function listPolls (): JSONResponse {
5159 return $ this ->response (function () {
5260 $ appSettings = Container::queryClass (AppSettings::class);
5361 return [
54- 'list ' => $ this ->pollService ->list (),
62+ 'polls ' => $ this ->pollService ->listPolls (),
5563 'permissions ' => [
5664 'pollCreationAllowed ' => $ appSettings ->getPollCreationAllowed (),
5765 'comboAllowed ' => $ appSettings ->getComboAllowed (),
5866 ],
67+ 'pollGroups ' => $ this ->pollService ->listPollGroups (),
5968 ];
6069 });
6170 }
6271
6372 /**
6473 * get poll
6574 * @param int $pollId Poll id
75+ *
76+ * psalm-return JSONResponse<array{poll: Poll}>
6677 */
6778 #[NoAdminRequired]
6879 #[FrontpageRoute(verb: 'GET ' , url: '/poll/{pollId}/poll ' )]
@@ -75,6 +86,16 @@ public function get(int $pollId): JSONResponse {
7586 /**
7687 * get complete poll
7788 * @param int $pollId Poll id
89+ *
90+ * psalm-return JSONResponse<array{
91+ * poll: Poll,
92+ * options: array<int, Option>,
93+ * votes: array<int, Vote>,
94+ * comments: array<int, Comment>,
95+ * shares: array<int, Share>,
96+ * subscribed: Subscription|null
97+ * }>
98+ *
7899 */
79100 #[NoAdminRequired]
80101 #[FrontpageRoute(verb: 'GET ' , url: '/poll/{pollId} ' )]
@@ -93,6 +114,9 @@ public function getFull(int $pollId): JSONResponse {
93114 * Add poll
94115 * @param string $title Poll title
95116 * @param string $type Poll type ('datePoll', 'textPoll')
117+ * @param string $votingVariant Voting variant (default: Poll::VARIANT_SIMPLE)
118+ *
119+ * psalm-return JSONResponse<array{poll: Poll}>
96120 */
97121 #[NoAdminRequired]
98122 #[FrontpageRoute(verb: 'POST ' , url: '/poll/add ' )]
@@ -109,6 +133,8 @@ public function add(string $type, string $title, string $votingVariant = Poll::V
109133 * Update poll configuration
110134 * @param int $pollId Poll id
111135 * @param array $poll poll config
136+ *
137+ * psalm-return JSONResponse<array{poll: Poll}>
112138 */
113139 #[NoAdminRequired]
114140 #[FrontpageRoute(verb: 'PUT ' , url: '/poll/{pollId} ' )]
@@ -238,4 +264,84 @@ public function changeOwner(int $pollId, string $targetUserId): JSONResponse {
238264 public function getParticipantsEmailAddresses (int $ pollId ): JSONResponse {
239265 return $ this ->response (fn () => $ this ->pollService ->getParticipantsEmailAddresses ($ pollId ));
240266 }
267+
268+ /**
269+ * Get list of pollgroups
270+ *
271+ * psalm-return JSONResponse<array{pollGroups: array<int, PollGroup>}>
272+ */
273+ #[NoAdminRequired]
274+ #[FrontpageRoute(verb: 'GET ' , url: '/pollgroups ' )]
275+ public function listPollGroups (): JSONResponse {
276+ return $ this ->response (function () {
277+ return [
278+ 'pollGroups ' => $ this ->pollService ->listPollGroups (),
279+ ];
280+ });
281+ }
282+
283+ /**
284+ * Create a new pollgroup with its title and add a poll to it
285+ *
286+ * @param int $pollId Poll id to add to the new pollgroup
287+ * @param string $newPollGroupName Name of the new pollgroup
288+ *
289+ * psalm-return JSONResponse<array{pollGroup: PollGroup, poll: Poll}>
290+ */
291+ #[NoAdminRequired]
292+ #[FrontpageRoute(verb: 'POST ' , url: '/pollgroup/new/poll/{pollId} ' )]
293+ public function addPollToNewPollGroup (int $ pollId , string $ newPollGroupName = '' ): JSONResponse {
294+ return $ this ->response (fn () => [
295+ 'pollGroup ' => $ this ->pollService ->addPollToPollGroup ($ pollId , newPollGroupName: $ newPollGroupName ),
296+ 'poll ' => $ this ->pollService ->get ($ pollId ),
297+ ]);
298+ }
299+
300+ /**
301+ * Add poll to pollgroup
302+ * @param int $pollId Poll id
303+ * @param int $pollGroupId Poll group id
304+ *
305+ * psalm-return JSONResponse<array{pollGroup: PollGroup, poll: Poll}>
306+ */
307+ #[NoAdminRequired]
308+ #[FrontpageRoute(verb: 'PUT ' , url: '/pollgroup/{pollGroupId}/poll/{pollId} ' )]
309+ public function addPollToPollGroup (int $ pollId , int $ pollGroupId ): JSONResponse {
310+ return $ this ->response (fn () => [
311+ 'pollGroup ' => $ this ->pollService ->addPollToPollGroup ($ pollId , $ pollGroupId ),
312+ 'poll ' => $ this ->pollService ->get ($ pollId ),
313+ ]);
314+ }
315+
316+ /**
317+ * Update Pollgroup
318+ */
319+ #[NoAdminRequired]
320+ #[FrontpageRoute(verb: 'PUT ' , url: '/pollgroup/{pollGroupId}/update ' )]
321+ public function updatePollGroup (
322+ int $ pollGroupId ,
323+ string $ title ,
324+ string $ titleExt ,
325+ string $ description ,
326+ ): JSONResponse {
327+ return $ this ->response (fn () => [
328+ 'pollGroup ' => $ this ->pollService ->updatePollGroup ($ pollGroupId , $ title , $ titleExt , $ description ),
329+ ]);
330+ }
331+ /**
332+ * Remove poll from pollgroup
333+ * @param int $pollId Poll id
334+ * @param int $pollGroupId Poll group id
335+ *
336+ * psalm-return JSONResponse<array{pollGroup: PollGroup | null, poll: Poll}>
337+ */
338+ #[NoAdminRequired]
339+ #[FrontpageRoute(verb: 'DELETE ' , url: '/pollgroup/{pollGroupId}/poll/{pollId} ' )]
340+ public function removePollFromPollGroup (int $ pollId , int $ pollGroupId ): JSONResponse {
341+ return $ this ->response (fn () => [
342+ 'pollGroup ' => $ this ->pollService ->removePollFromPollGroup ($ pollId , $ pollGroupId ),
343+ 'poll ' => $ this ->pollService ->get ($ pollId ),
344+ ]);
345+ }
346+
241347}
0 commit comments