Merge pull request #1102 from TorstenDittmann/feat-prefs-response-model
feat: preferences response model
This commit is contained in:
commit
8e4a87ea04
|
@ -6,7 +6,7 @@
|
|||
- Added events for functions and executions (#971)
|
||||
- Added JWT support
|
||||
- Added ARM support
|
||||
- Splited token & session models to become 2 different internal entities (#922)
|
||||
- Splitted token & session models to become 2 different internal entities (#922)
|
||||
- Added Dart 2.12 as a new Cloud Functions runtime (#989)
|
||||
- Added option to disable email/password
|
||||
- Added option to disable anonymous login (need to merge and apply changed)
|
||||
|
@ -21,6 +21,7 @@
|
|||
- ClamAV is now disabled by default to allow lower min requirments for Appwrite (#1064)
|
||||
- Added a new env var named `_APP_LOCALE` that allow to change the default `en` locale value (#1056)
|
||||
- Updated all the console bottom control to be consistent. Dropped the `+` icon (#1062)
|
||||
- Added Response Models for Documents and Preferences
|
||||
|
||||
## Bugs
|
||||
|
||||
|
|
|
@ -831,7 +831,7 @@ App::get('/v1/account/prefs')
|
|||
->label('sdk.description', '/docs/references/account/get-prefs.md')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', Response::MODEL_ANY)
|
||||
->label('sdk.response.model', Response::MODEL_PREFERENCES)
|
||||
->inject('response')
|
||||
->inject('user')
|
||||
->action(function ($response, $user) {
|
||||
|
@ -840,7 +840,7 @@ App::get('/v1/account/prefs')
|
|||
|
||||
$prefs = $user->getAttribute('prefs', new \stdClass());
|
||||
|
||||
$response->dynamic(new Document($prefs), Response::MODEL_ANY);
|
||||
$response->dynamic(new Document($prefs), Response::MODEL_PREFERENCES);
|
||||
});
|
||||
|
||||
App::get('/v1/account/sessions')
|
||||
|
@ -1124,7 +1124,7 @@ App::patch('/v1/account/prefs')
|
|||
->label('sdk.description', '/docs/references/account/update-prefs.md')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', Response::MODEL_ANY)
|
||||
->label('sdk.response.model', Response::MODEL_USER)
|
||||
->param('prefs', [], new Assoc(), 'Prefs key-value JSON object.')
|
||||
->inject('response')
|
||||
->inject('user')
|
||||
|
|
|
@ -151,7 +151,7 @@ App::get('/v1/users/:userId/prefs')
|
|||
->label('sdk.description', '/docs/references/users/get-user-prefs.md')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', Response::MODEL_ANY)
|
||||
->label('sdk.response.model', Response::MODEL_PREFERENCES)
|
||||
->param('userId', '', new UID(), 'User unique ID.')
|
||||
->inject('response')
|
||||
->inject('projectDB')
|
||||
|
@ -167,7 +167,7 @@ App::get('/v1/users/:userId/prefs')
|
|||
|
||||
$prefs = $user->getAttribute('prefs', new \stdClass());
|
||||
|
||||
$response->dynamic(new Document($prefs), Response::MODEL_ANY);
|
||||
$response->dynamic(new Document($prefs), Response::MODEL_PREFERENCES);
|
||||
});
|
||||
|
||||
App::get('/v1/users/:userId/sessions')
|
||||
|
@ -378,7 +378,7 @@ App::patch('/v1/users/:userId/prefs')
|
|||
->label('sdk.description', '/docs/references/users/update-user-prefs.md')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', Response::MODEL_ANY)
|
||||
->label('sdk.response.model', Response::MODEL_PREFERENCES)
|
||||
->param('userId', '', new UID(), 'User unique ID.')
|
||||
->param('prefs', '', new Assoc(), 'Prefs key-value JSON object.')
|
||||
->inject('response')
|
||||
|
@ -401,7 +401,7 @@ App::patch('/v1/users/:userId/prefs')
|
|||
throw new Exception('Failed saving user to DB', 500);
|
||||
}
|
||||
|
||||
$response->dynamic(new Document($prefs), Response::MODEL_ANY);
|
||||
$response->dynamic(new Document($prefs), Response::MODEL_PREFERENCES);
|
||||
});
|
||||
|
||||
App::delete('/v1/users/:userId/sessions/:sessionId')
|
||||
|
|
|
@ -40,6 +40,7 @@ use Appwrite\Utopia\Response\Model\Tag;
|
|||
use Appwrite\Utopia\Response\Model\Task;
|
||||
use Appwrite\Utopia\Response\Model\Token;
|
||||
use Appwrite\Utopia\Response\Model\Webhook;
|
||||
use Appwrite\Utopia\Response\Model\Preferences;
|
||||
use Appwrite\Utopia\Response\Model\Mock; // Keep last
|
||||
use stdClass;
|
||||
|
||||
|
@ -72,6 +73,7 @@ class Response extends SwooleResponse
|
|||
const MODEL_SESSION_LIST = 'sessionList';
|
||||
const MODEL_TOKEN = 'token';
|
||||
const MODEL_JWT = 'jwt';
|
||||
const MODEL_PREFERENCES = 'preferences';
|
||||
|
||||
// Storage
|
||||
const MODEL_FILE = 'file';
|
||||
|
@ -175,6 +177,7 @@ class Response extends SwooleResponse
|
|||
->setModel(new Rule())
|
||||
->setModel(new Log())
|
||||
->setModel(new User())
|
||||
->setModel(new Preferences())
|
||||
->setModel(new Session())
|
||||
->setModel(new Token())
|
||||
->setModel(new JWT())
|
||||
|
|
|
@ -109,6 +109,7 @@ class V06 extends Filter {
|
|||
|
||||
case Response::MODEL_ANY :
|
||||
case Response::MODEL_DOCUMENT :
|
||||
case Response::MODEL_PREFERENCES :
|
||||
$parsedResponse = $content;
|
||||
break;
|
||||
|
||||
|
|
33
src/Appwrite/Utopia/Response/Model/Preferences.php
Normal file
33
src/Appwrite/Utopia/Response/Model/Preferences.php
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
|
||||
class Preferences extends Any
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $any = true;
|
||||
|
||||
/**
|
||||
* Get Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName():string
|
||||
{
|
||||
return 'Preferences';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Collection
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType():string
|
||||
{
|
||||
return Response::MODEL_PREFERENCES;
|
||||
}
|
||||
}
|
|
@ -47,7 +47,7 @@ class User extends Model
|
|||
'example' => true,
|
||||
])
|
||||
->addRule('prefs', [
|
||||
'type' => self::TYPE_JSON,
|
||||
'type' => Response::MODEL_PREFERENCES,
|
||||
'description' => 'User preferences as a key-value object',
|
||||
'default' => new \stdClass,
|
||||
'example' => ['theme' => 'pink', 'timezone' => 'UTC'],
|
||||
|
|
Loading…
Reference in a new issue