diff --git a/src/FederationServer/Classes/Enums/Method.php b/src/FederationServer/Classes/Enums/Method.php index ff46e6b..1cbca12 100644 --- a/src/FederationServer/Classes/Enums/Method.php +++ b/src/FederationServer/Classes/Enums/Method.php @@ -7,6 +7,7 @@ use FederationServer\Methods\DeleteOperator; use FederationServer\Methods\DownloadAttachment; use FederationServer\Methods\EnableOperator; + use FederationServer\Methods\GetOperator; use FederationServer\Methods\UploadAttachment; enum Method @@ -14,6 +15,7 @@ case CREATE_OPERATOR; case DELETE_OPERATOR; case ENABLE_OPERATOR; + case GET_OPERATOR; case UPLOAD_ATTACHMENT; case DOWNLOAD_ATTACHMENT; @@ -37,6 +39,9 @@ case self::ENABLE_OPERATOR: EnableOperator::handleRequest(); break; + case self::GET_OPERATOR: + GetOperator::handleRequest(); + break; case self::UPLOAD_ATTACHMENT: UploadAttachment::handleRequest(); @@ -65,6 +70,7 @@ $requestMethod === 'POST' && $path === '/operators/create' => Method::CREATE_OPERATOR, $requestMethod === 'DELETE' && $path === '/operators/delete' => Method::DELETE_OPERATOR, + $requestMethod === 'GET' && $path === '/operators/get' => Method::GET_OPERATOR, $requestMethod === 'POST' && $path === '/operators/enable' => Method::ENABLE_OPERATOR, default => null, diff --git a/src/FederationServer/Methods/GetOperator.php b/src/FederationServer/Methods/GetOperator.php new file mode 100644 index 0000000..4ad7614 --- /dev/null +++ b/src/FederationServer/Methods/GetOperator.php @@ -0,0 +1,51 @@ +canManageOperators()) + { + throw new RequestException('Unauthorized: Insufficient permissions to get operators', 403); + } + + if(!FederationServer::getParameter('uuid')) + { + throw new RequestException('Bad Request: Operator UUID is required', 400); + } + + try + { + $existingOperator = OperatorManager::getOperator(FederationServer::getParameter('uuid')); + if($existingOperator === null) + { + throw new RequestException('Operator Not Found', 404); + } + } + catch(DatabaseOperationException $e) + { + Logger::log()->error('Database error while getting operator: ' . $e->getMessage(), $e); + throw new RequestException('Internal Server Error: Unable to get operator', 500, $e); + } + + // Respond with the UUID of the newly created operator. + self::successResponse($existingOperator->toArray()); + } + } \ No newline at end of file