Updated response models
This commit is contained in:
parent
7ebc6a5de9
commit
5b34a1ea7e
|
@ -1,15 +1,16 @@
|
|||
<?php
|
||||
|
||||
use Appwrite\Database\Database;
|
||||
use Appwrite\Database\Document;
|
||||
use Appwrite\Database\Validator\UID;
|
||||
use Appwrite\Storage\Storage;
|
||||
use Appwrite\Storage\Validator\File;
|
||||
use Appwrite\Storage\Validator\FileSize;
|
||||
use Appwrite\Storage\Validator\FileType;
|
||||
use Appwrite\Storage\Validator\Upload;
|
||||
use Appwrite\Swoole\Response;
|
||||
use Appwrite\Task\Validator\Cron;
|
||||
use Utopia\App;
|
||||
use Utopia\Response;
|
||||
use Utopia\Validator\ArrayList;
|
||||
use Utopia\Validator\Assoc;
|
||||
use Utopia\Validator\Text;
|
||||
|
@ -59,10 +60,8 @@ App::post('/v1/functions')
|
|||
throw new Exception('Failed saving function to DB', 500);
|
||||
}
|
||||
|
||||
$response
|
||||
->setStatusCode(Response::STATUS_CODE_CREATED)
|
||||
->json($function->getArrayCopy())
|
||||
;
|
||||
$response->setStatusCode(Response::STATUS_CODE_CREATED);
|
||||
$response->dynamic($function, Response::MODEL_FUNCTION);
|
||||
}, ['response', 'projectDB']);
|
||||
|
||||
App::get('/v1/functions')
|
||||
|
@ -90,7 +89,10 @@ App::get('/v1/functions')
|
|||
],
|
||||
]);
|
||||
|
||||
$response->json(['sum' => $projectDB->getSum(), 'functions' => $results]);
|
||||
$response->dynamic(new Document([
|
||||
'sum' => $projectDB->getSum(),
|
||||
'functions' => $results
|
||||
]), Response::MODEL_FUNCTION_LIST);
|
||||
}, ['response', 'projectDB']);
|
||||
|
||||
App::get('/v1/functions/:functionId')
|
||||
|
@ -109,7 +111,7 @@ App::get('/v1/functions/:functionId')
|
|||
throw new Exception('Function not found', 404);
|
||||
}
|
||||
|
||||
$response->json($function->getArrayCopy());
|
||||
$response->dynamic($function, Response::MODEL_FUNCTION);
|
||||
}, ['response', 'projectDB']);
|
||||
|
||||
App::get('/v1/functions/:functionId/usage')
|
||||
|
@ -264,7 +266,7 @@ App::put('/v1/functions/:functionId')
|
|||
throw new Exception('Failed saving function to DB', 500);
|
||||
}
|
||||
|
||||
$response->json($function->getArrayCopy());
|
||||
$response->dynamic($function, Response::MODEL_FUNCTION);
|
||||
}, ['response', 'projectDB']);
|
||||
|
||||
App::patch('/v1/functions/:functionId/tag')
|
||||
|
@ -302,7 +304,7 @@ App::patch('/v1/functions/:functionId/tag')
|
|||
throw new Exception('Failed saving function to DB', 500);
|
||||
}
|
||||
|
||||
$response->json($function->getArrayCopy());
|
||||
$response->dynamic($function, Response::MODEL_FUNCTION);
|
||||
}, ['response', 'projectDB']);
|
||||
|
||||
App::delete('/v1/functions/:functionId')
|
||||
|
@ -414,10 +416,8 @@ App::post('/v1/functions/:functionId/tags')
|
|||
->setParam('storage', $tag->getAttribute('codeSize', 0))
|
||||
;
|
||||
|
||||
$response
|
||||
->setStatusCode(Response::STATUS_CODE_CREATED)
|
||||
->json($tag->getArrayCopy())
|
||||
;
|
||||
$response->setStatusCode(Response::STATUS_CODE_CREATED);
|
||||
$response->dynamic($tag, Response::MODEL_TAG);
|
||||
}, ['request', 'response', 'projectDB', 'usage']);
|
||||
|
||||
App::get('/v1/functions/:functionId/tags')
|
||||
|
@ -453,7 +453,10 @@ App::get('/v1/functions/:functionId/tags')
|
|||
],
|
||||
]);
|
||||
|
||||
$response->json(['sum' => $projectDB->getSum(), 'tags' => $results]);
|
||||
$response->dynamic(new Document([
|
||||
'sum' => $projectDB->getSum(),
|
||||
'tags' => $results
|
||||
]), Response::MODEL_TAG_LIST);
|
||||
}, ['response', 'projectDB']);
|
||||
|
||||
App::get('/v1/functions/:functionId/tags/:tagId')
|
||||
|
@ -483,7 +486,7 @@ App::get('/v1/functions/:functionId/tags/:tagId')
|
|||
throw new Exception('Tag not found', 404);
|
||||
}
|
||||
|
||||
$response->json($tag->getArrayCopy());
|
||||
$response->dynamic($tag, Response::MODEL_TAG);
|
||||
}, ['response', 'projectDB']);
|
||||
|
||||
App::delete('/v1/functions/:functionId/tags/:tagId')
|
||||
|
@ -597,10 +600,8 @@ App::post('/v1/functions/:functionId/executions')
|
|||
'trigger' => 'http',
|
||||
]);
|
||||
|
||||
$response
|
||||
->setStatusCode(Response::STATUS_CODE_CREATED)
|
||||
->json($execution->getArrayCopy())
|
||||
;
|
||||
$response->setStatusCode(Response::STATUS_CODE_CREATED);
|
||||
$response->dynamic($execution, Response::MODEL_EXECUTION);
|
||||
}, ['response', 'project', 'projectDB']);
|
||||
|
||||
App::get('/v1/functions/:functionId/executions')
|
||||
|
@ -636,7 +637,10 @@ App::get('/v1/functions/:functionId/executions')
|
|||
],
|
||||
]);
|
||||
|
||||
$response->json(['sum' => $projectDB->getSum(), 'executions' => $results]);
|
||||
$response->dynamic(new Document([
|
||||
'sum' => $projectDB->getSum(),
|
||||
'executions' => $results
|
||||
]), Response::MODEL_EXECUTION_LIST);
|
||||
}, ['response', 'projectDB']);
|
||||
|
||||
App::get('/v1/functions/:functionId/executions/:executionId')
|
||||
|
@ -666,5 +670,5 @@ App::get('/v1/functions/:functionId/executions/:executionId')
|
|||
throw new Exception('Execution not found', 404);
|
||||
}
|
||||
|
||||
$response->json($execution->getArrayCopy());
|
||||
$response->dynamic($execution, Response::MODEL_EXECUTION);
|
||||
}, ['response', 'projectDB']);
|
|
@ -5,6 +5,7 @@ namespace Appwrite\Utopia;
|
|||
use Exception;
|
||||
use Appwrite\Database\Document;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
use Appwrite\Utopia\Response\Model\BaseList;
|
||||
use Appwrite\Utopia\Response\Model\Error;
|
||||
use Appwrite\Utopia\Response\Model\ErrorDev;
|
||||
use Appwrite\Utopia\Response\Model\File;
|
||||
|
@ -69,18 +70,24 @@ class Response extends UtopiaResponse
|
|||
public function __construct(int $time = 0)
|
||||
{
|
||||
$this
|
||||
// General
|
||||
->setModel(new Error())
|
||||
->setModel(new ErrorDev())
|
||||
// Lists
|
||||
->setModel(new BaseList('Files List', self::MODEL_FILE_LIST, 'files', self::MODEL_FILE))
|
||||
->setModel(new BaseList('Teams List', self::MODEL_TEAM_LIST, 'teams', self::MODEL_TEAM))
|
||||
->setModel(new BaseList('Memberships List', self::MODEL_MEMBERSHIP_LIST, 'memberships', self::MODEL_MEMBERSHIP))
|
||||
->setModel(new BaseList('Functions List', self::MODEL_FUNCTION_LIST, 'functions', self::MODEL_FUNCTION))
|
||||
->setModel(new BaseList('Tags List', self::MODEL_TAG_LIST, 'tags', self::MODEL_TAG))
|
||||
->setModel(new BaseList('Executions List', self::MODEL_EXECUTION_LIST, 'executions', self::MODEL_EXECUTION))
|
||||
// Entities
|
||||
->setModel(new User())
|
||||
->setModel(new Session())
|
||||
->setModel(new Locale())
|
||||
->setModel(new File())
|
||||
->setModel(new FileList())
|
||||
->setModel(new Team())
|
||||
->setModel(new TeamList())
|
||||
->setModel(new Membership())
|
||||
->setModel(new MembershipList())
|
||||
->setModel(new Functionx())
|
||||
->setModel(new Func())
|
||||
;
|
||||
|
||||
parent::__construct($time);
|
||||
|
|
|
@ -5,16 +5,35 @@ namespace Appwrite\Utopia\Response\Model;
|
|||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
||||
abstract class BaseList extends Model
|
||||
class BaseList extends Model
|
||||
{
|
||||
public function __construct()
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $name = '';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $type = '';
|
||||
|
||||
public function __construct(string $name, string $type, string $key, string $model)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->type = $type;
|
||||
|
||||
$this
|
||||
->addRule('sum', [
|
||||
'type' => 'integer',
|
||||
'description' => 'Total sum of items in the list.',
|
||||
'example' => '5',
|
||||
])
|
||||
->addRule($key, [
|
||||
'type' => $model,
|
||||
'description' => 'List of '.$key.'.',
|
||||
'example' => [],
|
||||
'array' => true,
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
|
@ -25,7 +44,7 @@ abstract class BaseList extends Model
|
|||
*/
|
||||
public function getName():string
|
||||
{
|
||||
return 'Base List';
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -35,6 +54,6 @@ abstract class BaseList extends Model
|
|||
*/
|
||||
public function getType():string
|
||||
{
|
||||
return Response::MODEL_BASE_LIST;
|
||||
return $this->type;
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
|
||||
class ExecutionList extends BaseList
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this
|
||||
->addRule('executions', [
|
||||
'type' => Response::MODEL_EXECUTION,
|
||||
'description' => 'List of function execitions.',
|
||||
'example' => [],
|
||||
'array' => true,
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName():string
|
||||
{
|
||||
return 'Executions List';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Collection
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType():string
|
||||
{
|
||||
return Response::MODEL_EXECUTION_LIST;
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
|
||||
class FileList extends BaseList
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this
|
||||
->addRule('files', [
|
||||
'type' => Response::MODEL_FILE,
|
||||
'description' => 'List of files.',
|
||||
'example' => [],
|
||||
'array' => true,
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName():string
|
||||
{
|
||||
return 'Files List';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Collection
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType():string
|
||||
{
|
||||
return Response::MODEL_FILE_LIST;
|
||||
}
|
||||
}
|
|
@ -5,7 +5,7 @@ namespace Appwrite\Utopia\Response\Model;
|
|||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
||||
class Functionx extends Model
|
||||
class Func extends Model
|
||||
{
|
||||
public function __construct()
|
||||
{
|
|
@ -1,41 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
|
||||
class FunctionxList extends BaseList
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this
|
||||
->addRule('functions', [
|
||||
'type' => Response::MODEL_MEMBERSHIP,
|
||||
'description' => 'List of functions.',
|
||||
'example' => [],
|
||||
'array' => true,
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName():string
|
||||
{
|
||||
return 'Functions List';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Collection
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType():string
|
||||
{
|
||||
return Response::MODEL_FUNCTION_LIST;
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
|
||||
class MembershipList extends BaseList
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this
|
||||
->addRule('memberships', [
|
||||
'type' => Response::MODEL_MEMBERSHIP,
|
||||
'description' => 'List of memberships.',
|
||||
'example' => [],
|
||||
'array' => true,
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName():string
|
||||
{
|
||||
return 'Memberships List';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Collection
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType():string
|
||||
{
|
||||
return Response::MODEL_MEMBERSHIP_LIST;
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
|
||||
class TagList extends BaseList
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this
|
||||
->addRule('tags', [
|
||||
'type' => Response::MODEL_TAG,
|
||||
'description' => 'List of tags.',
|
||||
'example' => [],
|
||||
'array' => true,
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName():string
|
||||
{
|
||||
return 'Tags List';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Collection
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType():string
|
||||
{
|
||||
return Response::MODEL_TAG_LIST;
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
|
||||
class TeamList extends BaseList
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this
|
||||
->addRule('teams', [
|
||||
'type' => Response::MODEL_TEAM,
|
||||
'description' => 'List of teams.',
|
||||
'example' => [],
|
||||
'array' => true,
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName():string
|
||||
{
|
||||
return 'Teams List';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Collection
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType():string
|
||||
{
|
||||
return Response::MODEL_TEAM_LIST;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue