From 3e70a19e4fd716b1818f2bd9940a975f199085e4 Mon Sep 17 00:00:00 2001 From: prateek banga Date: Mon, 7 Aug 2023 20:56:03 +0530 Subject: [PATCH] add response models required for messaging service --- src/Appwrite/Utopia/Response.php | 26 +++++ .../Utopia/Response/Model/Message.php | 97 +++++++++++++++++++ .../Utopia/Response/Model/Provider.php | 63 ++++++++++++ .../Utopia/Response/Model/Subsciber.php | 63 ++++++++++++ src/Appwrite/Utopia/Response/Model/Target.php | 70 +++++++++++++ src/Appwrite/Utopia/Response/Model/Topic.php | 64 ++++++++++++ 6 files changed, 383 insertions(+) create mode 100644 src/Appwrite/Utopia/Response/Model/Message.php create mode 100644 src/Appwrite/Utopia/Response/Model/Provider.php create mode 100644 src/Appwrite/Utopia/Response/Model/Subsciber.php create mode 100644 src/Appwrite/Utopia/Response/Model/Target.php create mode 100644 src/Appwrite/Utopia/Response/Model/Topic.php diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index 902d50b0c7..37e6d7682b 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -2,6 +2,9 @@ namespace Appwrite\Utopia; +use Appwrite\Utopia\Response\Model\Message; +use Appwrite\Utopia\Response\Model\Subscriber; +use Appwrite\Utopia\Response\Model\Topic; use Exception; use Swoole\Http\Request as SwooleRequest; use Utopia\Swoole\Response as SwooleResponse; @@ -78,6 +81,7 @@ use Appwrite\Utopia\Response\Model\LocaleCode; use Appwrite\Utopia\Response\Model\Mock; // Keep last use Appwrite\Utopia\Response\Model\Provider; use Appwrite\Utopia\Response\Model\Runtime; +use Appwrite\Utopia\Response\Model\Target; use Appwrite\Utopia\Response\Model\TemplateSMS; use Appwrite\Utopia\Response\Model\UsageBuckets; use Appwrite\Utopia\Response\Model\UsageCollection; @@ -180,6 +184,18 @@ class Response extends SwooleResponse public const MODEL_PHONE = 'phone'; public const MODEL_PHONE_LIST = 'phoneList'; + // Messaging + public const MODEL_PROVIDER = 'provider'; + public const MODEL_PROVIDER_LIST = 'providerList'; + public const MODEL_MESSAGE = 'message'; + public const MODEL_MESSAGE_LIST = 'messageList'; + public const MODEL_TOPIC = 'topic'; + public const MODEL_TOPIC_LIST = 'topicList'; + public const MODEL_SUBSCRIBER = 'subscriber'; + public const MODEL_SUBSCRIBER_LIST = 'subscriberList'; + public const MODEL_TARGET = 'target'; + public const MODEL_TARGET_LIST = 'targetList'; + // Teams public const MODEL_TEAM = 'team'; public const MODEL_TEAM_LIST = 'teamList'; @@ -289,6 +305,11 @@ class Response extends SwooleResponse ->setModel(new BaseList('Metric List', self::MODEL_METRIC_LIST, 'metrics', self::MODEL_METRIC, true, false)) ->setModel(new BaseList('Variables List', self::MODEL_VARIABLE_LIST, 'variables', self::MODEL_VARIABLE)) ->setModel(new BaseList('Locale codes list', self::MODEL_LOCALE_CODE_LIST, 'localeCodes', self::MODEL_LOCALE_CODE)) + ->setModel(new BaseList('Provider list', self::MODEL_PROVIDER_LIST, 'providers', self::MODEL_PROVIDER)) + ->setModel(new BaseList('Message list', self::MODEL_MESSAGE_LIST, 'messages', self::MODEL_MESSAGE)) + ->setModel(new BaseList('Topic list', self::MODEL_TOPIC_LIST, 'topics', self::MODEL_TOPIC)) + ->setModel(new BaseList('Subscriber list', self::MODEL_SUBSCRIBER_LIST, 'subscribers', self::MODEL_SUBSCRIBER)) + ->setModel(new BaseList('Target list', self::MODEL_TARGET_LIST, 'targets', self::MODEL_TARGET)) // Entities ->setModel(new Database()) ->setModel(new Collection()) @@ -361,6 +382,11 @@ class Response extends SwooleResponse ->setModel(new TemplateSMS()) ->setModel(new TemplateEmail()) ->setModel(new ConsoleVariables()) + ->setModel(new Provider()) + ->setModel(new Message()) + ->setModel(new Topic()) + ->setModel(new Subscriber()) + ->setModel(new Target()) // Verification // Recovery // Tests (keep last) diff --git a/src/Appwrite/Utopia/Response/Model/Message.php b/src/Appwrite/Utopia/Response/Model/Message.php new file mode 100644 index 0000000000..f8a7913ff6 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Message.php @@ -0,0 +1,97 @@ +addRule('$id', [ + 'type' => self::TYPE_STRING, + 'description' => 'Message ID.', + 'default' => '', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('providerId', [ + 'type' => self::TYPE_STRING, + 'description' => 'Provider Id for the message.', + 'default' => '', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('data', [ + 'type' => self::TYPE_JSON, + 'description' => 'Message Data.', + 'default' => '', + 'required' => false, + 'example' => '', + ]) + ->addRule('to', [ + 'type' => self::TYPE_STRING, + 'description' => 'Recipient of message.', + 'default' => '', + 'example' => ['user-1'], + ]) + ->addRule('deliveryTime', [ + 'type' => self::TYPE_DATETIME, + 'description' => 'Recipient of message.', + 'required' => false, + 'default' => DateTime::now(), + 'example' => DateTime::now(), + ]) + ->addRule('deliveryError', [ + 'type' => self::TYPE_STRING, + 'description' => 'Delivery error if any.', + 'required' => false, + 'default' => '', + 'example' => 'Provider not valid.', + ]) + ->addRule('deliveredTo', [ + 'type' => self::TYPE_INTEGER, + 'description' => 'Number of recipients the message was delivered to.', + 'default' => '', + 'example' => 1, + ]) + ->addRule('delivered', [ + 'type' => self::TYPE_BOOLEAN, + 'description' => 'Status of delivery.', + 'default' => '', + 'example' => true, + ]) + ->addRule('search', [ + 'type' => self::TYPE_STRING, + 'description' => 'Field that can be used for searching message.', + 'default' => '', + 'example' => 'Hello everyone', + ]); + } + + /** + * Get Name + * + * @return string + */ + public function getName(): string + { + return 'Message'; + } + + /** + * Get Type + * + * @return string + */ + public function getType(): string + { + return Response::MODEL_MESSAGE; + } +} diff --git a/src/Appwrite/Utopia/Response/Model/Provider.php b/src/Appwrite/Utopia/Response/Model/Provider.php new file mode 100644 index 0000000000..6bd43261ad --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Provider.php @@ -0,0 +1,63 @@ +addRule('$id', [ + 'type' => self::TYPE_STRING, + 'description' => 'Provider ID.', + 'default' => '', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('name', [ + 'type' => self::TYPE_STRING, + 'description' => 'The user-given name for the provider instance.', + 'default' => '', + 'example' => 'Mailgun', + ]) + ->addRule('provider', [ + 'type' => self::TYPE_STRING, + 'description' => 'Provider name setup in Utopia.', + 'default' => '', + 'example' => 'mailgun', + ]) + ->addRule('type', [ + 'type' => self::TYPE_STRING, + 'description' => 'Type of provider.', + 'default' => '', + 'example' => 'sms', + ]); + } + + /** + * Get Name + * + * @return string + */ + public function getName(): string + { + return 'Provider'; + } + + /** + * Get Type + * + * @return string + */ + public function getType(): string + { + return Response::MODEL_PROVIDER; + } +} diff --git a/src/Appwrite/Utopia/Response/Model/Subsciber.php b/src/Appwrite/Utopia/Response/Model/Subsciber.php new file mode 100644 index 0000000000..a72146ccf3 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Subsciber.php @@ -0,0 +1,63 @@ +addRule('$id', [ + 'type' => self::TYPE_STRING, + 'description' => 'Subscriber ID.', + 'default' => '', + 'example' => '259125845563242502', + ]) + ->addRule('userId', [ + 'type' => self::TYPE_STRING, + 'description' => 'User ID.', + 'default' => '', + 'example' => '259125845563242502', + ]) + ->addRule('targetId', [ + 'type' => self::TYPE_STRING, + 'description' => 'Target ID.', + 'default' => '', + 'example' => '259125845563242502', + ]) + ->addRule('topicId', [ + 'type' => self::TYPE_STRING, + 'description' => 'Topic ID.', + 'default' => '', + 'example' => '259125845563242502', + ]); + } + + /** + * Get Name + * + * @return string + */ + public function getName(): string + { + return 'Subscriber'; + } + + /** + * Get Type + * + * @return string + */ + public function getType(): string + { + return Response::MODEL_SUBSCRIBER; + } +} diff --git a/src/Appwrite/Utopia/Response/Model/Target.php b/src/Appwrite/Utopia/Response/Model/Target.php new file mode 100644 index 0000000000..1ecc0126cc --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Target.php @@ -0,0 +1,70 @@ +addRule('$id', [ + 'type' => self::TYPE_STRING, + 'description' => 'Target ID.', + 'default' => '', + 'example' => '259125845563242502', + ]) + ->addRule('userId', [ + 'type' => self::TYPE_STRING, + 'description' => 'User ID.', + 'default' => '', + 'example' => '259125845563242502', + ]) + ->addRule('providerId', [ + 'type' => self::TYPE_STRING, + 'description' => 'Provider ID.', + 'required' => false, + 'default' => '', + 'example' => '259125845563242502', + ]) + ->addRule('providerType', [ + 'type' => self::TYPE_STRING, + 'description' => 'The type of provider supported by this target.', + 'default' => '', + 'example' => 'sms', + ]) + ->addRule('identifier', [ + 'type' => self::TYPE_STRING, + 'description' => 'The target identifier.', + 'default' => '', + 'example' => 'token', + ]); + } + + /** + * Get Name + * + * @return string + */ + public function getName(): string + { + return 'Target'; + } + + /** + * Get Type + * + * @return string + */ + public function getType(): string + { + return Response::MODEL_TARGET; + } +} diff --git a/src/Appwrite/Utopia/Response/Model/Topic.php b/src/Appwrite/Utopia/Response/Model/Topic.php new file mode 100644 index 0000000000..d22364f917 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Topic.php @@ -0,0 +1,64 @@ +addRule('$id', [ + 'type' => self::TYPE_STRING, + 'description' => 'Topic ID.', + 'default' => '', + 'example' => '259125845563242502', + ]) + ->addRule('providerId', [ + 'type' => self::TYPE_STRING, + 'description' => 'Provider ID.', + 'default' => '', + 'example' => '259125845563242502', + ]) + ->addRule('name', [ + 'type' => self::TYPE_STRING, + 'description' => 'The name of the topic.', + 'default' => '', + 'example' => 'events', + ]) + ->addRule('description', [ + 'type' => self::TYPE_STRING, + 'description' => 'Description of the topic.', + 'default' => '', + 'required' => false, + 'example' => 'All events related messages will be sent to this topic.', + ]); + } + + /** + * Get Name + * + * @return string + */ + public function getName(): string + { + return 'Topic'; + } + + /** + * Get Type + * + * @return string + */ + public function getType(): string + { + return Response::MODEL_TOPIC; + } +}