From 7ebc6a5de994cace14d795120e32c49603c43152 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Fri, 7 Aug 2020 07:39:10 +0300 Subject: [PATCH] Updated response models --- app/controllers/api/functions.php | 2 +- src/Appwrite/Utopia/Response.php | 10 ++ .../Utopia/Response/Model/ExecutionList.php | 41 +++++++ src/Appwrite/Utopia/Response/Model/File.php | 9 +- .../Utopia/Response/Model/FileList.php | 2 +- .../Utopia/Response/Model/Functionx.php | 106 ++++++++++++++++++ .../Utopia/Response/Model/FunctionxList.php | 41 +++++++ .../Utopia/Response/Model/MembershipList.php | 2 +- .../Utopia/Response/Model/TagList.php | 41 +++++++ .../Utopia/Response/Model/TeamList.php | 2 +- src/Appwrite/Utopia/Response/Model/User.php | 5 +- 11 files changed, 246 insertions(+), 15 deletions(-) create mode 100644 src/Appwrite/Utopia/Response/Model/ExecutionList.php create mode 100644 src/Appwrite/Utopia/Response/Model/Functionx.php create mode 100644 src/Appwrite/Utopia/Response/Model/FunctionxList.php create mode 100644 src/Appwrite/Utopia/Response/Model/TagList.php diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 5e1d6cdc3a..efcc2162a5 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -43,7 +43,7 @@ App::post('/v1/functions') ], 'dateCreated' => time(), 'dateUpdated' => time(), - 'status' => 'paused', + 'status' => 'disabled', 'name' => $name, 'env' => $env, 'tag' => '', diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index a2ae3c890b..53065df939 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -9,6 +9,7 @@ use Appwrite\Utopia\Response\Model\Error; use Appwrite\Utopia\Response\Model\ErrorDev; use Appwrite\Utopia\Response\Model\File; use Appwrite\Utopia\Response\Model\FileList; +use Appwrite\Utopia\Response\Model\Functionx; use Appwrite\Utopia\Response\Model\User; use Appwrite\Utopia\Response\Model\Session; use Appwrite\Utopia\Response\Model\Team; @@ -54,6 +55,14 @@ class Response extends UtopiaResponse const MODEL_MEMBERSHIP = 'membership'; const MODEL_MEMBERSHIP_LIST = 'membershipList'; + // Functions + const MODEL_FUNCTION = 'function'; + const MODEL_FUNCTION_LIST = 'functionList'; + const MODEL_TAG = 'tag'; + const MODEL_TAG_LIST = 'tagList'; + const MODEL_EXECUTION = 'execution'; + const MODEL_EXECUTION_LIST = 'executionList'; + /** * Response constructor. */ @@ -71,6 +80,7 @@ class Response extends UtopiaResponse ->setModel(new TeamList()) ->setModel(new Membership()) ->setModel(new MembershipList()) + ->setModel(new Functionx()) ; parent::__construct($time); diff --git a/src/Appwrite/Utopia/Response/Model/ExecutionList.php b/src/Appwrite/Utopia/Response/Model/ExecutionList.php new file mode 100644 index 0000000000..a36dab6505 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/ExecutionList.php @@ -0,0 +1,41 @@ +addRule('executions', [ + 'type' => Response::MODEL_EXECUTION, + 'description' => 'List of function execitions.', + 'example' => [], + 'array' => true, + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Executions List'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_EXECUTION_LIST; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/File.php b/src/Appwrite/Utopia/Response/Model/File.php index a1583eaf23..416a02ac53 100644 --- a/src/Appwrite/Utopia/Response/Model/File.php +++ b/src/Appwrite/Utopia/Response/Model/File.php @@ -9,7 +9,6 @@ class File extends Model { public function __construct() { - //return $value->getArrayCopy(['$id', '$permissions', 'name', 'dateCreated', 'signature', 'mimeType', 'sizeOriginal']); $this ->addRule('$id', [ 'type' => 'string', @@ -19,13 +18,12 @@ class File extends Model ->addRule('$permissions', [ 'type' => Response::MODEL_PERMISSIONS, 'description' => 'File permissions.', - 'example' => [], + 'example' => new \stdClass, 'array' => false, ]) ->addRule('name', [ 'type' => 'string', 'description' => 'File name.', - 'default' => '', 'example' => 'Pink.png', ]) ->addRule('dateCreated', [ @@ -36,20 +34,17 @@ class File extends Model ->addRule('signature', [ 'type' => 'string', 'description' => 'File MD5 signature.', - 'default' => false, 'example' => '5d529fd02b544198ae075bd57c1762bb', ]) ->addRule('mimeType', [ 'type' => 'string', 'description' => 'File mime type.', - 'default' => '', 'example' => 'image/png', ]) ->addRule('sizeOriginal', [ 'type' => 'integer', 'description' => 'File original size in bytes.', - 'default' => false, - 'example' => true, + 'example' => 17890, ]) ; } diff --git a/src/Appwrite/Utopia/Response/Model/FileList.php b/src/Appwrite/Utopia/Response/Model/FileList.php index a5437fce22..731ca31628 100644 --- a/src/Appwrite/Utopia/Response/Model/FileList.php +++ b/src/Appwrite/Utopia/Response/Model/FileList.php @@ -26,7 +26,7 @@ class FileList extends BaseList */ public function getName():string { - return 'File List'; + return 'Files List'; } /** diff --git a/src/Appwrite/Utopia/Response/Model/Functionx.php b/src/Appwrite/Utopia/Response/Model/Functionx.php new file mode 100644 index 0000000000..01e9de4e49 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Functionx.php @@ -0,0 +1,106 @@ +addRule('$id', [ + 'type' => 'string', + 'description' => 'Function ID.', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('name', [ + 'type' => 'string', + 'description' => 'Function name.', + 'example' => 'My Function', + ]) + ->addRule('dateCreated', [ + 'type' => 'integer', + 'description' => 'Function creation date in Unix timestamp.', + 'example' => 1592981250, + ]) + ->addRule('dateUpdated', [ + 'type' => 'integer', + 'description' => 'Function update date in Unix timestamp.', + 'example' => 1592981257, + ]) + ->addRule('status', [ + 'type' => 'string', + 'description' => 'Function status. Possible values: disabled, enabled', + 'example' => 'enabled', + ]) + ->addRule('env', [ + 'type' => 'string', + 'description' => 'Function execution environment.', + 'example' => 'python-3.8', + ]) + ->addRule('tag', [ + 'type' => 'string', + 'description' => 'Function active tag ID.', + 'default' => '', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('vars', [ + 'type' => 'json', + 'description' => 'Function environment variables.', + 'default' => new \stdClass, + 'example' => ['key' => 'value'], + ]) + ->addRule('events', [ + 'type' => 'string', + 'description' => 'Function trigger events.', + 'default' => '', + 'example' => 'account.create', + 'array' => true, + ]) + ->addRule('schedule', [ + 'type' => 'string', + 'description' => 'Function execution schedult in CRON format.', + 'default' => '', + 'example' => '5 4 * * *', + ]) + ->addRule('next', [ + 'type' => 'integer', + 'description' => 'Function next scheduled execution date in Unix timestamp.', + 'example' => 1592981292, + ]) + ->addRule('previous', [ + 'type' => 'integer', + 'description' => 'Function next scheduled execution date in Unix timestamp.', + 'example' => 1592981237, + ]) + ->addRule('timeout', [ + 'type' => 'integer', + 'description' => 'Function execution timeout in seconds.', + 'default' => 15, + 'example' => 1592981237, + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Function'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_FUNCTION; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/FunctionxList.php b/src/Appwrite/Utopia/Response/Model/FunctionxList.php new file mode 100644 index 0000000000..237353ee48 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/FunctionxList.php @@ -0,0 +1,41 @@ +addRule('functions', [ + 'type' => Response::MODEL_MEMBERSHIP, + 'description' => 'List of functions.', + 'example' => [], + 'array' => true, + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Functions List'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_FUNCTION_LIST; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/MembershipList.php b/src/Appwrite/Utopia/Response/Model/MembershipList.php index 56937c8d33..2b9934acf4 100644 --- a/src/Appwrite/Utopia/Response/Model/MembershipList.php +++ b/src/Appwrite/Utopia/Response/Model/MembershipList.php @@ -26,7 +26,7 @@ class MembershipList extends BaseList */ public function getName():string { - return 'Membership List'; + return 'Memberships List'; } /** diff --git a/src/Appwrite/Utopia/Response/Model/TagList.php b/src/Appwrite/Utopia/Response/Model/TagList.php new file mode 100644 index 0000000000..838452bef9 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/TagList.php @@ -0,0 +1,41 @@ +addRule('tags', [ + 'type' => Response::MODEL_TAG, + 'description' => 'List of tags.', + 'example' => [], + 'array' => true, + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Tags List'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_TAG_LIST; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/TeamList.php b/src/Appwrite/Utopia/Response/Model/TeamList.php index c96e4cd0d4..b5d35bc0a6 100644 --- a/src/Appwrite/Utopia/Response/Model/TeamList.php +++ b/src/Appwrite/Utopia/Response/Model/TeamList.php @@ -26,7 +26,7 @@ class TeamList extends BaseList */ public function getName():string { - return 'Team List'; + return 'Teams List'; } /** diff --git a/src/Appwrite/Utopia/Response/Model/User.php b/src/Appwrite/Utopia/Response/Model/User.php index a1a0b1edcf..25b50cfa20 100644 --- a/src/Appwrite/Utopia/Response/Model/User.php +++ b/src/Appwrite/Utopia/Response/Model/User.php @@ -18,7 +18,6 @@ class User extends Model ->addRule('name', [ 'type' => 'string', 'description' => 'User name.', - 'default' => '', 'example' => 'John Doe', ]) ->addRule('registration', [ @@ -29,13 +28,11 @@ class User extends Model ->addRule('status', [ 'type' => 'integer', 'description' => 'User status. 0 for Unavtivated, 1 for active and 2 is blocked.', - 'default' => false, - 'example' => true, + 'example' => 0, ]) ->addRule('email', [ 'type' => 'string', 'description' => 'User email address.', - 'default' => '', 'example' => 'john@appwrite.io', ]) ->addRule('emailVerification', [