update: use abstract for getResponseModel.

This commit is contained in:
Darshan 2025-05-08 12:47:21 +05:30
parent cb64484c44
commit 96b89693fc
55 changed files with 287 additions and 323 deletions

View file

@ -30,9 +30,9 @@ abstract class Action extends UtopiaAction
private ?string $context = DATABASE_ATTRIBUTES_CONTEXT; private ?string $context = DATABASE_ATTRIBUTES_CONTEXT;
/** /**
* @var string|array|null The current response model for the attribute/column type. * Get the correct response model.
*/ */
private string|array|null $responseModel = null; abstract protected function getResponseModel(): string|array;
/** /**
* Set the context to either `column` or `attribute`. * Set the context to either `column` or `attribute`.
@ -92,26 +92,6 @@ abstract class Action extends UtopiaAction
return $this->getContext() . 'Id'; return $this->getContext() . 'Id';
} }
/**
* Set the correct response model.
*/
final protected function setResponseModel(string|array $model): void
{
$this->responseModel = $model;
}
/**
* Get the correct response model.
*/
final protected function getResponseModel(): string|array
{
if ($this->responseModel === null) {
throw new \LogicException("Missing response model: you must call setResponseModel() before using it.");
}
return $this->responseModel;
}
/** /**
* Get the appropriate parent level not found exception. * Get the appropriate parent level not found exception.
*/ */

View file

