Replace prefs patch method with put

This commit is contained in:
Eldad Fux 2020-08-06 15:45:58 +03:00
parent 1707fac0ab
commit f8970dc023
5 changed files with 17 additions and 17 deletions

View file

@ -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

View file

@ -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) {

View file

@ -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) {

View file

@ -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'],

View file

@ -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()));