diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index b42e495fb..27fe597e1 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -345,7 +345,7 @@ App::put('/v1/functions/:functionId') $response->dynamic($function, Response::MODEL_FUNCTION); }); -App::patch('/v1/functions/:functionId/deployment') +App::patch('/v1/functions/:functionId/deployments/:deploymentId') ->groups(['api', 'functions']) ->desc('Update Function Deployment') ->label('scope', 'functions.write') @@ -358,17 +358,17 @@ App::patch('/v1/functions/:functionId/deployment') ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_FUNCTION) ->param('functionId', '', new UID(), 'Function ID.') - ->param('deployment', '', new UID(), 'Deployment ID.') + ->param('deploymentId', '', new UID(), 'Deployment ID.') ->inject('response') ->inject('dbForProject') ->inject('project') - ->action(function ($functionId, $deployment, $response, $dbForProject, $project) { + ->action(function ($functionId, $deploymentId, $response, $dbForProject, $project) { /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Database\Database $dbForProject */ /** @var Utopia\Database\Document $project */ $function = $dbForProject->getDocument('functions', $functionId); - $deployment = $dbForProject->getDocument('deployments', $deployment); + $deployment = $dbForProject->getDocument('deployments', $deploymentId); $build = $dbForProject->getDocument('builds', $deployment->getAttribute('buildId', '')); if ($function->isEmpty()) { @@ -984,7 +984,7 @@ App::get('/v1/functions/:functionId/executions/:executionId') $response->dynamic($execution, Response::MODEL_EXECUTION); }); -App::post('/v1/builds/:buildId') +App::post('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId') ->groups(['api', 'functions']) ->desc('Retry Build') ->label('scope', 'functions.write') @@ -995,15 +995,28 @@ App::post('/v1/builds/:buildId') ->label('sdk.description', '/docs/references/functions/retry-build.md') ->label('sdk.response.code', Response::STATUS_CODE_NOCONTENT) ->label('sdk.response.model', Response::MODEL_NONE) + ->param('functionId', '', new UID(), 'Function ID.') + ->param('deploymentId', '', new UID(), 'Deployment ID.') ->param('buildId', '', new UID(), 'Build unique ID.') ->inject('response') ->inject('dbForProject') ->inject('project') - ->action(function ($buildId, $response, $dbForProject, $project) { + ->action(function ($functionId, $deploymentId, $buildId, $response, $dbForProject, $project) { /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Database\Database $dbForProject */ /** @var Utopia\Database\Document $project */ + $function = $dbForProject->getDocument('functions', $functionId); + $deployment = $dbForProject->getDocument('deployments', $deploymentId); + + if ($function->isEmpty()) { + throw new Exception('Function not found', 404); + } + + if ($deployment->isEmpty()) { + throw new Exception('Deployment not found', 404); + } + $build = Authorization::skip(fn() => $dbForProject->getDocument('builds', $buildId)); if ($build->isEmpty()) { diff --git a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php index 3255caf2a..26e41542f 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php @@ -89,15 +89,11 @@ class FunctionsCustomClientTest extends Scope // Wait for deployment to be built. sleep(10); - $function = $this->client->call(Client::METHOD_PATCH, '/functions/'.$function['body']['$id'].'/deployment', [ + $function = $this->client->call(Client::METHOD_PATCH, '/functions/'.$function['body']['$id'].'/deployments/'.$deploymentId, [ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'], - ], [ - 'deployment' => $deploymentId, - ]); - - // var_dump($function); + ], []); $this->assertEquals(200, $function['headers']['status-code']); @@ -176,13 +172,11 @@ class FunctionsCustomClientTest extends Scope $this->assertEquals(201, $deployment['headers']['status-code']); - $function = $this->client->call(Client::METHOD_PATCH, '/functions/'.$functionId.'/deployment', [ + $function = $this->client->call(Client::METHOD_PATCH, '/functions/'.$functionId.'/deployments/'.$deploymentId, [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, 'x-appwrite-key' => $apikey, - ], [ - 'deployment' => $deploymentId, - ]); + ], []); $this->assertEquals(200, $function['headers']['status-code']); @@ -360,13 +354,11 @@ class FunctionsCustomClientTest extends Scope // Wait for deployment to be built. sleep(10); - $function = $this->client->call(Client::METHOD_PATCH, '/functions/'.$functionId.'/deployment', [ + $function = $this->client->call(Client::METHOD_PATCH, '/functions/'.$functionId.'/deployments/'.$deploymentId, [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, 'x-appwrite-key' => $apikey, - ], [ - 'deployment' => $deploymentId, - ]); + ], []); $this->assertEquals(200, $function['headers']['status-code']); diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 9bb2a296e..deb1b5b20 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -310,12 +310,10 @@ class FunctionsCustomServerTest extends Scope /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_PATCH, '/functions/'.$data['functionId'].'/deployment', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/functions/'.$data['functionId'].'/deployments/'.$data['deploymentId'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'deployment' => $data['deploymentId'], - ]); + ], $this->getHeaders()), []); $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); @@ -687,13 +685,10 @@ class FunctionsCustomServerTest extends Scope // Allow build step to run sleep(10); - $deployment = $this->client->call(Client::METHOD_PATCH, '/functions/'.$functionId.'/deployment', array_merge([ + $deployment = $this->client->call(Client::METHOD_PATCH, '/functions/'.$functionId.'/deployments/'.$deploymentId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'functionId' => $functionId, - 'deployment' => $deploymentId, - ]); + ], $this->getHeaders()), []); $this->assertEquals(200, $deployment['headers']['status-code']); @@ -779,12 +774,10 @@ class FunctionsCustomServerTest extends Scope // Allow build step to run sleep(10); - $deployment = $this->client->call(Client::METHOD_PATCH, '/functions/'.$functionId.'/deployment', array_merge([ + $deployment = $this->client->call(Client::METHOD_PATCH, '/functions/'.$functionId.'/deployments/'.$deploymentId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'deployment' => $deploymentId, - ]); + ], $this->getHeaders()), []); $this->assertEquals(200, $deployment['headers']['status-code']); diff --git a/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php b/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php index 8f8e467ea..a12272398 100644 --- a/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php +++ b/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php @@ -1002,13 +1002,11 @@ class RealtimeCustomClientTest extends Scope // Wait for deployment to be built. sleep(5); - $response = $this->client->call(Client::METHOD_PATCH, '/functions/'.$functionId.'/deployment', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/functions/'.$functionId.'/deployments/'.$deploymentId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] - ]), [ - 'deployment' => $deploymentId, - ]); + ]), []); $this->assertEquals($response['headers']['status-code'], 200); $this->assertNotEmpty($response['body']['$id']); diff --git a/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php b/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php index 94db8cc15..fe3efa1c3 100644 --- a/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php +++ b/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php @@ -434,12 +434,10 @@ class WebhooksCustomServerTest extends Scope /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_PATCH, '/functions/'.$data['functionId'].'/deployment', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/functions/'.$data['functionId'].'/deployments/'.$data['deploymentId'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'deployment' => $data['deploymentId'], - ]); + ], $this->getHeaders()), []); $this->assertEquals($response['headers']['status-code'], 200); $this->assertNotEmpty($response['body']['$id']);