@ -26,10 +26,13 @@ class Create extends Action
return 'createBooleanColumn'; return 'createBooleanColumn';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_ATTRIBUTE_BOOLEAN;
}
public function __construct() public function __construct()
{ {
$this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_BOOLEAN);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST)
->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/boolean') ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/boolean')
@ -66,19 +69,8 @@ class Create extends Action
->callback([$this, 'action']); ->callback([$this, 'action']);
} }
public function action( public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?bool $default, bool $array, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents): void
string $databaseId, {
string $collectionId,
string $key,
?bool $required,
?bool $default,
bool $array,
UtopiaResponse $response,
Database $dbForProject,
EventDatabase $queueForDatabase,
Event $queueForEvents
): void {
$attribute = $this->createAttribute($databaseId, $collectionId, new Document([ $attribute = $this->createAttribute($databaseId, $collectionId, new Document([
'key' => $key, 'key' => $key,
'type' => Database::VAR_BOOLEAN, 'type' => Database::VAR_BOOLEAN,

View file

@ -26,10 +26,13 @@ class Update extends Action
return 'updateBooleanColumn'; return 'updateBooleanColumn';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_ATTRIBUTE_BOOLEAN;
}
public function __construct() public function __construct()
{ {
$this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_BOOLEAN);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH)
->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/boolean/:key') ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/boolean/:key')
@ -66,17 +69,8 @@ class Update extends Action
->callback([$this, 'action']); ->callback([$this, 'action']);
} }
public function action( public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?bool $default, ?string $newKey, UtopiaResponse $response, Database $dbForProject, Event $queueForEvents): void
string $databaseId, {
string $collectionId,
string $key,
?bool $required,
?bool $default,
?string $newKey,
UtopiaResponse $response,
Database $dbForProject,
Event $queueForEvents
): void {
$attribute = $this->updateAttribute( $attribute = $this->updateAttribute(
databaseId: $databaseId, databaseId: $databaseId,
collectionId: $collectionId, collectionId: $collectionId,

View file

@ -27,10 +27,13 @@ class Create extends Action
return 'createDatetimeAttribute'; return 'createDatetimeAttribute';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_ATTRIBUTE_DATETIME;
}
public function __construct() public function __construct()
{ {
$this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_DATETIME);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST)
->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/datetime') ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/datetime')
@ -67,18 +70,8 @@ class Create extends Action
->callback([$this, 'action']); ->callback([$this, 'action']);
} }
public function action( public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, bool $array, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents): void
string $databaseId, {
string $collectionId,
string $key,
?bool $required,
?string $default,
bool $array,
UtopiaResponse $response,
Database $dbForProject,
EventDatabase $queueForDatabase,
Event $queueForEvents
): void {
$attribute = $this->createAttribute( $attribute = $this->createAttribute(
$databaseId, $databaseId,
$collectionId, $collectionId,

View file

@ -27,10 +27,13 @@ class Update extends Action
return 'updateDatetimeAttribute'; return 'updateDatetimeAttribute';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_ATTRIBUTE_DATETIME;
}
public function __construct() public function __construct()
{ {
$this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_DATETIME);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH)
->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/datetime/:key') ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/datetime/:key')
@ -67,17 +70,8 @@ class Update extends Action
->callback([$this, 'action']); ->callback([$this, 'action']);
} }
public function action( public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, ?string $newKey, UtopiaResponse $response, Database $dbForProject, Event $queueForEvents): void
string $databaseId, {
string $collectionId,
string $key,
?bool $required,
?string $default,
?string $newKey,
UtopiaResponse $response,
Database $dbForProject,
Event $queueForEvents
): void {
$attribute = $this->updateAttribute( $attribute = $this->updateAttribute(
databaseId: $databaseId, databaseId: $databaseId,
collectionId: $collectionId, collectionId: $collectionId,

View file

@ -27,11 +27,14 @@ class Delete extends Action
return 'deleteAttribute'; return 'deleteAttribute';
} }
public function __construct() protected function getResponseModel(): string|array
{ {
// we should correctly & carefully set the context later. // we should correctly & carefully set the context later.
$this->setResponseModel(UtopiaResponse::MODEL_NONE); return UtopiaResponse::MODEL_NONE;
}
public function __construct()
{
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_DELETE) ->setHttpMethod(self::HTTP_REQUEST_METHOD_DELETE)
->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/:key') ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/:key')
@ -44,8 +47,8 @@ class Delete extends Action
->label('audits.resource', 'database/{request.databaseId}/collection/{request.collectionId}') ->label('audits.resource', 'database/{request.databaseId}/collection/{request.collectionId}')
->label('sdk', new Method( ->label('sdk', new Method(
namespace: 'databases', namespace: 'databases',
group: 'attributes', group: $this->getSdkGroup(),
name: 'deleteAttribute', name: self::getName(),
description: '/docs/references/databases/delete-attribute.md', description: '/docs/references/databases/delete-attribute.md',
auth: [AuthType::KEY], auth: [AuthType::KEY],
responses: [ responses: [
@ -66,15 +69,8 @@ class Delete extends Action
->callback([$this, 'action']); ->callback([$this, 'action']);
} }
public function action( public function action(string $databaseId, string $collectionId, string $key, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents): void
string $databaseId, {
string $collectionId,
string $key,
UtopiaResponse $response,
Database $dbForProject,
EventDatabase $queueForDatabase,
Event $queueForEvents
): void {
$db = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); $db = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));
if ($db->isEmpty()) { if ($db->isEmpty()) {
throw new Exception(Exception::DATABASE_NOT_FOUND); throw new Exception(Exception::DATABASE_NOT_FOUND);

View file

@ -27,10 +27,13 @@ class Create extends Action
return 'createEmailAttribute'; return 'createEmailAttribute';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_ATTRIBUTE_EMAIL;
}
public function __construct() public function __construct()
{ {
$this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_EMAIL);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST)
->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/email') ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/email')
@ -67,18 +70,8 @@ class Create extends Action
->callback([$this, 'action']); ->callback([$this, 'action']);
} }
public function action( public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, bool $array, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents): void
string $databaseId, {
string $collectionId,
string $key,
?bool $required,
?string $default,
bool $array,
UtopiaResponse $response,
Database $dbForProject,
EventDatabase $queueForDatabase,
Event $queueForEvents
): void {
$attribute = $this->createAttribute( $attribute = $this->createAttribute(
$databaseId, $databaseId,
$collectionId, $collectionId,

View file

@ -27,10 +27,13 @@ class Update extends Action
return 'updateEmailAttribute'; return 'updateEmailAttribute';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_ATTRIBUTE_EMAIL;
}
public function __construct() public function __construct()
{ {
$this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_EMAIL);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH)
->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/email/:key') ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/email/:key')
@ -67,17 +70,8 @@ class Update extends Action
->callback([$this, 'action']); ->callback([$this, 'action']);
} }
public function action( public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, ?string $newKey, UtopiaResponse $response, Database $dbForProject, Event $queueForEvents): void
string $databaseId, {
string $collectionId,
string $key,
?bool $required,
?string $default,
?string $newKey,
UtopiaResponse $response,
Database $dbForProject,
Event $queueForEvents
): void {
$attribute = $this->updateAttribute( $attribute = $this->updateAttribute(
databaseId: $databaseId, databaseId: $databaseId,
collectionId: $collectionId, collectionId: $collectionId,

View file

@ -29,10 +29,13 @@ class Create extends Action
return 'createEnumAttribute'; return 'createEnumAttribute';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_ATTRIBUTE_ENUM;
}
public function __construct() public function __construct()
{ {
$this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_ENUM);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST)
->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/enum') ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/enum')
@ -70,19 +73,8 @@ class Create extends Action
->callback([$this, 'action']); ->callback([$this, 'action']);
} }
public function action( public function action(string $databaseId, string $collectionId, string $key, array $elements, ?bool $required, ?string $default, bool $array, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents): void
string $databaseId, {
string $collectionId,
string $key,
array $elements,
?bool $required,
?string $default,
bool $array,
UtopiaResponse $response,
Database $dbForProject,
EventDatabase $queueForDatabase,
Event $queueForEvents
): void {
if (!is_null($default) && !\in_array($default, $elements, true)) { if (!is_null($default) && !\in_array($default, $elements, true)) {
throw new Exception($this->getInvalidValueException(), 'Default value not found in elements'); throw new Exception($this->getInvalidValueException(), 'Default value not found in elements');
} }

View file

@ -28,10 +28,13 @@ class Update extends Action
return 'updateEnumAttribute'; return 'updateEnumAttribute';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_ATTRIBUTE_ENUM;
}
public function __construct() public function __construct()
{ {
$this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_ENUM);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH)
->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/enum/:key') ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/enum/:key')
@ -69,18 +72,8 @@ class Update extends Action
->callback([$this, 'action']); ->callback([$this, 'action']);
} }
public function action( public function action(string $databaseId, string $collectionId, string $key, ?array $elements, ?bool $required, ?string $default, ?string $newKey, UtopiaResponse $response, Database $dbForProject, Event $queueForEvents): void
string $databaseId, {
string $collectionId,
string $key,
?array $elements,
?bool $required,
?string $default,
?string $newKey,
UtopiaResponse $response,
Database $dbForProject,
Event $queueForEvents
): void {
$attribute = $this->updateAttribute( $attribute = $this->updateAttribute(
databaseId: $databaseId, databaseId: $databaseId,
collectionId: $collectionId, collectionId: $collectionId,

View file

@ -29,10 +29,13 @@ class Create extends Action
return 'createFloatAttribute'; return 'createFloatAttribute';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_ATTRIBUTE_FLOAT;
}
public function __construct() public function __construct()
{ {
$this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_FLOAT);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST)
->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/float') ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/float')
@ -71,20 +74,8 @@ class Create extends Action
->callback([$this, 'action']); ->callback([$this, 'action']);
} }
public function action( public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?float $min, ?float $max, ?float $default, bool $array, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents): void
string $databaseId, {
string $collectionId,
string $key,
?bool $required,
?float $min,
?float $max,
?float $default,
bool $array,
UtopiaResponse $response,
Database $dbForProject,
EventDatabase $queueForDatabase,
Event $queueForEvents
): void {
$min ??= -PHP_FLOAT_MAX; $min ??= -PHP_FLOAT_MAX;
$max ??= PHP_FLOAT_MAX; $max ??= PHP_FLOAT_MAX;

View file

@ -27,10 +27,13 @@ class Update extends Action
return 'updateFloatAttribute'; return 'updateFloatAttribute';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_ATTRIBUTE_FLOAT;
}
public function __construct() public function __construct()
{ {
$this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_FLOAT);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH)
->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/float/:key') ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/float/:key')
@ -69,19 +72,8 @@ class Update extends Action
->callback([$this, 'action']); ->callback([$this, 'action']);
} }
public function action( public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?float $min, ?float $max, ?float $default, ?string $newKey, UtopiaResponse $response, Database $dbForProject, Event $queueForEvents): void
string $databaseId, {
string $collectionId,
string $key,
?bool $required,
?float $min,
?float $max,
?float $default,
?string $newKey,
UtopiaResponse $response,
Database $dbForProject,
Event $queueForEvents
): void {
$attribute = $this->updateAttribute( $attribute = $this->updateAttribute(
databaseId: $databaseId, databaseId: $databaseId,
collectionId: $collectionId, collectionId: $collectionId,

View file

@ -23,9 +23,9 @@ class Get extends Action
return 'getColumn'; return 'getColumn';
} }
public function __construct() protected function getResponseModel(): string|array
{ {
$this->setResponseModel([ return [
UtopiaResponse::MODEL_ATTRIBUTE_BOOLEAN, UtopiaResponse::MODEL_ATTRIBUTE_BOOLEAN,
UtopiaResponse::MODEL_ATTRIBUTE_INTEGER, UtopiaResponse::MODEL_ATTRIBUTE_INTEGER,
UtopiaResponse::MODEL_ATTRIBUTE_FLOAT, UtopiaResponse::MODEL_ATTRIBUTE_FLOAT,
@ -36,8 +36,11 @@ class Get extends Action
UtopiaResponse::MODEL_ATTRIBUTE_DATETIME, UtopiaResponse::MODEL_ATTRIBUTE_DATETIME,
UtopiaResponse::MODEL_ATTRIBUTE_RELATIONSHIP, UtopiaResponse::MODEL_ATTRIBUTE_RELATIONSHIP,
UtopiaResponse::MODEL_ATTRIBUTE_STRING, UtopiaResponse::MODEL_ATTRIBUTE_STRING,
]); ];
}
public function __construct()
{
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_GET) ->setHttpMethod(self::HTTP_REQUEST_METHOD_GET)
->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/:key') ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/:key')
@ -47,8 +50,8 @@ class Get extends Action
->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('resourceType', RESOURCE_TYPE_DATABASES)
->label('sdk', new Method( ->label('sdk', new Method(
namespace: 'databases', namespace: 'databases',
group: 'columns', group: $this->getSdkGroup(),
name: 'getColumn', name: self::getName(),
description: '/docs/references/databases/get-attribute.md', description: '/docs/references/databases/get-attribute.md',
auth: [AuthType::KEY], auth: [AuthType::KEY],
responses: [ responses: [
@ -66,13 +69,8 @@ class Get extends Action
->callback([$this, 'action']); ->callback([$this, 'action']);
} }
public function action( public function action(string $databaseId, string $tableId, string $key, UtopiaResponse $response, Database $dbForProject): void
string $databaseId, {
string $tableId,
string $key,
UtopiaResponse $response,
Database $dbForProject
): void {
$database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));
if ($database->isEmpty()) { if ($database->isEmpty()) {
throw new Exception(Exception::DATABASE_NOT_FOUND); throw new Exception(Exception::DATABASE_NOT_FOUND);

View file

@ -27,10 +27,13 @@ class Create extends Action
return 'createIpAttribute'; return 'createIpAttribute';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_ATTRIBUTE_IP;
}
public function __construct() public function __construct()
{ {
$this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_IP);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST)
->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/ip') ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/ip')
@ -67,18 +70,8 @@ class Create extends Action
->callback([$this, 'action']); ->callback([$this, 'action']);
} }
public function action( public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, bool $array, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents): void
string $databaseId, {
string $collectionId,
string $key,
?bool $required,
?string $default,
bool $array,
UtopiaResponse $response,
Database $dbForProject,
EventDatabase $queueForDatabase,
Event $queueForEvents
): void {
$attribute = $this->createAttribute( $attribute = $this->createAttribute(
$databaseId, $databaseId,
$collectionId, $collectionId,

View file

@ -27,10 +27,13 @@ class Update extends Action
return 'updateIpAttribute'; return 'updateIpAttribute';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_ATTRIBUTE_IP;
}
public function __construct() public function __construct()
{ {
$this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_IP);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH)
->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/ip/:key') ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/ip/:key')
@ -67,17 +70,8 @@ class Update extends Action
->callback([$this, 'action']); ->callback([$this, 'action']);
} }
public function action( public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, ?string $newKey, UtopiaResponse $response, Database $dbForProject, Event $queueForEvents): void
string $databaseId, {
string $collectionId,
string $key,
?bool $required,
?string $default,
?string $newKey,
UtopiaResponse $response,
Database $dbForProject,
Event $queueForEvents
): void {
$attribute = $this->updateAttribute( $attribute = $this->updateAttribute(
databaseId: $databaseId, databaseId: $databaseId,
collectionId: $collectionId, collectionId: $collectionId,

View file

@ -29,10 +29,13 @@ class Create extends Action
return 'createIntegerAttribute'; return 'createIntegerAttribute';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_ATTRIBUTE_INTEGER;
}
public function __construct() public function __construct()
{ {
$this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_INTEGER);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST)
->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/integer') ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/integer')
@ -71,20 +74,8 @@ class Create extends Action
->callback([$this, 'action']); ->callback([$this, 'action']);
} }
public function action( public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?int $min, ?int $max, ?int $default, bool $array, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents): void
string $databaseId, {
string $collectionId,
string $key,
?bool $required,
?int $min,
?int $max,
?int $default,
bool $array,
UtopiaResponse $response,
Database $dbForProject,
EventDatabase $queueForDatabase,
Event $queueForEvents
): void {
$min ??= \PHP_INT_MIN; $min ??= \PHP_INT_MIN;
$max ??= \PHP_INT_MAX; $max ??= \PHP_INT_MAX;

View file

@ -27,10 +27,13 @@ class Update extends Action
return 'updateIntegerAttribute'; return 'updateIntegerAttribute';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_ATTRIBUTE_INTEGER;
}
public function __construct() public function __construct()
{ {
$this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_INTEGER);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH)
->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/integer/:key') ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/integer/:key')
@ -69,19 +72,8 @@ class Update extends Action
->callback([$this, 'action']); ->callback([$this, 'action']);
} }
public function action( public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?int $min, ?int $max, ?int $default, ?string $newKey, UtopiaResponse $response, Database $dbForProject, Event $queueForEvents): void
string $databaseId, {
string $collectionId,
string $key,
?bool $required,
?int $min,
?int $max,
?int $default,
?string $newKey,
UtopiaResponse $response,
Database $dbForProject,
Event $queueForEvents
): void {
$attribute = $this->updateAttribute( $attribute = $this->updateAttribute(
databaseId: $databaseId, databaseId: $databaseId,
collectionId: $collectionId, collectionId: $collectionId,

View file

@ -29,10 +29,13 @@ class Create extends Action
return 'createRelationshipAttribute'; return 'createRelationshipAttribute';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_ATTRIBUTE_RELATIONSHIP;
}
public function __construct() public function __construct()
{ {
$this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_RELATIONSHIP);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST)
->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/relationship') ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/relationship')
@ -80,20 +83,8 @@ class Create extends Action
->callback([$this, 'action']); ->callback([$this, 'action']);
} }
public function action( public function action(string $databaseId, string $collectionId, string $relatedCollectionId, string $type, bool $twoWay, ?string $key, ?string $twoWayKey, string $onDelete, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents): void
string $databaseId, {
string $collectionId,
string $relatedCollectionId,
string $type,
bool $twoWay,
?string $key,
?string $twoWayKey,
string $onDelete,
UtopiaResponse $response,
Database $dbForProject,
EventDatabase $queueForDatabase,
Event $queueForEvents
): void {
$key ??= $relatedCollectionId; $key ??= $relatedCollectionId;
$twoWayKey ??= $collectionId; $twoWayKey ??= $collectionId;

View file

@ -25,10 +25,13 @@ class Update extends Action
return 'updateRelationshipAttribute'; return 'updateRelationshipAttribute';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_ATTRIBUTE_RELATIONSHIP;
}
public function __construct() public function __construct()
{ {
$this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_RELATIONSHIP);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH)
->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/:key/relationship') ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/:key/relationship')

