Skip to content

Commit 823e801

Browse files
committed
refactor(dashboard): Use attributes for routing
Signed-off-by: provokateurin <kate@provokateurin.de>
1 parent 35252b9 commit 823e801

4 files changed

Lines changed: 59 additions & 90 deletions

File tree

apps/dashboard/appinfo/routes.php

Lines changed: 0 additions & 41 deletions
This file was deleted.

apps/dashboard/lib/Controller/DashboardApiController.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use OCA\Dashboard\ResponseDefinitions;
3232
use OCA\Dashboard\Service\DashboardService;
3333
use OCP\AppFramework\Http;
34+
use OCP\AppFramework\Http\Attribute\ApiRoute;
3435
use OCP\AppFramework\Http\DataResponse;
3536
use OCP\AppFramework\OCSController;
3637
use OCP\Dashboard\IAPIWidget;
@@ -98,6 +99,7 @@ static function (IWidget $widget) use ($widgetIds) {
9899
*
99100
* 200: Widget items returned
100101
*/
102+
#[ApiRoute(verb: 'GET', url: '/api/v1/widget-items')]
101103
public function getWidgetItems(array $sinceIds = [], int $limit = 7, array $widgets = []): DataResponse {
102104
$items = [];
103105
$widgets = $this->getShownWidgets($widgets);
@@ -126,6 +128,7 @@ public function getWidgetItems(array $sinceIds = [], int $limit = 7, array $widg
126128
*
127129
* 200: Widget items returned
128130
*/
131+
#[ApiRoute(verb: 'GET', url: '/api/v2/widget-items')]
129132
public function getWidgetItemsV2(array $sinceIds = [], int $limit = 7, array $widgets = []): DataResponse {
130133
$items = [];
131134
$widgets = $this->getShownWidgets($widgets);
@@ -150,6 +153,7 @@ public function getWidgetItemsV2(array $sinceIds = [], int $limit = 7, array $wi
150153
*
151154
* 200: Widgets returned
152155
*/
156+
#[ApiRoute(verb: 'GET', url: '/api/v1/widgets')]
153157
public function getWidgets(): DataResponse {
154158
$widgets = $this->dashboardManager->getWidgets();
155159

@@ -200,6 +204,7 @@ public function getWidgets(): DataResponse {
200204
*
201205
* 200: Layout returned
202206
*/
207+
#[ApiRoute(verb: 'GET', url: '/api/v3/layout')]
203208
public function getLayout(): DataResponse {
204209
return new DataResponse(['layout' => $this->service->getLayout()]);
205210
}
@@ -213,6 +218,7 @@ public function getLayout(): DataResponse {
213218
*
214219
* 200: Statuses updated successfully
215220
*/
221+
#[ApiRoute(verb: 'POST', url: '/api/v3/layout')]
216222
public function updateLayout(array $layout): DataResponse {
217223
$this->config->setUserValue($this->userId, 'dashboard', 'layout', implode(',', $layout));
218224
return new DataResponse(['layout' => $layout]);
@@ -226,6 +232,7 @@ public function updateLayout(array $layout): DataResponse {
226232
*
227233
* 200: Statuses returned
228234
*/
235+
#[ApiRoute(verb: 'GET', url: '/api/v3/statuses')]
229236
public function getStatuses(): DataResponse {
230237
return new DataResponse(['statuses' => $this->service->getStatuses()]);
231238
}
@@ -239,6 +246,7 @@ public function getStatuses(): DataResponse {
239246
*
240247
* 200: Statuses updated successfully
241248
*/
249+
#[ApiRoute(verb: 'POST', url: '/api/v3/statuses')]
242250
public function updateStatuses(array $statuses): DataResponse {
243251
$this->config->setUserValue($this->userId, 'dashboard', 'statuses', implode(',', $statuses));
244252
return new DataResponse(['statuses' => $statuses]);

apps/dashboard/lib/Controller/DashboardController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use OCA\Dashboard\Service\DashboardService;
3434
use OCP\AppFramework\Controller;
3535
use OCP\AppFramework\Http;
36+
use OCP\AppFramework\Http\Attribute\FrontpageRoute;
3637
use OCP\AppFramework\Http\Attribute\OpenAPI;
3738
use OCP\AppFramework\Http\TemplateResponse;
3839
use OCP\AppFramework\Services\IInitialState;
@@ -65,6 +66,7 @@ public function __construct(
6566
* @NoAdminRequired
6667
* @return TemplateResponse
6768
*/
69+
#[FrontpageRoute(verb: 'GET', url: '/')]
6870
public function index(): TemplateResponse {
6971
\OCP\Util::addStyle('dashboard', 'dashboard');
7072
\OCP\Util::addScript('dashboard', 'main', 'theming');

apps/dashboard/openapi.json

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,10 @@
172172
}
173173
},
174174
"paths": {
175-
"/ocs/v2.php/apps/dashboard/api/v1/widgets": {
175+
"/ocs/v2.php/apps/dashboard/api/v1/widget-items": {
176176
"get": {
177-
"operationId": "dashboard_api-get-widgets",
178-
"summary": "Get the widgets",
177+
"operationId": "dashboard_api-get-widget-items",
178+
"summary": "Get the items for the widgets",
179179
"tags": [
180180
"dashboard_api"
181181
],
@@ -188,6 +188,38 @@
188188
}
189189
],
190190
"parameters": [
191+
{
192+
"name": "sinceIds",
193+
"in": "query",
194+
"description": "Array indexed by widget Ids, contains date/id from which we want the new items",
195+
"schema": {
196+
"type": "string"
197+
}
198+
},
199+
{
200+
"name": "limit",
201+
"in": "query",
202+
"description": "Limit number of result items per widget",
203+
"schema": {
204+
"type": "integer",
205+
"format": "int64",
206+
"default": 7,
207+
"minimum": 1,
208+
"maximum": 30
209+
}
210+
},
211+
{
212+
"name": "widgets[]",
213+
"in": "query",
214+
"description": "Limit results to specific widgets",
215+
"schema": {
216+
"type": "array",
217+
"default": [],
218+
"items": {
219+
"type": "string"
220+
}
221+
}
222+
},
191223
{
192224
"name": "OCS-APIRequest",
193225
"in": "header",
@@ -201,7 +233,7 @@
201233
],
202234
"responses": {
203235
"200": {
204-
"description": "Widgets returned",
236+
"description": "Widget items returned",
205237
"content": {
206238
"application/json": {
207239
"schema": {
@@ -223,7 +255,10 @@
223255
"data": {
224256
"type": "object",
225257
"additionalProperties": {
226-
"$ref": "#/components/schemas/Widget"
258+
"type": "array",
259+
"items": {
260+
"$ref": "#/components/schemas/WidgetItem"
261+
}
227262
}
228263
}
229264
}
@@ -236,9 +271,9 @@
236271
}
237272
}
238273
},
239-
"/ocs/v2.php/apps/dashboard/api/v1/widget-items": {
274+
"/ocs/v2.php/apps/dashboard/api/v2/widget-items": {
240275
"get": {
241-
"operationId": "dashboard_api-get-widget-items",
276+
"operationId": "dashboard_api-get-widget-items-v2",
242277
"summary": "Get the items for the widgets",
243278
"tags": [
244279
"dashboard_api"
@@ -263,7 +298,7 @@
263298
{
264299
"name": "limit",
265300
"in": "query",
266-
"description": "Limit number of result items per widget",
301+
"description": "Limit number of result items per widget, not more than 30 are allowed",
267302
"schema": {
268303
"type": "integer",
269304
"format": "int64",
@@ -319,10 +354,7 @@
319354
"data": {
320355
"type": "object",
321356
"additionalProperties": {
322-
"type": "array",
323-
"items": {
324-
"$ref": "#/components/schemas/WidgetItem"
325-
}
357+
"$ref": "#/components/schemas/WidgetItems"
326358
}
327359
}
328360
}
@@ -335,10 +367,10 @@
335367
}
336368
}
337369
},
338-
"/ocs/v2.php/apps/dashboard/api/v2/widget-items": {
370+
"/ocs/v2.php/apps/dashboard/api/v1/widgets": {
339371
"get": {
340-
"operationId": "dashboard_api-get-widget-items-v2",
341-
"summary": "Get the items for the widgets",
372+
"operationId": "dashboard_api-get-widgets",
373+
"summary": "Get the widgets",
342374
"tags": [
343375
"dashboard_api"
344376
],
@@ -351,38 +383,6 @@
351383
}
352384
],
353385
"parameters": [
354-
{
355-
"name": "sinceIds",
356-
"in": "query",
357-
"description": "Array indexed by widget Ids, contains date/id from which we want the new items",
358-
"schema": {
359-
"type": "string"
360-
}
361-
},
362-
{
363-
"name": "limit",
364-
"in": "query",
365-
"description": "Limit number of result items per widget, not more than 30 are allowed",
366-
"schema": {
367-
"type": "integer",
368-
"format": "int64",
369-
"default": 7,
370-
"minimum": 1,
371-
"maximum": 30
372-
}
373-
},
374-
{
375-
"name": "widgets[]",
376-
"in": "query",
377-
"description": "Limit results to specific widgets",
378-
"schema": {
379-
"type": "array",
380-
"default": [],
381-
"items": {
382-
"type": "string"
383-
}
384-
}
385-
},
386386
{
387387
"name": "OCS-APIRequest",
388388
"in": "header",
@@ -396,7 +396,7 @@
396396
],
397397
"responses": {
398398
"200": {
399-
"description": "Widget items returned",
399+
"description": "Widgets returned",
400400
"content": {
401401
"application/json": {
402402
"schema": {
@@ -418,7 +418,7 @@
418418
"data": {
419419
"type": "object",
420420
"additionalProperties": {
421-
"$ref": "#/components/schemas/WidgetItems"
421+
"$ref": "#/components/schemas/Widget"
422422
}
423423
}
424424
}

0 commit comments

Comments
 (0)