From 94b7f67e44ec27a19b70a80cddfc6cd1a4a12033 Mon Sep 17 00:00:00 2001 From: prateek banga Date: Fri, 25 Aug 2023 04:43:40 +0530 Subject: [PATCH] changes id to providerId for provider create controllers --- app/controllers/api/messaging.php | 74 +++++++++---------- .../e2e/Services/Messaging/MessagingBase.php | 20 ++--- 2 files changed, 47 insertions(+), 47 deletions(-) diff --git a/app/controllers/api/messaging.php b/app/controllers/api/messaging.php index f391eef5ba..d86b8247b4 100644 --- a/app/controllers/api/messaging.php +++ b/app/controllers/api/messaging.php @@ -56,7 +56,7 @@ App::get('/v1/messaging/providers') $filterQueries = Query::groupByType($queries)['filters']; $response->dynamic(new Document([ 'total' => $dbForProject->count('providers', $filterQueries, APP_LIMIT_COUNT), - 'indexes' => $dbForProject->find('providers', $queries), + 'providers' => $dbForProject->find('providers', $queries), ]), Response::MODEL_PROVIDER_LIST); }); @@ -100,16 +100,16 @@ App::post('/v1/messaging/providers/mailgun') ->label('sdk.response.code', Response::STATUS_CODE_CREATED) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_PROVIDER) - ->param('id', '', new CustomId(), 'Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') + ->param('providerId', '', new CustomId(), 'Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') ->param('name', '', new Text(128), 'Provider name.') ->param('apiKey', '', new Text(0), 'Mailgun API Key.') ->param('domain', '', new Text(0), 'Mailgun Domain.') ->inject('dbForProject') ->inject('response') - ->action(function (string $id, string $name, string $apiKey, string $domain, Database $dbForProject, Response $response) { - $id = $id == 'unique()' ? ID::unique() : $id; + ->action(function (string $providerId, string $name, string $apiKey, string $domain, Database $dbForProject, Response $response) { + $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; $provider = $dbForProject->createDocument('providers', new Document([ - '$id' => $id, + '$id' => $providerId, 'name' => $name, 'provider' => 'mailgun', 'type' => 'email', @@ -191,15 +191,15 @@ App::post('/v1/messaging/providers/sendgrid') ->label('sdk.response.code', Response::STATUS_CODE_CREATED) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_PROVIDER) - ->param('id', '', new CustomId(), 'Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') + ->param('providerId', '', new CustomId(), 'Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') ->param('name', '', new Text(128), 'Provider name.') ->param('apiKey', '', new Text(0), 'Sendgrid API key.') ->inject('dbForProject') ->inject('response') - ->action(function (string $id, string $name, string $apiKey, Database $dbForProject, Response $response) { - $id = $id == 'unique()' ? ID::unique() : $id; + ->action(function (string $providerId, string $name, string $apiKey, Database $dbForProject, Response $response) { + $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; $provider = $dbForProject->createDocument('providers', new Document([ - '$id' => $id, + '$id' => $providerId, 'name' => $name, 'provider' => 'sendgrid', 'type' => 'email', @@ -275,16 +275,16 @@ App::post('/v1/messaging/providers/msg91') ->label('sdk.response.code', Response::STATUS_CODE_CREATED) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_PROVIDER) - ->param('id', '', new CustomId(), 'Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') + ->param('providerId', '', new CustomId(), 'Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') ->param('name', '', new Text(128), 'Provider name.') ->param('senderId', '', new Text(0), 'Msg91 Sender ID.') ->param('authKey', '', new Text(0), 'Msg91 Auth Key.') ->inject('dbForProject') ->inject('response') - ->action(function (string $id, string $name, string $senderId, string $authKey, Database $dbForProject, Response $response) { - $id = $id == 'unique()' ? ID::unique() : $id; + ->action(function (string $providerId, string $name, string $senderId, string $authKey, Database $dbForProject, Response $response) { + $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; $provider = $dbForProject->createDocument('providers', new Document([ - '$id' => $id, + '$id' => $providerId, 'name' => $name, 'provider' => 'msg91', 'type' => 'sms', @@ -366,16 +366,16 @@ App::post('/v1/messaging/providers/telesign') ->label('sdk.response.code', Response::STATUS_CODE_CREATED) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_PROVIDER) - ->param('id', '', new CustomId(), 'Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') + ->param('providerId', '', new CustomId(), 'Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') ->param('name', '', new Text(128), 'Provider name.') ->param('username', '', new Text(0), 'Telesign username.') ->param('password', '', new Text(0), 'Telesign password.') ->inject('dbForProject') ->inject('response') - ->action(function (string $id, string $name, string $username, string $password, Database $dbForProject, Response $response) { - $id = $id == 'unique()' ? ID::unique() : $id; + ->action(function (string $providerId, string $name, string $username, string $password, Database $dbForProject, Response $response) { + $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; $provider = $dbForProject->createDocument('providers', new Document([ - '$id' => $id, + '$id' => $providerId, 'name' => $name, 'provider' => 'telesign', 'type' => 'sms', @@ -457,16 +457,16 @@ App::post('/v1/messaging/providers/textmagic') ->label('sdk.response.code', Response::STATUS_CODE_CREATED) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_PROVIDER) - ->param('id', '', new CustomId(), 'Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') + ->param('providerId', '', new CustomId(), 'Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') ->param('name', '', new Text(128), 'Provider name.') ->param('username', '', new Text(0), 'Textmagic username.') ->param('apiKey', '', new Text(0), 'Textmagic apiKey.') ->inject('dbForProject') ->inject('response') - ->action(function (string $id, string $name, string $username, string $apiKey, Database $dbForProject, Response $response) { - $id = $id == 'unique()' ? ID::unique() : $id; + ->action(function (string $providerId, string $name, string $username, string $apiKey, Database $dbForProject, Response $response) { + $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; $provider = $dbForProject->createDocument('providers', new Document([ - '$id' => $id, + '$id' => $providerId, 'name' => $name, 'provider' => 'text-magic', 'type' => 'sms', @@ -548,16 +548,16 @@ App::post('/v1/messaging/providers/twilio') ->label('sdk.response.code', Response::STATUS_CODE_CREATED) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_PROVIDER) - ->param('id', '', new CustomId(), 'Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') + ->param('providerId', '', new CustomId(), 'Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') ->param('name', '', new Text(128), 'Provider name.') ->param('accountSid', '', new Text(0), 'Twilio account secret ID.') ->param('authToken', '', new Text(0), 'Twilio authentication token.') ->inject('dbForProject') ->inject('response') - ->action(function (string $id, string $name, string $accountSid, string $authToken, Database $dbForProject, Response $response) { - $id = $id == 'unique()' ? ID::unique() : $id; + ->action(function (string $providerId, string $name, string $accountSid, string $authToken, Database $dbForProject, Response $response) { + $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; $provider = $dbForProject->createDocument('providers', new Document([ - '$id' => $id, + '$id' => $providerId, 'name' => $name, 'provider' => 'twilio', 'type' => 'sms', @@ -639,16 +639,16 @@ App::post('/v1/messaging/providers/vonage') ->label('sdk.response.code', Response::STATUS_CODE_CREATED) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_PROVIDER) - ->param('id', '', new CustomId(), 'Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') + ->param('providerId', '', new CustomId(), 'Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') ->param('name', '', new Text(128), 'Provider name.') ->param('apiKey', '', new Text(0), 'Vonage API key.') ->param('apiSecret', '', new Text(0), 'Vonage API secret.') ->inject('dbForProject') ->inject('response') - ->action(function (string $id, string $name, string $apiKey, string $apiSecret, Database $dbForProject, Response $response) { - $id = $id == 'unique()' ? ID::unique() : $id; + ->action(function (string $providerId, string $name, string $apiKey, string $apiSecret, Database $dbForProject, Response $response) { + $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; $provider = $dbForProject->createDocument('providers', new Document([ - '$id' => $id, + '$id' => $providerId, 'name' => $name, 'provider' => 'vonage', 'type' => 'sms', @@ -733,15 +733,15 @@ App::post('/v1/messaging/providers/fcm') ->label('sdk.response.code', Response::STATUS_CODE_CREATED) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_PROVIDER) - ->param('id', '', new CustomId(), 'Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') + ->param('providerId', '', new CustomId(), 'Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') ->param('name', '', new Text(128), 'Provider name.') ->param('serverKey', '', new Text(0), 'FCM Server Key.') ->inject('dbForProject') ->inject('response') - ->action(function (string $id, string $name, string $serverKey, Database $dbForProject, Response $response) { -$id = $id == 'unique()' ? ID::unique() : $id; + ->action(function (string $providerId, string $name, string $serverKey, Database $dbForProject, Response $response) { + $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; $provider = $dbForProject->createDocument('providers', new Document([ - '$id' => $id, + '$id' => $providerId, 'name' => $name, 'provider' => 'fcm', 'type' => 'push', @@ -812,7 +812,7 @@ App::post('/v1/messaging/providers/apns') ->label('sdk.response.code', Response::STATUS_CODE_CREATED) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_PROVIDER) - ->param('id', '', new CustomId(), 'Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') + ->param('providerId', '', new CustomId(), 'Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') ->param('name', '', new Text(128), 'Provider name.') ->param('authKey', '', new Text(0), 'APNS authentication key.') ->param('authKeyId', '', new Text(0), 'APNS authentication key ID.') @@ -821,10 +821,10 @@ App::post('/v1/messaging/providers/apns') ->param('endpoint', '', new Text(0), 'APNS endpoint.') ->inject('dbForProject') ->inject('response') - ->action(function (string $id, string $name, string $authKey, string $authKeyId, string $teamId, string $bundleId, string $endpoint, Database $dbForProject, Response $response) { - $id = $id == 'unique()' ? ID::unique() : $id; + ->action(function (string $providerId, string $name, string $authKey, string $authKeyId, string $teamId, string $bundleId, string $endpoint, Database $dbForProject, Response $response) { + $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; $provider = $dbForProject->createDocument('providers', new Document([ - '$id' => $id, + '$id' => $providerId, 'name' => $name, 'provider' => 'apns', 'type' => 'push', diff --git a/tests/e2e/Services/Messaging/MessagingBase.php b/tests/e2e/Services/Messaging/MessagingBase.php index 8a0937c0eb..0bea95ac1a 100644 --- a/tests/e2e/Services/Messaging/MessagingBase.php +++ b/tests/e2e/Services/Messaging/MessagingBase.php @@ -10,53 +10,53 @@ trait MessagingBase { $providersParams = [ 'sendgrid' => [ - 'id' => 'unique()', + 'providerId' => 'unique()', 'name' => 'Sengrid1', 'apiKey' => 'my-apikey', ], 'mailgun' => [ - 'id' => 'unique()', + 'providerId' => 'unique()', 'name' => 'Mailgun1', 'apiKey' => 'my-apikey', 'domain' => 'my-domain', ], 'twilio' => [ - 'id' => 'unique()', + 'providerId' => 'unique()', 'name' => 'Twilio1', 'accountSid' => 'my-accountSid', 'authToken' => 'my-authToken', ], 'telesign' => [ - 'id' => 'unique()', + 'providerId' => 'unique()', 'name' => 'Telesign1', 'username' => 'my-username', 'password' => 'my-password', ], 'textmagic' => [ - 'id' => 'unique()', + 'providerId' => 'unique()', 'name' => 'Textmagic1', 'username' => 'my-username', 'apiKey' => 'my-apikey', ], 'msg91' => [ - 'id' => 'unique()', + 'providerId' => 'unique()', 'name' => 'Ms91-1', 'senderId' => 'my-senderid', 'authKey' => 'my-authkey', ], 'vonage' => [ - 'id' => 'unique()', + 'providerId' => 'unique()', 'name' => 'Vonage1', 'apiKey' => 'my-apikey', 'apiSecret' => 'my-apisecret', ], 'fcm' => [ - 'id' => 'unique()', + 'providerId' => 'unique()', 'name' => 'FCM1', 'serverKey' => 'my-serverkey', ], 'apns' => [ - 'id' => 'unique()', + 'providerId' => 'unique()', 'name' => 'APNS1', 'authKey' => 'my-authkey', 'authKeyId' => 'my-authkeyid', @@ -159,7 +159,7 @@ trait MessagingBase 'x-appwrite-key' => $this->getProject()['apiKey'], ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals(\count($providers), $response['body']['total']); + $this->assertEquals(\count($providers), \count($response['body']['providers'])); } /**