Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
refactor(dashboard): Use attributes for routing
Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin committed May 10, 2024
commit 395bf7c70d93ae445d664312e629b890265c29b7
41 changes: 0 additions & 41 deletions apps/dashboard/appinfo/routes.php

This file was deleted.

8 changes: 8 additions & 0 deletions apps/dashboard/lib/Controller/DashboardApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
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;
Expand Down Expand Up @@ -98,6 +99,7 @@ static function (IWidget $widget) use ($widgetIds) {
*
* 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);
Expand Down Expand Up @@ -126,6 +128,7 @@ public function getWidgetItems(array $sinceIds = [], int $limit = 7, array $widg
*
* 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);
Expand All @@ -150,6 +153,7 @@ public function getWidgetItemsV2(array $sinceIds = [], int $limit = 7, array $wi
*
* 200: Widgets returned
*/
#[ApiRoute(verb: 'GET', url: '/api/v1/widgets')]
public function getWidgets(): DataResponse {
$widgets = $this->dashboardManager->getWidgets();

Expand Down Expand Up @@ -200,6 +204,7 @@ public function getWidgets(): DataResponse {
*
* 200: Layout returned
*/
#[ApiRoute(verb: 'GET', url: '/api/v3/layout')]
public function getLayout(): DataResponse {
return new DataResponse(['layout' => $this->service->getLayout()]);
}
Expand All @@ -213,6 +218,7 @@ public function getLayout(): DataResponse {
*
* 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));

Check notice

Code scanning / Psalm

PossiblyNullArgument

Argument 1 of OCP\IConfig::setUserValue cannot be null, possibly null value provided
return new DataResponse(['layout' => $layout]);
Expand All @@ -226,6 +232,7 @@ public function updateLayout(array $layout): DataResponse {
*
* 200: Statuses returned
*/
#[ApiRoute(verb: 'GET', url: '/api/v3/statuses')]
public function getStatuses(): DataResponse {
return new DataResponse(['statuses' => $this->service->getStatuses()]);
}
Expand All @@ -239,6 +246,7 @@ public function getStatuses(): DataResponse {
*
* 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));

Check notice

Code scanning / Psalm

PossiblyNullArgument

Argument 1 of OCP\IConfig::setUserValue cannot be null, possibly null value provided
return new DataResponse(['statuses' => $statuses]);
Expand Down
2 changes: 2 additions & 0 deletions apps/dashboard/lib/Controller/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
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;
Expand Down Expand Up @@ -65,6 +66,7 @@ public function __construct(
* @NoAdminRequired
* @return TemplateResponse
*/
#[FrontpageRoute(verb: 'GET', url: '/')]
public function index(): TemplateResponse {
\OCP\Util::addStyle('dashboard', 'dashboard');
\OCP\Util::addScript('dashboard', 'main', 'theming');
Expand Down
98 changes: 49 additions & 49 deletions apps/dashboard/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@
}
},
"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"
],
Expand All @@ -188,6 +188,38 @@
}
],
"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",
Expand All @@ -201,7 +233,7 @@
],
"responses": {
"200": {
"description": "Widgets returned",
"description": "Widget items returned",
"content": {
"application/json": {
"schema": {
Expand All @@ -223,7 +255,10 @@
"data": {
"type": "object",
"additionalProperties": {
"$ref": "#/components/schemas/Widget"
"type": "array",
"items": {
"$ref": "#/components/schemas/WidgetItem"
}
}
}
}
Expand All @@ -236,9 +271,9 @@
}
}
},
"/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"
Expand All @@ -263,7 +298,7 @@
{
"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",
Expand Down Expand Up @@ -319,10 +354,7 @@
"data": {
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"$ref": "#/components/schemas/WidgetItem"
}
"$ref": "#/components/schemas/WidgetItems"
}
}
}
Expand All @@ -335,10 +367,10 @@
}
}
},
"/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"
],
Expand All @@ -351,38 +383,6 @@
}
],
"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",
Expand All @@ -396,7 +396,7 @@
],
"responses": {
"200": {
"description": "Widget items returned",
"description": "Widgets returned",
"content": {
"application/json": {
"schema": {
Expand All @@ -418,7 +418,7 @@
"data": {
"type": "object",
"additionalProperties": {
"$ref": "#/components/schemas/WidgetItems"
"$ref": "#/components/schemas/Widget"
}
}
}
Expand Down