View file

@ -30,10 +30,13 @@ class Create extends Action
return 'createStringAttribute'; return 'createStringAttribute';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_ATTRIBUTE_STRING;
}
public function __construct() public function __construct()
{ {
$this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_STRING);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST)
->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/string') ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/string')

View file

@ -29,10 +29,13 @@ class Update extends Action
return 'updateStringAttribute'; return 'updateStringAttribute';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_ATTRIBUTE_STRING;
}
public function __construct() public function __construct()
{ {
$this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_STRING);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH)
->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/string/:key') ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/string/:key')

View file

@ -27,10 +27,13 @@ class Create extends Action
return 'createUrlAttribute'; return 'createUrlAttribute';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_ATTRIBUTE_URL;
}
public function __construct() public function __construct()
{ {
$this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_URL);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST)
->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/url') ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/url')

View file

@ -27,10 +27,13 @@ class Update extends Action
return 'updateUrlAttribute'; return 'updateUrlAttribute';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_ATTRIBUTE_URL;
}
public function __construct() public function __construct()
{ {
$this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_URL);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH)
->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/url/:key') ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/url/:key')

View file

@ -28,10 +28,13 @@ class XList extends Action
return 'listAttributes'; return 'listAttributes';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_ATTRIBUTE_LIST;
}
public function __construct() public function __construct()
{ {
$this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_LIST);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_GET) ->setHttpMethod(self::HTTP_REQUEST_METHOD_GET)
->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes') ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes')
@ -67,8 +70,8 @@ class XList extends Action
throw new Exception(Exception::DATABASE_NOT_FOUND); throw new Exception(Exception::DATABASE_NOT_FOUND);
} }
$table = $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId); $collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId);
if ($table->isEmpty()) { if ($collection->isEmpty()) {
throw new Exception($this->getParentNotFoundException()); throw new Exception($this->getParentNotFoundException());
} }
@ -77,7 +80,7 @@ class XList extends Action
\array_push( \array_push(
$queries, $queries,
Query::equal('databaseInternalId', [$database->getInternalId()]), Query::equal('databaseInternalId', [$database->getInternalId()]),
Query::equal('collectionInternalId', [$table->getInternalId()]) Query::equal('collectionInternalId', [$collection->getInternalId()])
); );
$cursor = \array_filter( $cursor = \array_filter(
@ -96,7 +99,7 @@ class XList extends Action
$cursorDocument = Authorization::skip( $cursorDocument = Authorization::skip(
fn () => $dbForProject->find('attributes', [ fn () => $dbForProject->find('attributes', [
Query::equal('databaseInternalId', [$database->getInternalId()]), Query::equal('databaseInternalId', [$database->getInternalId()]),
Query::equal('collectionInternalId', [$table->getInternalId()]), Query::equal('collectionInternalId', [$collection->getInternalId()]),
Query::equal('key', [$attributeId]), Query::equal('key', [$attributeId]),
Query::limit(1), Query::limit(1),
]) ])
@ -104,7 +107,7 @@ class XList extends Action
if (empty($cursorDocument) || $cursorDocument[0]->isEmpty()) { if (empty($cursorDocument) || $cursorDocument[0]->isEmpty()) {
$type = ucfirst($this->getContext()); $type = ucfirst($this->getContext());
throw new Exception(Exception::GENERAL_CURSOR_NOT_FOUND, "$type '{$attributeId}' for the 'cursor' value not found."); throw new Exception(Exception::GENERAL_CURSOR_NOT_FOUND, "$type '$attributeId' for the 'cursor' value not found.");
} }
$cursor->setValue($cursorDocument[0]); $cursor->setValue($cursorDocument[0]);

View file

@ -18,6 +18,11 @@ abstract class Action extends UtopiaAction
*/ */
private ?string $context = DATABASE_COLLECTIONS_CONTEXT; private ?string $context = DATABASE_COLLECTIONS_CONTEXT;
/**
* Get the response model used in the SDK and HTTP responses.
*/
abstract protected function getResponseModel(): string;
/** /**
* Set the current API context. * Set the current API context.
* *
@ -50,11 +55,6 @@ abstract class Action extends UtopiaAction
return $this->getContext() . 'Id'; return $this->getContext() . 'Id';
} }
/**
* Get the response model used in the SDK and HTTP responses.
*/
abstract protected function getResponseModel(): string;
/** /**
* Determine if the current action is for the Collections API. * Determine if the current action is for the Collections API.
*/ */

View file

@ -25,10 +25,14 @@ class Create extends BooleanCreate
return 'createBooleanColumn'; return 'createBooleanColumn';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_COLUMN_BOOLEAN;
}
public function __construct() public function __construct()
{ {
$this->setContext(DATABASE_COLUMNS_CONTEXT); $this->setContext(DATABASE_COLUMNS_CONTEXT);
$this->setResponseModel(UtopiaResponse::MODEL_COLUMN_BOOLEAN);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST)

View file

@ -26,10 +26,14 @@ class Update extends BooleanUpdate
return 'updateBooleanColumn'; return 'updateBooleanColumn';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_COLUMN_BOOLEAN;
}
public function __construct() public function __construct()
{ {
$this->setContext(DATABASE_COLUMNS_CONTEXT); $this->setContext(DATABASE_COLUMNS_CONTEXT);
$this->setResponseModel(UtopiaResponse::MODEL_COLUMN_BOOLEAN);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH)

View file

@ -26,10 +26,14 @@ class Create extends DatetimeCreate
return 'createDatetimeColumn'; return 'createDatetimeColumn';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_COLUMN_DATETIME;
}
public function __construct() public function __construct()
{ {
$this->setContext(DATABASE_COLUMNS_CONTEXT); $this->setContext(DATABASE_COLUMNS_CONTEXT);
$this->setResponseModel(UtopiaResponse::MODEL_COLUMN_DATETIME);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST)

View file

@ -27,10 +27,14 @@ class Update extends DatetimeUpdate
return 'updateDatetimeColumn'; return 'updateDatetimeColumn';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_COLUMN_DATETIME;
}
public function __construct() public function __construct()
{ {
$this->setContext(DATABASE_COLUMNS_CONTEXT); $this->setContext(DATABASE_COLUMNS_CONTEXT);
$this->setResponseModel(UtopiaResponse::MODEL_COLUMN_DATETIME);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH)

View file

@ -25,13 +25,16 @@ class Delete extends AttributesDelete
return 'deleteColumn'; return 'deleteColumn';
} }
// parent handles multiple model types internally
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_NONE;
}
public function __construct() public function __construct()
{ {
$this->setContext(DATABASE_COLUMNS_CONTEXT); $this->setContext(DATABASE_COLUMNS_CONTEXT);
// parent action handles multiple model types internally
$this->setResponseModel(UtopiaResponse::MODEL_NONE);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_DELETE) ->setHttpMethod(self::HTTP_REQUEST_METHOD_DELETE)
->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/:key') ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/:key')

View file

@ -26,10 +26,14 @@ class Create extends EmailCreate
return 'createEmailColumn'; return 'createEmailColumn';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_COLUMN_EMAIL;
}
public function __construct() public function __construct()
{ {
$this->setContext(DATABASE_COLUMNS_CONTEXT); $this->setContext(DATABASE_COLUMNS_CONTEXT);
$this->setResponseModel(UtopiaResponse::MODEL_COLUMN_EMAIL);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST)

View file

@ -27,10 +27,14 @@ class Update extends EmailUpdate
return 'updateEmailColumn'; return 'updateEmailColumn';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_COLUMN_EMAIL;
}
public function __construct() public function __construct()
{ {
$this->setContext(DATABASE_COLUMNS_CONTEXT); $this->setContext(DATABASE_COLUMNS_CONTEXT);
$this->setResponseModel(UtopiaResponse::MODEL_COLUMN_EMAIL);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH)

View file

@ -27,10 +27,14 @@ class Create extends EnumCreate
return 'createEnumColumn'; return 'createEnumColumn';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_COLUMN_ENUM;
}
public function __construct() public function __construct()
{ {
$this->setContext(DATABASE_COLUMNS_CONTEXT); $this->setContext(DATABASE_COLUMNS_CONTEXT);
$this->setResponseModel(UtopiaResponse::MODEL_COLUMN_ENUM);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST)

View file

@ -28,10 +28,14 @@ class Update extends EnumUpdate
return 'updateEnumColumn'; return 'updateEnumColumn';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_COLUMN_ENUM;
}
public function __construct() public function __construct()
{ {
$this->setContext(DATABASE_COLUMNS_CONTEXT); $this->setContext(DATABASE_COLUMNS_CONTEXT);
$this->setResponseModel(UtopiaResponse::MODEL_COLUMN_ENUM);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH)

View file

@ -26,10 +26,14 @@ class Create extends FloatCreate
return 'createFloatColumn'; return 'createFloatColumn';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_COLUMN_FLOAT;
}
public function __construct() public function __construct()
{ {
$this->setContext(DATABASE_COLUMNS_CONTEXT); $this->setContext(DATABASE_COLUMNS_CONTEXT);
$this->setResponseModel(UtopiaResponse::MODEL_COLUMN_FLOAT);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST)

View file

@ -27,10 +27,14 @@ class Update extends FloatUpdate
return 'updateFloatColumn'; return 'updateFloatColumn';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_COLUMN_FLOAT;
}
public function __construct() public function __construct()
{ {
$this->setContext(DATABASE_COLUMNS_CONTEXT); $this->setContext(DATABASE_COLUMNS_CONTEXT);
$this->setResponseModel(UtopiaResponse::MODEL_COLUMN_FLOAT);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH)

View file

@ -22,11 +22,9 @@ class Get extends AttributesGet
return 'getColumn'; return 'getColumn';
} }
public function __construct() protected function getResponseModel(): string|array
{ {
$this->setContext(DATABASE_COLUMNS_CONTEXT); return [
$this->setResponseModel([
UtopiaResponse::MODEL_COLUMN_BOOLEAN, UtopiaResponse::MODEL_COLUMN_BOOLEAN,
UtopiaResponse::MODEL_COLUMN_INTEGER, UtopiaResponse::MODEL_COLUMN_INTEGER,
UtopiaResponse::MODEL_COLUMN_FLOAT, UtopiaResponse::MODEL_COLUMN_FLOAT,
@ -37,7 +35,12 @@ class Get extends AttributesGet
UtopiaResponse::MODEL_COLUMN_DATETIME, UtopiaResponse::MODEL_COLUMN_DATETIME,
UtopiaResponse::MODEL_COLUMN_RELATIONSHIP, UtopiaResponse::MODEL_COLUMN_RELATIONSHIP,
UtopiaResponse::MODEL_COLUMN_STRING, UtopiaResponse::MODEL_COLUMN_STRING,
]); ];
}
public function __construct()
{
$this->setContext(DATABASE_COLUMNS_CONTEXT);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_GET) ->setHttpMethod(self::HTTP_REQUEST_METHOD_GET)

View file

@ -26,10 +26,14 @@ class Create extends IPCreate
return 'createIpColumn'; return 'createIpColumn';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_COLUMN_IP;
}
public function __construct() public function __construct()
{ {
$this->setContext(DATABASE_COLUMNS_CONTEXT); $this->setContext(DATABASE_COLUMNS_CONTEXT);
$this->setResponseModel(UtopiaResponse::MODEL_COLUMN_IP);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST)

View file

@ -27,10 +27,14 @@ class Update extends IPUpdate
return 'updateIpColumn'; return 'updateIpColumn';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_COLUMN_IP;
}
public function __construct() public function __construct()
{ {
$this->setContext(DATABASE_COLUMNS_CONTEXT); $this->setContext(DATABASE_COLUMNS_CONTEXT);
$this->setResponseModel(UtopiaResponse::MODEL_COLUMN_IP);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH)

View file

@ -26,10 +26,14 @@ class Create extends IntegerCreate
return 'createIntegerColumn'; return 'createIntegerColumn';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_COLUMN_INTEGER;
}
public function __construct() public function __construct()
{ {
$this->setContext(DATABASE_COLUMNS_CONTEXT); $this->setContext(DATABASE_COLUMNS_CONTEXT);
$this->setResponseModel(UtopiaResponse::MODEL_COLUMN_INTEGER);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST)

View file

@ -27,10 +27,14 @@ class Update extends IntegerUpdate
return 'updateIntegerColumn'; return 'updateIntegerColumn';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_COLUMN_INTEGER;
}
public function __construct() public function __construct()
{ {
$this->setContext(DATABASE_COLUMNS_CONTEXT); $this->setContext(DATABASE_COLUMNS_CONTEXT);
$this->setResponseModel(UtopiaResponse::MODEL_COLUMN_INTEGER);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH)

View file

@ -26,10 +26,14 @@ class Create extends RelationshipCreate
return 'createRelationshipColumn'; return 'createRelationshipColumn';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_COLUMN_RELATIONSHIP;
}
public function __construct() public function __construct()
{ {
$this->setContext(DATABASE_COLUMNS_CONTEXT); $this->setContext(DATABASE_COLUMNS_CONTEXT);
$this->setResponseModel(UtopiaResponse::MODEL_COLUMN_RELATIONSHIP);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST)

View file

@ -25,15 +25,18 @@ class Update extends RelationshipUpdate
return 'updateRelationshipColumn'; return 'updateRelationshipColumn';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_COLUMN_RELATIONSHIP;
}
public function __construct() public function __construct()
{ {
$this->setContext(DATABASE_COLUMNS_CONTEXT); $this->setContext(DATABASE_COLUMNS_CONTEXT);
$this->setResponseModel(UtopiaResponse::MODEL_COLUMN_RELATIONSHIP);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH)
->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/:key/relationship') ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/:key/relationship')
->httpAlias('/v1/databases/:databaseId/collections/:tableId/attributes/:key/relationship')
->desc('Update relationship column') ->desc('Update relationship column')
->groups(['api', 'database', 'schema']) ->groups(['api', 'database', 'schema'])
->label('scope', 'collections.write') ->label('scope', 'collections.write')

