Migrated project platforms to it's own collection
This commit is contained in:
parent
1d47ace629
commit
82085df58a
|
@ -511,7 +511,7 @@ $collections = [
|
|||
'required' => false,
|
||||
'default' => null,
|
||||
'array' => true,
|
||||
'filters' => ['json'],
|
||||
'filters' => ['subQueryProjectPlatforms'],
|
||||
],
|
||||
[
|
||||
'$id' => 'webhooks',
|
||||
|
@ -558,6 +558,111 @@ $collections = [
|
|||
],
|
||||
],
|
||||
|
||||
'projectsPlatforms' => [
|
||||
'$collection' => Database::METADATA,
|
||||
'$id' => 'projectsPlatforms',
|
||||
'name' => 'projectsPlatforms',
|
||||
'attributes' => [
|
||||
[
|
||||
'$id' => 'projectId',
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => Database::LENGTH_KEY,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
],
|
||||
[
|
||||
'$id' => 'type',
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => 16,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
],
|
||||
[
|
||||
'$id' => 'name',
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => 256,
|
||||
'signed' => true,
|
||||
'required' => true,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
],
|
||||
[
|
||||
'$id' => 'key',
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => Database::LENGTH_KEY,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
],
|
||||
[
|
||||
'$id' => 'store',
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => 256,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
],
|
||||
[
|
||||
'$id' => 'hostname',
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => 256,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
],
|
||||
[
|
||||
'$id' => 'dateCreated',
|
||||
'type' => Database::VAR_INTEGER,
|
||||
'format' => '',
|
||||
'size' => 0,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
],
|
||||
[
|
||||
'$id' => 'dateUpdated',
|
||||
'type' => Database::VAR_INTEGER,
|
||||
'format' => '',
|
||||
'size' => 0,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
],
|
||||
],
|
||||
'indexes' => [
|
||||
[
|
||||
'$id' => '_key_project',
|
||||
'type' => Database::INDEX_KEY,
|
||||
'attributes' => ['projectId'],
|
||||
'lengths' => [Database::LENGTH_KEY],
|
||||
'orders' => [Database::ORDER_ASC],
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
'users' => [
|
||||
'$collection' => Database::METADATA,
|
||||
'$id' => 'users',
|
||||
|
|
|
@ -1047,8 +1047,13 @@ App::post('/v1/projects/:projectId/platforms')
|
|||
throw new Exception('Project not found', 404);
|
||||
}
|
||||
|
||||
$teamId = $project->getAttribute("teamId");
|
||||
|
||||
$platform = new Document([
|
||||
'projectId' => $project->getId(),
|
||||
'$id' => $dbForConsole->getId(),
|
||||
'$read' => ['team:' . $teamId],
|
||||
'$write' => ['team:' . $teamId . '/owner', 'team:' . $teamId . '/developer'],
|
||||
'type' => $type,
|
||||
'name' => $name,
|
||||
'key' => $key,
|
||||
|
@ -1058,9 +1063,8 @@ App::post('/v1/projects/:projectId/platforms')
|
|||
'dateUpdated' => \time(),
|
||||
]);
|
||||
|
||||
$project = $dbForConsole->updateDocument('projects', $project->getId(), $project
|
||||
->setAttribute('platforms', $platform, Document::SET_TYPE_APPEND)
|
||||
);
|
||||
$dbForConsole->createDocument("projectsPlatforms", $platform);
|
||||
$dbForConsole->purgeDocument('projects', $project->getId());
|
||||
|
||||
$response->setStatusCode(Response::STATUS_CODE_CREATED);
|
||||
$response->dynamic($platform, Response::MODEL_PLATFORM);
|
||||
|
@ -1083,13 +1087,17 @@ App::get('/v1/projects/:projectId/platforms')
|
|||
/** @var Appwrite\Utopia\Response $response */
|
||||
/** @var Utopia\Database\Database $dbForConsole */
|
||||
|
||||
// TODO: Implement pagination
|
||||
|
||||
$project = $dbForConsole->getDocument('projects', $projectId);
|
||||
|
||||
if ($project->isEmpty()) {
|
||||
throw new Exception('Project not found', 404);
|
||||
}
|
||||
|
||||
$platforms = $project->getAttribute('platforms', []);
|
||||
$platforms = $dbForConsole->find('projectsPlatforms', [
|
||||
new Query('projectId', Query::TYPE_EQUAL, [$project->getId()])
|
||||
]);
|
||||
|
||||
$response->dynamic(new Document([
|
||||
'platforms' => $platforms,
|
||||
|
@ -1121,7 +1129,7 @@ App::get('/v1/projects/:projectId/platforms/:platformId')
|
|||
throw new Exception('Project not found', 404);
|
||||
}
|
||||
|
||||
$platform = $project->find('$id', $platformId, 'platforms');
|
||||
$platform = $dbForConsole->getDocument("projectsPlatforms", $platformId);
|
||||
|
||||
if (empty($platform) || !$platform instanceof Document) {
|
||||
throw new Exception('Platform not found', 404);
|
||||
|
@ -1158,7 +1166,7 @@ App::put('/v1/projects/:projectId/platforms/:platformId')
|
|||
throw new Exception('Project not found', 404);
|
||||
}
|
||||
|
||||
$platform = $project->find('$id', $platformId, 'platforms');
|
||||
$platform = $dbForConsole->getDocument("projectsPlatforms", $platformId);
|
||||
|
||||
if (empty($platform) || !$platform instanceof Document) {
|
||||
throw new Exception('Platform not found', 404);
|
||||
|
@ -1172,15 +1180,9 @@ App::put('/v1/projects/:projectId/platforms/:platformId')
|
|||
->setAttribute('hostname', $hostname)
|
||||
;
|
||||
|
||||
$project->findAndReplace('$id', $platform->getId(), $platform
|
||||
->setAttribute('name', $name)
|
||||
->setAttribute('dateUpdated', \time())
|
||||
->setAttribute('key', $key)
|
||||
->setAttribute('store', $store)
|
||||
->setAttribute('hostname', $hostname)
|
||||
, 'platforms');
|
||||
$dbForConsole->updateDocument('projectsPlatforms', $platform->getId(), $platform);
|
||||
|
||||
$dbForConsole->updateDocument('projects', $project->getId(), $project);
|
||||
$dbForConsole->purgeDocument('projects', $project->getId());
|
||||
|
||||
$response->dynamic($platform, Response::MODEL_PLATFORM);
|
||||
});
|
||||
|
@ -1208,11 +1210,13 @@ App::delete('/v1/projects/:projectId/platforms/:platformId')
|
|||
throw new Exception('Project not found', 404);
|
||||
}
|
||||
|
||||
if (!$project->findAndRemove('$id', $platformId, 'platforms')) {
|
||||
$deleteRecord = $dbForConsole->deleteDocument("projectsPlatforms", $platformId);
|
||||
|
||||
if($deleteRecord == false) {
|
||||
throw new Exception('Platform not found', 404);
|
||||
}
|
||||
|
||||
$dbForConsole->updateDocument('projects', $project->getId(), $project);
|
||||
$dbForConsole->purgeDocument('projects', $project->getId());
|
||||
|
||||
$response->noContent();
|
||||
});
|
||||
|
|
12
app/init.php
12
app/init.php
|
@ -200,6 +200,18 @@ Database::addFilter('subQueryIndexes',
|
|||
}
|
||||
);
|
||||
|
||||
Database::addFilter('subQueryProjectPlatforms',
|
||||
function($value) {
|
||||
return null;
|
||||
},
|
||||
function($value, Document $document, Database $database) {
|
||||
return $database
|
||||
->find('projectsPlatforms', [
|
||||
new Query('collectionId', Query::TYPE_EQUAL, [$document->getId()])
|
||||
], 100, 0, []);
|
||||
}
|
||||
);
|
||||
|
||||
Database::addFilter('encrypt',
|
||||
function($value) {
|
||||
$key = App::getEnv('_APP_OPENSSL_KEY_V1');
|
||||
|
|
Loading…
Reference in a new issue