]> source.dussan.org Git - nextcloud-server.git/commitdiff
refactor(dashboard): Use attributes for routing 42973/head
authorprovokateurin <kate@provokateurin.de>
Sun, 5 May 2024 06:19:37 +0000 (08:19 +0200)
committerprovokateurin <kate@provokateurin.de>
Fri, 10 May 2024 07:44:01 +0000 (09:44 +0200)
Signed-off-by: provokateurin <kate@provokateurin.de>
apps/dashboard/appinfo/routes.php [deleted file]
apps/dashboard/lib/Controller/DashboardApiController.php
apps/dashboard/lib/Controller/DashboardController.php
apps/dashboard/openapi.json

diff --git a/apps/dashboard/appinfo/routes.php b/apps/dashboard/appinfo/routes.php
deleted file mode 100644 (file)
index 6fcc920..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-/**
- * @copyright Copyright (c) 2020 Julius Härtl <jus@bitgrid.net>
- *
- * @author Julien Veyssier <eneiluj@posteo.net>
- * @author Julius Härtl <jus@bitgrid.net>
- * @author Richard Steinmetz <richard@steinmetz.cloud>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-return [
-       'routes' => [
-               ['name' => 'dashboard#index', 'url' => '/', 'verb' => 'GET'],
-       ],
-       'ocs' => [
-               ['name' => 'dashboardApi#getWidgets', 'url' => '/api/v1/widgets', 'verb' => 'GET'],
-               ['name' => 'dashboardApi#getWidgetItems', 'url' => '/api/v1/widget-items', 'verb' => 'GET'],
-               ['name' => 'dashboardApi#getWidgetItemsV2', 'url' => '/api/v2/widget-items', 'verb' => 'GET'],
-               ['name' => 'dashboardApi#getLayout', 'url' => '/api/v3/layout', 'verb' => 'GET'],
-               ['name' => 'dashboardApi#updateLayout', 'url' => '/api/v3/layout', 'verb' => 'POST'],
-               ['name' => 'dashboardApi#getStatuses', 'url' => '/api/v3/statuses', 'verb' => 'GET'],
-               ['name' => 'dashboardApi#updateStatuses', 'url' => '/api/v3/statuses', 'verb' => 'POST'],
-       ]
-];
index bd7cb40260094a153bec04297fa60dcd8c7dfd05..b6ebb4625b5a0805283e13d54f956f39d11244f2 100644 (file)
@@ -31,6 +31,7 @@ namespace OCA\Dashboard\Controller;
 use OCA\Dashboard\ResponseDefinitions;
 use OCA\Dashboard\Service\DashboardService;
 use OCP\AppFramework\Http;
+use OCP\AppFramework\Http\Attribute\ApiRoute;
 use OCP\AppFramework\Http\DataResponse;
 use OCP\AppFramework\OCSController;
 use OCP\Dashboard\IAPIWidget;
@@ -98,6 +99,7 @@ class DashboardApiController extends OCSController {
         *
         * 200: Widget items returned
         */