View file

@ -28,10 +28,14 @@ class Create extends StringCreate
return 'createStringColumn'; return 'createStringColumn';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_COLUMN_STRING;
}
public function __construct() public function __construct()
{ {
$this->setContext(DATABASE_COLUMNS_CONTEXT); $this->setContext(DATABASE_COLUMNS_CONTEXT);
$this->setResponseModel(UtopiaResponse::MODEL_COLUMN_STRING);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST)

View file

@ -29,10 +29,14 @@ class Update extends StringUpdate
return 'updateStringColumn'; return 'updateStringColumn';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_COLUMN_STRING;
}
public function __construct() public function __construct()
{ {
$this->setContext(DATABASE_COLUMNS_CONTEXT); $this->setContext(DATABASE_COLUMNS_CONTEXT);
$this->setResponseModel(UtopiaResponse::MODEL_COLUMN_STRING);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH)

View file

@ -26,10 +26,14 @@ class Create extends URLCreate
return 'createUrlColumn'; return 'createUrlColumn';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_COLUMN_URL;
}
public function __construct() public function __construct()
{ {
$this->setContext(DATABASE_COLUMNS_CONTEXT); $this->setContext(DATABASE_COLUMNS_CONTEXT);
$this->setResponseModel(UtopiaResponse::MODEL_COLUMN_URL);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST)

View file

@ -27,15 +27,18 @@ class Update extends URLUpdate
return 'updateUrlColumn'; return 'updateUrlColumn';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_COLUMN_URL;
}
public function __construct() public function __construct()
{ {
$this->setContext(DATABASE_COLUMNS_CONTEXT); $this->setContext(DATABASE_COLUMNS_CONTEXT);
$this->setResponseModel(UtopiaResponse::MODEL_COLUMN_URL);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH)
->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/url/:key') ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/url/:key')
->httpAlias('/v1/databases/:databaseId/collections/:tableId/attributes/url/:key')
->desc('Update URL column') ->desc('Update URL column')
->groups(['api', 'database', 'schema']) ->groups(['api', 'database', 'schema'])
->label('scope', 'collections.write') ->label('scope', 'collections.write')

