From 8ad2dd1e879352310b1ea4573422bb13d84e41cf Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Sat, 12 Sep 2020 11:07:28 +0300 Subject: [PATCH] Updated project model --- app/controllers/api/projects.php | 18 +- src/Appwrite/Utopia/Response.php | 2 + .../Utopia/Response/Model/Project.php | 166 ++++++++++++++++++ 3 files changed, 178 insertions(+), 8 deletions(-) create mode 100644 src/Appwrite/Utopia/Response/Model/Project.php diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index e8c667dbb3..eab5205a0d 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -71,6 +71,7 @@ App::post('/v1/projects') 'webhooks' => [], 'keys' => [], 'tasks' => [], + 'domains' => [], ] ); @@ -80,10 +81,8 @@ App::post('/v1/projects') $consoleDB->createNamespace($project->getId()); - $response - ->setStatusCode(Response::STATUS_CODE_CREATED) - ->json($project->getArrayCopy()) - ; + $response->setStatusCode(Response::STATUS_CODE_CREATED); + $response->dynamic($project, Response::MODEL_PROJECT); }, ['response', 'consoleDB', 'projectDB']); App::get('/v1/projects') @@ -122,7 +121,10 @@ App::get('/v1/projects') } } - $response->json(['sum' => $consoleDB->getSum(), 'projects' => $results]); + $response->dynamic(new Document([ + 'sum' => $consoleDB->getSum(), + 'projects' => $results + ]), Response::MODEL_PROJECT_LIST); }, ['response', 'consoleDB']); App::get('/v1/projects/:projectId') @@ -151,7 +153,7 @@ App::get('/v1/projects/:projectId') } } - $response->json($project->getArrayCopy()); + $response->dynamic($project, Response::MODEL_PROJECT); }, ['response', 'consoleDB']); App::get('/v1/projects/:projectId/usage') @@ -386,7 +388,7 @@ App::patch('/v1/projects/:projectId') throw new Exception('Failed saving project to DB', 500); } - $response->json($project->getArrayCopy()); + $response->dynamic($project, Response::MODEL_PROJECT); }, ['response', 'consoleDB']); App::patch('/v1/projects/:projectId/oauth2') @@ -429,7 +431,7 @@ App::patch('/v1/projects/:projectId/oauth2') throw new Exception('Failed saving project to DB', 500); } - $response->json($project->getArrayCopy()); + $response->dynamic($project, Response::MODEL_PROJECT); }, ['response', 'consoleDB']); App::delete('/v1/projects/:projectId') diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index 70b57c361f..91f7976b25 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -29,6 +29,7 @@ use Appwrite\Utopia\Response\Model\Log; use Appwrite\Utopia\Response\Model\Membership; use Appwrite\Utopia\Response\Model\Phone; use Appwrite\Utopia\Response\Model\Platform; +use Appwrite\Utopia\Response\Model\Project; use Appwrite\Utopia\Response\Model\Rule; use Appwrite\Utopia\Response\Model\Tag; use Appwrite\Utopia\Response\Model\Task; @@ -153,6 +154,7 @@ class Response extends SwooleResponse ->setModel(new Func()) ->setModel(new Tag()) ->setModel(new Execution()) + ->setModel(new Project()) ->setModel(new Webhook()) ->setModel(new Key()) ->setModel(new Task()) diff --git a/src/Appwrite/Utopia/Response/Model/Project.php b/src/Appwrite/Utopia/Response/Model/Project.php new file mode 100644 index 0000000000..af5cad3ebe --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Project.php @@ -0,0 +1,166 @@ +addRule('$id', [ + 'type' => 'string', + 'description' => 'Project ID.', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('name', [ + 'type' => 'string', + 'description' => 'Project name.', + 'default' => '', + 'example' => 'New Project', + ]) + ->addRule('description', [ + 'type' => 'string', + 'description' => 'Project description.', + 'default' => '', + 'example' => 'This is a new project.', + ]) + ->addRule('teamId', [ + 'type' => 'string', + 'description' => 'Project team ID.', + 'example' => '1592981250', + ]) + ->addRule('logo', [ + 'type' => 'string', + 'description' => 'Project logo file ID.', + 'default' => '', + 'example' => '5f5c451b403cb', + ]) + ->addRule('url', [ + 'type' => 'string', + 'description' => 'Project website URL.', + 'default' => '', + 'example' => '5f5c451b403cb', + ]) + ->addRule('legalName', [ + 'type' => 'string', + 'description' => 'Company legal name.', + 'default' => '', + 'example' => 'Company LTD.', + ]) + ->addRule('legalCountry', [ + 'type' => 'string', + 'description' => 'Country code in [ISO 3166-1](http://en.wikipedia.org/wiki/ISO_3166-1) two-character format.', + 'default' => '', + 'example' => 'US', + ]) + ->addRule('legalState', [ + 'type' => 'string', + 'description' => 'State name.', + 'default' => '', + 'example' => 'New York', + ]) + ->addRule('legalCity', [ + 'type' => 'string', + 'description' => 'City name.', + 'default' => '', + 'example' => 'New York City.', + ]) + ->addRule('legalAddress', [ + 'type' => 'string', + 'description' => 'Company Address.', + 'default' => '', + 'example' => '620 Eighth Avenue, New York, NY 10018', + ]) + ->addRule('legalTaxId', [ + 'type' => 'string', + 'description' => 'Company Tax ID.', + 'default' => '', + 'example' => '131102020', + ]) + ->addRule('platforms', [ + 'type' => Response::MODEL_PLATFORM, + 'description' => 'List of Platforms.', + 'default' => [], + 'example' => [], + 'array' => true, + ]) + ->addRule('webhooks', [ + 'type' => Response::MODEL_WEBHOOK, + 'description' => 'List of Webhooks.', + 'default' => [], + 'example' => [], + 'array' => true, + ]) + ->addRule('keys', [ + 'type' => Response::MODEL_KEY, + 'description' => 'List of API Keys.', + 'default' => [], + 'example' => [], + 'array' => true, + ]) + ->addRule('domains', [ + 'type' => Response::MODEL_DOMAIN, + 'description' => 'List of Domains.', + 'default' => [], + 'example' => [], + 'array' => true, + ]) + ->addRule('tasks', [ + 'type' => Response::MODEL_TASK, + 'description' => 'List of Tasks.', + 'default' => [], + 'example' => [], + 'array' => true, + ]) + ; + + $providers = Config::getParam('providers', []); + + foreach ($providers as $index => $provider) { + if (!$provider['enabled']) { + continue; + } + + $name = (isset($provider['name'])) ? $provider['name'] : 'Unknown'; + + $this + ->addRule('usersOauth2'.\ucfirst($index).'Appid', [ + 'type' => 'string', + 'description' => $name.' OAuth app ID.', + 'example' => '123247283472834787438', + 'default' => '', + ]) + ->addRule('usersOauth2'.\ucfirst($index).'Secret', [ + 'type' => 'string', + 'description' => $name.' OAuth secret ID.', + 'example' => 'djsgudsdsewe43434343dd34...', + 'default' => '', + ]) + ; + } + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Project'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_PROJECT; + } +} \ No newline at end of file