+       #[ApiRoute(verb: 'GET', url: '/api/v1/widget-items')]
        public function getWidgetItems(array $sinceIds = [], int $limit = 7, array $widgets = []): DataResponse {
                $items = [];
                $widgets = $this->getShownWidgets($widgets);
@@ -126,6 +128,7 @@ class DashboardApiController extends OCSController {
         *
         * 200: Widget items returned
         */
+       #[ApiRoute(verb: 'GET', url: '/api/v2/widget-items')]
        public function getWidgetItemsV2(array $sinceIds = [], int $limit = 7, array $widgets = []): DataResponse {
                $items = [];
                $widgets = $this->getShownWidgets($widgets);
@@ -150,6 +153,7 @@ class DashboardApiController extends OCSController {
         *
         * 200: Widgets returned
         */
+       #[ApiRoute(verb: 'GET', url: '/api/v1/widgets')]
        public function getWidgets(): DataResponse {
                $widgets = $this->dashboardManager->getWidgets();
 
@@ -200,6 +204,7 @@ class DashboardApiController extends OCSController {
         *
         * 200: Layout returned
         */
+       #[ApiRoute(verb: 'GET', url: '/api/v3/layout')]
        public function getLayout(): DataResponse {
                return new DataResponse(['layout' => $this->service->getLayout()]);
        }
@@ -213,6 +218,7 @@ class DashboardApiController extends OCSController {
         *
         * 200: Statuses updated successfully
         */
+       #[ApiRoute(verb: 'POST', url: '/api/v3/layout')]
        public function updateLayout(array $layout): DataResponse {
                $this->config->setUserValue($this->userId, 'dashboard', 'layout', implode(',', $layout));
                return new DataResponse(['layout' => $layout]);
@@ -226,6 +232,7 @@ class DashboardApiController extends OCSController {
         *
         * 200: Statuses returned
         */
+       #[ApiRoute(verb: 'GET', url: '/api/v3/statuses')]
        public function getStatuses(): DataResponse {
                return new DataResponse(['statuses' => $this->service->getStatuses()]);
        }
@@ -239,6 +246,7 @@ class DashboardApiController extends OCSController {
         *
         * 200: Statuses updated successfully
         */
+       #[ApiRoute(verb: 'POST', url: '/api/v3/statuses')]
        public function updateStatuses(array $statuses): DataResponse {
                $this->config->setUserValue($this->userId, 'dashboard', 'statuses', implode(',', $statuses));
                return new DataResponse(['statuses' => $statuses]);
index 8375858cbee1cb1d2dd1c15c18faa50bc34800d8..f07fd4938d31a2b49bbc3b0986d1eb31c3aca382 100644 (file)
@@ -33,6 +33,7 @@ namespace OCA\Dashboard\Controller;
 use OCA\Dashboard\Service\DashboardService;
 use OCP\AppFramework\Controller;
 use OCP\AppFramework\Http;
+use OCP\AppFramework\Http\Attribute\FrontpageRoute;
 use OCP\AppFramework\Http\Attribute\OpenAPI;
 use OCP\AppFramework\Http\TemplateResponse;
 use OCP\AppFramework\Services\IInitialState;
@@ -65,6 +66,7 @@ class DashboardController extends Controller {
         * @NoAdminRequired
         * @return TemplateResponse
         */
+       #[FrontpageRoute(verb: 'GET', url: '/')]
        public function index(): TemplateResponse {
                \OCP\Util::addStyle('dashboard', 'dashboard');
                \OCP\Util::addScript('dashboard', 'main', 'theming');
index 7c537b4604cabdd4dcee9907db80d37fd6331f9a..c317611ab27bb81c7e1be4a74300a255bfe66f45 100644 (file)
         }
     },
     "paths": {
-        "/ocs/v2.php/apps/dashboard/api/v1/widgets": {
+        "/ocs/v2.php/apps/dashboard/api/v1/widget-items": {
             "get": {
-                "operationId": "dashboard_api-get-widgets",
-                "summary": "Get the widgets",
+                "operationId": "dashboard_api-get-widget-items",
+                "summary": "Get the items for the widgets",
                 "tags": [
                     "dashboard_api"
                 ],
                     }
                 ],
                 "parameters": [
+                    {
+                        "name": "sinceIds",
+                        "in": "query",
+                        "description": "Array indexed by widget Ids, contains date/id from which we want the new items",
+                        "schema": {
+                            "type": "string"
+                        }
+                    },
+                    {
+                        "name": "limit",
+                        "in": "query",
+                        "description": "Limit number of result items per widget",
+                        "schema": {
+                            "type": "integer",
+                            "format": "int64",
+                            "default": 7,
+                            "minimum": 1,
+                            "maximum": 30
+                        }
+                    },
+                    {
+                        "name": "widgets[]",
+                        "in": "query",
+                        "description": "Limit results to specific widgets",
+                        "schema": {
+                            "type": "array",
+                            "default": [],
+                            "items": {
+                                "type": "string"
+                            }
+                        }
+                    },
                     {
                         "name": "OCS-APIRequest",
                         "in": "header",
                 ],
                 "responses": {
                     "200": {
-                        "description": "Widgets returned",
+                        "description": "Widget items returned",
                         "content": {
                             "application/json": {
                                 "schema": {
                                                 "data": {
                                                     "type": "object",
                                                     "additionalProperties": {
-                                                        "$ref": "#/components/schemas/Widget"
+                                                        "type": "array",
+                                                        "items": {
+                                                            "$ref": "#/components/schemas/WidgetItem"
+                                                        }
                                                     }
                                                 }
                                             }
                 }
             }
         },
-        "/ocs/v2.php/apps/dashboard/api/v1/widget-items": {
+        "/ocs/v2.php/apps/dashboard/api/v2/widget-items": {
             "get": {
-                "operationId": "dashboard_api-get-widget-items",
+                "operationId": "dashboard_api-get-widget-items-v2",
                 "summary": "Get the items for the widgets",
                 "tags": [
                     "dashboard_api"
                     {
                         "name": "limit",
                         "in": "query",
-                        "description": "Limit number of result items per widget",
+                        "description": "Limit number of result items per widget, not more than 30 are allowed",
                         "schema": {
                             "type": "integer",
                             "format": "int64",
                                                 "data": {
                                                     "type": "object",
                                                     "additionalProperties": {
-                                                        "type": "array",
-                                                        "items": {
-                                                            "$ref": "#/components/schemas/WidgetItem"
-                                                        }
+                                                        "$ref": "#/components/schemas/WidgetItems"
                                                     }
                                                 }
                                             }
                 }
             }
         },
-        "/ocs/v2.php/apps/dashboard/api/v2/widget-items": {
+        "/ocs/v2.php/apps/dashboard/api/v1/widgets": {
             "get": {
-                "operationId": "dashboard_api-get-widget-items-v2",
-                "summary": "Get the items for the widgets",
+                "operationId": "dashboard_api-get-widgets",
+                "summary": "Get the widgets",
                 "tags": [
                     "dashboard_api"
                 ],
                     }
                 ],
                 "parameters": [
-                    {
-                        "name": "sinceIds",
-                        "in": "query",
-                        "description": "Array indexed by widget Ids, contains date/id from which we want the new items",
-                        "schema": {
-                            "type": "string"
-                        }
-                    },
-                    {
-                        "name": "limit",
-                        "in": "query",
-                        "description": "Limit number of result items per widget, not more than 30 are allowed",
-                        "schema": {
-                            "type": "integer",
-                            "format": "int64",
-                            "default": 7,
-                            "minimum": 1,
-                            "maximum": 30
-                        }
-                    },
-                    {
-                        "name": "widgets[]",
-                        "in": "query",
-                        "description": "Limit results to specific widgets",
-                        "schema": {
-                            "type": "array",
-                            "default": [],
-                            "items": {
-                                "type": "string"
-                            }
-                        }
-                    },
                     {
                         "name": "OCS-APIRequest",
                         "in": "header",
                 ],
                 "responses": {
                     "200": {
-                        "description": "Widget items returned",
+                        "description": "Widgets returned",
                         "content": {
                             "application/json": {
                                 "schema": {
                                                 "data": {
                                                     "type": "object",
                                                     "additionalProperties": {
-                                                        "$ref": "#/components/schemas/WidgetItems"
+                                                        "$ref": "#/components/schemas/Widget"
                                                     }
                                                 }
                                             }