View file

@ -22,10 +22,14 @@ class XList extends AttributesXList
return 'listColumns'; return 'listColumns';
} }
protected function getResponseModel(): string|array
{
return UtopiaResponse::MODEL_COLUMN_LIST;
}
public function __construct() public function __construct()
{ {
$this->setContext(DATABASE_COLUMNS_CONTEXT); $this->setContext(DATABASE_COLUMNS_CONTEXT);
$this->setResponseModel(UtopiaResponse::MODEL_COLUMN_LIST);
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_GET) ->setHttpMethod(self::HTTP_REQUEST_METHOD_GET)

View file

@ -39,13 +39,13 @@ class Create extends Action
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST)
->setHttpPath('/v1/databases/:databaseId/tables/:tableId/indexes') ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/indexes')
->httpAlias('/v1/databases/:databaseId/collections/:tableId/indexes')
->desc('Create index') ->desc('Create index')
->groups(['api', 'database']) ->groups(['api', 'database'])
->label('event', 'databases.[databaseId].tables.[tableId].indexes.[indexId].create') ->label('event', 'databases.[databaseId].tables.[tableId].indexes.[indexId].create')
->label('scope', 'collections.write') ->label('scope', 'collections.write')
->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('resourceType', RESOURCE_TYPE_DATABASES)
->label('audits.event', 'index.create') ->label('audits.event', 'index.create')
// TODO: audits table or collections, check the context type if possible, move into another module.
->label('audits.resource', 'database/{request.databaseId}/table/{request.tableId}') ->label('audits.resource', 'database/{request.databaseId}/table/{request.tableId}')
->label('sdk', new Method( ->label('sdk', new Method(
namespace: 'databases', namespace: 'databases',

View file

@ -32,13 +32,13 @@ class Delete extends Action
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_DELETE) ->setHttpMethod(self::HTTP_REQUEST_METHOD_DELETE)
->setHttpPath('/v1/databases/:databaseId/tables/:tableId/indexes/:key') ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/indexes/:key')
->httpAlias('/v1/databases/:databaseId/collections/:tableId/indexes/:key')
->desc('Delete index') ->desc('Delete index')
->groups(['api', 'database']) ->groups(['api', 'database'])
->label('scope', 'collections.write') ->label('scope', 'collections.write')
->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('resourceType', RESOURCE_TYPE_DATABASES)
->label('event', 'databases.[databaseId].tables.[tableId].indexes.[indexId].update') ->label('event', 'databases.[databaseId].tables.[tableId].indexes.[indexId].update')
->label('audits.event', 'index.delete') ->label('audits.event', 'index.delete')
// TODO: audits table or collections, check the context type if possible
->label('audits.resource', 'database/{request.databaseId}/table/{request.tableId}') ->label('audits.resource', 'database/{request.databaseId}/table/{request.tableId}')
->label('sdk', new Method( ->label('sdk', new Method(
namespace: 'databases', namespace: 'databases',

View file

@ -30,7 +30,6 @@ class Get extends Action
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_GET) ->setHttpMethod(self::HTTP_REQUEST_METHOD_GET)
->setHttpPath('/v1/databases/:databaseId/tables/:tableId/indexes/:key') ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/indexes/:key')
->httpAlias('/v1/databases/:databaseId/collections/:tableId/indexes/:key')
->desc('Get index') ->desc('Get index')
->groups(['api', 'database']) ->groups(['api', 'database'])
->label('scope', 'collections.read') ->label('scope', 'collections.read')

View file

@ -34,7 +34,6 @@ class XList extends Action
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_GET) ->setHttpMethod(self::HTTP_REQUEST_METHOD_GET)
->setHttpPath('/v1/databases/:databaseId/tables/:tableId/indexes') ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/indexes')
->httpAlias('/v1/databases/:databaseId/collections/:tableId/indexes')
->desc('List indexes') ->desc('List indexes')
->groups(['api', 'database']) ->groups(['api', 'database'])
->label('scope', 'collections.read') ->label('scope', 'collections.read')

View file

@ -37,7 +37,6 @@ class Get extends DocumentGet
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_GET) ->setHttpMethod(self::HTTP_REQUEST_METHOD_GET)
->setHttpPath('/v1/databases/:databaseId/tables/:tableId/rows/:rowId') ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/rows/:rowId')
->httpAlias('/v1/databases/:databaseId/collections/:tableId/documents/:rowId')
->desc('Get row') ->desc('Get row')
->groups(['api', 'database']) ->groups(['api', 'database'])
->label('scope', 'documents.read') ->label('scope', 'documents.read')

View file

@ -38,7 +38,6 @@ class Update extends DocumentUpdate
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH)
->setHttpPath('/v1/databases/:databaseId/tables/:tableId/rows/:rowId') ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/rows/:rowId')
->httpAlias('/v1/databases/:databaseId/collections/:tableId/documents/:rowId')
->desc('Update row') ->desc('Update row')
->groups(['api', 'database']) ->groups(['api', 'database'])
->label('event', 'databases.[databaseId].tables.[tableId].rows.[rowId].update') ->label('event', 'databases.[databaseId].tables.[tableId].rows.[rowId].update')

View file

@ -37,7 +37,6 @@ class XList extends DocumentXList
$this $this
->setHttpMethod(self::HTTP_REQUEST_METHOD_GET) ->setHttpMethod(self::HTTP_REQUEST_METHOD_GET)
->setHttpPath('/v1/databases/:databaseId/tables/:tableId/rows') ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/rows')
->httpAlias('/v1/databases/:databaseId/collections/:tableId/documents')
->desc('List rows') ->desc('List rows')
->groups(['api', 'database']) ->groups(['api', 'database'])
->label('scope', 'documents.read') ->label('scope', 'documents.read')