diff --git a/apps/user_status/appinfo/routes.php b/apps/user_status/appinfo/routes.php deleted file mode 100644 index fe534098a58..00000000000 --- a/apps/user_status/appinfo/routes.php +++ /dev/null @@ -1,43 +0,0 @@ - - * - * @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 . - * - */ -return [ - 'ocs' => [ - // Routes for querying statuses - ['name' => 'Statuses#findAll', 'url' => '/api/v1/statuses', 'verb' => 'GET'], - ['name' => 'Statuses#find', 'url' => '/api/v1/statuses/{userId}', 'verb' => 'GET'], - // Routes for manipulating your own status - ['name' => 'UserStatus#getStatus', 'url' => '/api/v1/user_status', 'verb' => 'GET'], - ['name' => 'UserStatus#setStatus', 'url' => '/api/v1/user_status/status', 'verb' => 'PUT'], - ['name' => 'UserStatus#setPredefinedMessage', 'url' => '/api/v1/user_status/message/predefined', 'verb' => 'PUT'], - ['name' => 'UserStatus#setCustomMessage', 'url' => '/api/v1/user_status/message/custom', 'verb' => 'PUT'], - ['name' => 'UserStatus#clearMessage', 'url' => '/api/v1/user_status/message', 'verb' => 'DELETE'], - ['name' => 'UserStatus#revertStatus', 'url' => '/api/v1/user_status/revert/{messageId}', 'verb' => 'DELETE'], - // Routes for listing default routes - ['name' => 'PredefinedStatus#findAll', 'url' => '/api/v1/predefined_statuses/', 'verb' => 'GET'], - // Route for doing heartbeats - ['name' => 'Heartbeat#heartbeat', 'url' => '/api/v1/heartbeat', 'verb' => 'PUT'], - ], -]; diff --git a/apps/user_status/lib/Controller/HeartbeatController.php b/apps/user_status/lib/Controller/HeartbeatController.php index 79e12902495..f78dfe716e9 100644 --- a/apps/user_status/lib/Controller/HeartbeatController.php +++ b/apps/user_status/lib/Controller/HeartbeatController.php @@ -30,6 +30,7 @@ use OCA\UserStatus\Db\UserStatus; use OCA\UserStatus\ResponseDefinitions; use OCA\UserStatus\Service\StatusService; use OCP\AppFramework\Http; +use OCP\AppFramework\Http\Attribute\ApiRoute; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCSController; use OCP\AppFramework\Utility\ITimeFactory; @@ -81,6 +82,7 @@ class HeartbeatController extends OCSController { * 204: User has no status to keep alive * 400: Invalid status to update */ + #[ApiRoute(verb: 'PUT', url: '/api/v1/heartbeat')] public function heartbeat(string $status): DataResponse { if (!\in_array($status, [IUserStatus::ONLINE, IUserStatus::AWAY], true)) { return new DataResponse([], Http::STATUS_BAD_REQUEST); diff --git a/apps/user_status/lib/Controller/PredefinedStatusController.php b/apps/user_status/lib/Controller/PredefinedStatusController.php index 99acdca9f79..74952fd1247 100644 --- a/apps/user_status/lib/Controller/PredefinedStatusController.php +++ b/apps/user_status/lib/Controller/PredefinedStatusController.php @@ -29,6 +29,7 @@ namespace OCA\UserStatus\Controller; use OCA\UserStatus\ResponseDefinitions; use OCA\UserStatus\Service\PredefinedStatusService; use OCP\AppFramework\Http; +use OCP\AppFramework\Http\Attribute\ApiRoute; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCSController; use OCP\IRequest; @@ -66,6 +67,7 @@ class PredefinedStatusController extends OCSController { * * 200: Predefined statuses returned */ + #[ApiRoute(verb: 'GET', url: '/api/v1/predefined_statuses/')] public function findAll():DataResponse { // Filtering out the invisible one, that should only be set by API return new DataResponse(array_filter($this->predefinedStatusService->getDefaultStatuses(), function (array $status) { diff --git a/apps/user_status/lib/Controller/StatusesController.php b/apps/user_status/lib/Controller/StatusesController.php index b506a691a61..b2539af8689 100644 --- a/apps/user_status/lib/Controller/StatusesController.php +++ b/apps/user_status/lib/Controller/StatusesController.php @@ -32,6 +32,7 @@ use OCA\UserStatus\ResponseDefinitions; use OCA\UserStatus\Service\StatusService; use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Http; +use OCP\AppFramework\Http\Attribute\ApiRoute; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCS\OCSNotFoundException; use OCP\AppFramework\OCSController; @@ -72,6 +73,7 @@ class StatusesController extends OCSController { * * 200: Statuses returned */ + #[ApiRoute(verb: 'GET', url: '/api/v1/statuses')] public function findAll(?int $limit = null, ?int $offset = null): DataResponse { $allStatuses = $this->service->findAll($limit, $offset); @@ -91,6 +93,7 @@ class StatusesController extends OCSController { * * 200: Status returned */ + #[ApiRoute(verb: 'GET', url: '/api/v1/statuses/{userId}')] public function find(string $userId): DataResponse { try { $userStatus = $this->service->findByUserId($userId); diff --git a/apps/user_status/lib/Controller/UserStatusController.php b/apps/user_status/lib/Controller/UserStatusController.php index d06370a19ea..736c4e772ca 100644 --- a/apps/user_status/lib/Controller/UserStatusController.php +++ b/apps/user_status/lib/Controller/UserStatusController.php @@ -39,6 +39,7 @@ use OCA\UserStatus\ResponseDefinitions; use OCA\UserStatus\Service\StatusService; use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Http; +use OCP\AppFramework\Http\Attribute\ApiRoute; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCS\OCSBadRequestException; use OCP\AppFramework\OCS\OCSNotFoundException; @@ -72,6 +73,7 @@ class UserStatusController extends OCSController { * * 200: The status was found successfully */ + #[ApiRoute(verb: 'GET', url: '/api/v1/user_status')] public function getStatus(): DataResponse { try { $this->calendarStatusService->processCalendarStatus($this->userId); @@ -94,6 +96,7 @@ class UserStatusController extends OCSController { * * 200: The status was updated successfully */ + #[ApiRoute(verb: 'PUT', url: '/api/v1/user_status/status')] public function setStatus(string $statusType): DataResponse { try { $status = $this->service->setStatus($this->userId, $statusType, null, true); @@ -118,6 +121,7 @@ class UserStatusController extends OCSController { * * 200: The message was updated successfully */ + #[ApiRoute(verb: 'PUT', url: '/api/v1/user_status/message/predefined')] public function setPredefinedMessage(string $messageId, ?int $clearAt): DataResponse { try { @@ -146,6 +150,7 @@ class UserStatusController extends OCSController { * * 200: The message was updated successfully */ + #[ApiRoute(verb: 'PUT', url: '/api/v1/user_status/message/custom')] public function setCustomMessage(?string $statusIcon, ?string $message, ?int $clearAt): DataResponse { @@ -179,6 +184,7 @@ class UserStatusController extends OCSController { * * 200: Message cleared successfully */ + #[ApiRoute(verb: 'DELETE', url: '/api/v1/user_status/message')] public function clearMessage(): DataResponse { $this->service->clearMessage($this->userId); return new DataResponse([]); @@ -195,6 +201,7 @@ class UserStatusController extends OCSController { * * 200: Status reverted */ + #[ApiRoute(verb: 'DELETE', url: '/api/v1/user_status/revert/{messageId}')] public function revertStatus(string $messageId): DataResponse { $backupStatus = $this->service->revertUserStatus($this->userId, $messageId, true); if ($backupStatus) { diff --git a/apps/user_status/openapi.json b/apps/user_status/openapi.json index 2d76f8760ee..009973bc195 100644 --- a/apps/user_status/openapi.json +++ b/apps/user_status/openapi.json @@ -206,6 +206,224 @@ } }, "paths": { + "/ocs/v2.php/apps/user_status/api/v1/heartbeat": { + "put": { + "operationId": "heartbeat-heartbeat", + "summary": "Keep the status alive", + "tags": [ + "heartbeat" + ], + "security": [ + { + "bearer_auth": [] + }, + { + "basic_auth": [] + } + ], + "parameters": [ + { + "name": "status", + "in": "query", + "description": "Only online, away", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "OCS-APIRequest", + "in": "header", + "description": "Required to be true for the API request to pass", + "required": true, + "schema": { + "type": "boolean", + "default": true + } + } + ], + "responses": { + "200": { + "description": "Status successfully updated", + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "ocs" + ], + "properties": { + "ocs": { + "type": "object", + "required": [ + "meta", + "data" + ], + "properties": { + "meta": { + "$ref": "#/components/schemas/OCSMeta" + }, + "data": { + "$ref": "#/components/schemas/Private" + } + } + } + } + } + } + } + }, + "400": { + "description": "Invalid status to update", + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "ocs" + ], + "properties": { + "ocs": { + "type": "object", + "required": [ + "meta", + "data" + ], + "properties": { + "meta": { + "$ref": "#/components/schemas/OCSMeta" + }, + "data": {} + } + } + } + } + } + } + }, + "500": { + "description": "", + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "ocs" + ], + "properties": { + "ocs": { + "type": "object", + "required": [ + "meta", + "data" + ], + "properties": { + "meta": { + "$ref": "#/components/schemas/OCSMeta" + }, + "data": {} + } + } + } + } + } + } + }, + "204": { + "description": "User has no status to keep alive", + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "ocs" + ], + "properties": { + "ocs": { + "type": "object", + "required": [ + "meta", + "data" + ], + "properties": { + "meta": { + "$ref": "#/components/schemas/OCSMeta" + }, + "data": {} + } + } + } + } + } + } + } + } + } + }, + "/ocs/v2.php/apps/user_status/api/v1/predefined_statuses": { + "get": { + "operationId": "predefined_status-find-all", + "summary": "Get all predefined messages", + "tags": [ + "predefined_status" + ], + "security": [ + { + "bearer_auth": [] + }, + { + "basic_auth": [] + } + ], + "parameters": [ + { + "name": "OCS-APIRequest", + "in": "header", + "description": "Required to be true for the API request to pass", + "required": true, + "schema": { + "type": "boolean", + "default": true + } + } + ], + "responses": { + "200": { + "description": "Predefined statuses returned", + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "ocs" + ], + "properties": { + "ocs": { + "type": "object", + "required": [ + "meta", + "data" + ], + "properties": { + "meta": { + "$ref": "#/components/schemas/OCSMeta" + }, + "data": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Predefined" + } + } + } + } + } + } + } + } + } + } + } + }, "/ocs/v2.php/apps/user_status/api/v1/statuses": { "get": { "operationId": "statuses-find-all", @@ -846,224 +1064,6 @@ } } } - }, - "/ocs/v2.php/apps/user_status/api/v1/predefined_statuses": { - "get": { - "operationId": "predefined_status-find-all", - "summary": "Get all predefined messages", - "tags": [ - "predefined_status" - ], - "security": [ - { - "bearer_auth": [] - }, - { - "basic_auth": [] - } - ], - "parameters": [ - { - "name": "OCS-APIRequest", - "in": "header", - "description": "Required to be true for the API request to pass", - "required": true, - "schema": { - "type": "boolean", - "default": true - } - } - ], - "responses": { - "200": { - "description": "Predefined statuses returned", - "content": { - "application/json": { - "schema": { - "type": "object", - "required": [ - "ocs" - ], - "properties": { - "ocs": { - "type": "object", - "required": [ - "meta", - "data" - ], - "properties": { - "meta": { - "$ref": "#/components/schemas/OCSMeta" - }, - "data": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Predefined" - } - } - } - } - } - } - } - } - } - } - } - }, - "/ocs/v2.php/apps/user_status/api/v1/heartbeat": { - "put": { - "operationId": "heartbeat-heartbeat", - "summary": "Keep the status alive", - "tags": [ - "heartbeat" - ], - "security": [ - { - "bearer_auth": [] - }, - { - "basic_auth": [] - } - ], - "parameters": [ - { - "name": "status", - "in": "query", - "description": "Only online, away", - "required": true, - "schema": { - "type": "string" - } - }, - { - "name": "OCS-APIRequest", - "in": "header", - "description": "Required to be true for the API request to pass", - "required": true, - "schema": { - "type": "boolean", - "default": true - } - } - ], - "responses": { - "200": { - "description": "Status successfully updated", - "content": { - "application/json": { - "schema": { - "type": "object", - "required": [ - "ocs" - ], - "properties": { - "ocs": { - "type": "object", - "required": [ - "meta", - "data" - ], - "properties": { - "meta": { - "$ref": "#/components/schemas/OCSMeta" - }, - "data": { - "$ref": "#/components/schemas/Private" - } - } - } - } - } - } - } - }, - "400": { - "description": "Invalid status to update", - "content": { - "application/json": { - "schema": { - "type": "object", - "required": [ - "ocs" - ], - "properties": { - "ocs": { - "type": "object", - "required": [ - "meta", - "data" - ], - "properties": { - "meta": { - "$ref": "#/components/schemas/OCSMeta" - }, - "data": {} - } - } - } - } - } - } - }, - "500": { - "description": "", - "content": { - "application/json": { - "schema": { - "type": "object", - "required": [ - "ocs" - ], - "properties": { - "ocs": { - "type": "object", - "required": [ - "meta", - "data" - ], - "properties": { - "meta": { - "$ref": "#/components/schemas/OCSMeta" - }, - "data": {} - } - } - } - } - } - } - }, - "204": { - "description": "User has no status to keep alive", - "content": { - "application/json": { - "schema": { - "type": "object", - "required": [ - "ocs" - ], - "properties": { - "ocs": { - "type": "object", - "required": [ - "meta", - "data" - ], - "properties": { - "meta": { - "$ref": "#/components/schemas/OCSMeta" - }, - "data": {} - } - } - } - } - } - } - } - } - } } }, "tags": []