From f8970dc023fe7ddba6d8b5f062cc1e7d2c7960a9 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Thu, 6 Aug 2020 15:45:58 +0300 Subject: [PATCH] Replace prefs patch method with put --- CHANGES.md | 2 ++ app/controllers/api/account.php | 9 ++++----- app/controllers/api/users.php | 7 +++---- tests/e2e/Services/Account/AccountBase.php | 10 +++++----- tests/e2e/Services/Users/UsersBase.php | 6 +++--- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index e27b89b088..6fb9d80e96 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -30,6 +30,8 @@ ## Breaking Changes (Read before upgrading!) - **Deprecated** `first` and `last` query params for documents list route in the database API - **Deprecated** Deprectaed Pubjabi Translations ('pn') +- **Deprecated** `PATCH /account/prefs` in favour of `PUT /account/prefs` route +- **Deprecated** `PATCH /users/:userId/prefs` in favour of `PUT /users/:userId/prefs` route - Switched order of limit and offset params in all the SDKs `listDocuments` method for better consistency - Default `limit` param value in all the SDKs `listDocuments` method is now 25 for better consistency diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index cf2bc5da7e..8cb3ad7b41 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -124,6 +124,7 @@ App::post('/v1/account') ->setAttribute('roles', Authorization::getRoles()) ; + $response->setStatusCode(Response::STATUS_CODE_CREATED); $response->dynamic($user, Response::MODEL_USER); }, ['request', 'response', 'project', 'projectDB', 'webhooks', 'audits']); @@ -828,7 +829,7 @@ App::patch('/v1/account/email') $response->dynamic($user, Response::MODEL_USER); }, ['response', 'user', 'projectDB', 'audits']); -App::patch('/v1/account/prefs') +App::put('/v1/account/prefs') ->desc('Update Account Preferences') ->groups(['api', 'account']) ->label('event', 'account.update.prefs') @@ -836,7 +837,7 @@ App::patch('/v1/account/prefs') ->label('sdk.platform', [APP_PLATFORM_CLIENT]) ->label('sdk.namespace', 'account') ->label('sdk.method', 'updatePrefs') - ->param('prefs', '', function () { return new Assoc();}, 'Prefs key-value JSON object.') + ->param('prefs', [], function () { return new Assoc();}, 'Prefs key-value JSON object.') ->label('sdk.description', '/docs/references/account/update-prefs.md') ->action(function ($prefs, $response, $user, $projectDB, $audits) { /** @var Appwrite\Swoole\Response $response */ @@ -844,10 +845,8 @@ App::patch('/v1/account/prefs') /** @var Appwrite\Database\Database $projectDB */ /** @var Appwrite\Event\Event $audits */ - $old = $user->getAttribute('prefs', new \stdClass); - $user = $projectDB->updateDocument(\array_merge($user->getArrayCopy(), [ - 'prefs' => \array_merge($old, $prefs), + 'prefs' => $prefs, ])); if (false === $user) { diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index ca7c8dcebf..ae7fd593cc 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -65,6 +65,7 @@ App::post('/v1/users') throw new Exception('Account already exists', 409); } + $response->setStatusCode(Response::STATUS_CODE_CREATED); $response->dynamic($user, Response::MODEL_USER); }, ['response', 'projectDB']); @@ -340,7 +341,7 @@ App::patch('/v1/users/:userId/status') $response->dynamic($user, Response::MODEL_USER); }, ['response', 'projectDB']); -App::patch('/v1/users/:userId/prefs') +App::put('/v1/users/:userId/prefs') ->desc('Update User Preferences') ->groups(['api', 'users']) ->label('scope', 'users.write') @@ -360,10 +361,8 @@ App::patch('/v1/users/:userId/prefs') throw new Exception('User not found', 404); } - $old = $user->getAttribute('prefs', new \stdClass); - $user = $projectDB->updateDocument(\array_merge($user->getArrayCopy(), [ - 'prefs' => \array_merge($old, $prefs), + 'prefs' => $prefs, ])); if (false === $user) { diff --git a/tests/e2e/Services/Account/AccountBase.php b/tests/e2e/Services/Account/AccountBase.php index fef7990f6c..e001657e42 100644 --- a/tests/e2e/Services/Account/AccountBase.php +++ b/tests/e2e/Services/Account/AccountBase.php @@ -566,7 +566,7 @@ trait AccountBase /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_PATCH, '/account/prefs', array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/account/prefs', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -588,7 +588,7 @@ trait AccountBase /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_PATCH, '/account/prefs', array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/account/prefs', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -596,7 +596,7 @@ trait AccountBase $this->assertEquals($response['headers']['status-code'], 401); - $response = $this->client->call(Client::METHOD_PATCH, '/account/prefs', array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/account/prefs', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -608,7 +608,7 @@ trait AccountBase $this->assertEquals($response['headers']['status-code'], 400); - $response = $this->client->call(Client::METHOD_PATCH, '/account/prefs', array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/account/prefs', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -619,7 +619,7 @@ trait AccountBase $this->assertEquals($response['headers']['status-code'], 400); - $response = $this->client->call(Client::METHOD_PATCH, '/account/prefs', array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/account/prefs', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], diff --git a/tests/e2e/Services/Users/UsersBase.php b/tests/e2e/Services/Users/UsersBase.php index f66841ce05..ca2d20185d 100644 --- a/tests/e2e/Services/Users/UsersBase.php +++ b/tests/e2e/Services/Users/UsersBase.php @@ -132,7 +132,7 @@ trait UsersBase /** * Test for SUCCESS */ - $user = $this->client->call(Client::METHOD_PATCH, '/users/' . $data['userId'] . '/prefs', array_merge([ + $user = $this->client->call(Client::METHOD_PUT, '/users/' . $data['userId'] . '/prefs', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -149,7 +149,7 @@ trait UsersBase /** * Test for FAILURE */ - $user = $this->client->call(Client::METHOD_PATCH, '/users/' . $data['userId'] . '/prefs', array_merge([ + $user = $this->client->call(Client::METHOD_PUT, '/users/' . $data['userId'] . '/prefs', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -158,7 +158,7 @@ trait UsersBase $this->assertEquals($user['headers']['status-code'], 400); - $user = $this->client->call(Client::METHOD_PATCH, '/users/' . $data['userId'] . '/prefs', array_merge([ + $user = $this->client->call(Client::METHOD_PUT, '/users/' . $data['userId'] . '/prefs', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()));