diff --git a/CHANGES.md b/CHANGES.md index be06d3bdbe..7fa0f2285a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 3731c8524c..2cf9770fc8 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -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') diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 3ad2360cca..6b5bfbdbd9 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -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') diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index 0bed14e45c..ef9d48f4ee 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -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()) diff --git a/src/Appwrite/Utopia/Response/Filters/V06.php b/src/Appwrite/Utopia/Response/Filters/V06.php index 13ee89cbb7..673755e7d1 100644 --- a/src/Appwrite/Utopia/Response/Filters/V06.php +++ b/src/Appwrite/Utopia/Response/Filters/V06.php @@ -109,6 +109,7 @@ class V06 extends Filter { case Response::MODEL_ANY : case Response::MODEL_DOCUMENT : + case Response::MODEL_PREFERENCES : $parsedResponse = $content; break; diff --git a/src/Appwrite/Utopia/Response/Model/Preferences.php b/src/Appwrite/Utopia/Response/Model/Preferences.php new file mode 100644 index 0000000000..24196f6a84 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Preferences.php @@ -0,0 +1,33 @@ + 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'],