Remove functions.php

This commit is contained in:
Khushboo Verma 2025-02-27 23:42:43 +05:30
parent 26a822e4b2
commit 4afd9771c6
6 changed files with 10 additions and 18 deletions

View file

@ -1,4 +0,0 @@
<?php
include_once __DIR__ . '/../shared/api.php';

View file

@ -63,11 +63,11 @@ class Delete extends Action
->callback([$this, 'action']); ->callback([$this, 'action']);
} }
public function action(string $siteId, string $deploymentId, Response $response, Database $dbForProject, DeleteEvent $queueForDeletes, Event $queueForEvents, Device $deviceForSites) public function action(string $functionId, string $deploymentId, Response $response, Database $dbForProject, DeleteEvent $queueForDeletes, Event $queueForEvents, Device $deviceForFunctions)
{ {
$site = $dbForProject->getDocument('sites', $siteId); $function = $dbForProject->getDocument('functions', $functionId);
if ($site->isEmpty()) { if ($function->isEmpty()) {
throw new Exception(Exception::SITE_NOT_FOUND); throw new Exception(Exception::FUNCTION_NOT_FOUND);
} }
$deployment = $dbForProject->getDocument('deployments', $deploymentId); $deployment = $dbForProject->getDocument('deployments', $deploymentId);
@ -75,7 +75,7 @@ class Delete extends Action
throw new Exception(Exception::DEPLOYMENT_NOT_FOUND); throw new Exception(Exception::DEPLOYMENT_NOT_FOUND);
} }
if ($deployment->getAttribute('resourceId') !== $site->getId()) { if ($deployment->getAttribute('resourceId') !== $function->getId()) {
throw new Exception(Exception::DEPLOYMENT_NOT_FOUND); throw new Exception(Exception::DEPLOYMENT_NOT_FOUND);
} }
@ -84,20 +84,20 @@ class Delete extends Action
} }
if (!empty($deployment->getAttribute('path', ''))) { if (!empty($deployment->getAttribute('path', ''))) {
if (!($deviceForSites->delete($deployment->getAttribute('path', '')))) { if (!($deviceForFunctions->delete($deployment->getAttribute('path', '')))) {
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove deployment from storage'); throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove deployment from storage');
} }
} }
if ($site->getAttribute('deployment') === $deployment->getId()) { // Reset site deployment if ($function->getAttribute('deployment') === $deployment->getId()) { // Reset function deployment
$site = $dbForProject->updateDocument('sites', $site->getId(), new Document(array_merge($site->getArrayCopy(), [ $function = $dbForProject->updateDocument('functions', $function->getId(), new Document(array_merge($function->getArrayCopy(), [
'deploymentId' => '', 'deployment' => '',
'deploymentInternalId' => '', 'deploymentInternalId' => '',
]))); ])));
} }
$queueForEvents $queueForEvents
->setParam('siteId', $site->getId()) ->setParam('functionId', $function->getId())
->setParam('deploymentId', $deployment->getId()); ->setParam('deploymentId', $deployment->getId());
$queueForDeletes $queueForDeletes

View file

@ -29,7 +29,6 @@ class Get extends Base
->setHttpMethod(Action::HTTP_REQUEST_METHOD_GET) ->setHttpMethod(Action::HTTP_REQUEST_METHOD_GET)
->setHttpPath('/v1/functions/templates/:templateId') ->setHttpPath('/v1/functions/templates/:templateId')
->desc('Get function template') ->desc('Get function template')
->groups(['api'])
->label('scope', 'public') ->label('scope', 'public')
->label('resourceType', RESOURCE_TYPE_FUNCTIONS) ->label('resourceType', RESOURCE_TYPE_FUNCTIONS)
->label('sdk', new Method( ->label('sdk', new Method(

View file

@ -30,7 +30,6 @@ class XList extends Base
->setHttpMethod(Action::HTTP_REQUEST_METHOD_GET) ->setHttpMethod(Action::HTTP_REQUEST_METHOD_GET)
->setHttpPath('/v1/functions/templates') ->setHttpPath('/v1/functions/templates')
->desc('List function templates') ->desc('List function templates')
->groups(['api'])
->label('scope', 'public') ->label('scope', 'public')
->label('resourceType', RESOURCE_TYPE_FUNCTIONS) ->label('resourceType', RESOURCE_TYPE_FUNCTIONS)
->label('sdk', new Method( ->label('sdk', new Method(

View file

@ -29,7 +29,6 @@ class Get extends Base
->setHttpMethod(Action::HTTP_REQUEST_METHOD_GET) ->setHttpMethod(Action::HTTP_REQUEST_METHOD_GET)
->setHttpPath('/v1/sites/templates/:templateId') ->setHttpPath('/v1/sites/templates/:templateId')
->desc('Get site template') ->desc('Get site template')
->groups(['api'])
->label('scope', 'public') ->label('scope', 'public')
->label('sdk', new Method( ->label('sdk', new Method(
namespace: 'sites', namespace: 'sites',

View file

@ -30,7 +30,6 @@ class XList extends Base
->setHttpMethod(Action::HTTP_REQUEST_METHOD_GET) ->setHttpMethod(Action::HTTP_REQUEST_METHOD_GET)
->setHttpPath('/v1/sites/templates') ->setHttpPath('/v1/sites/templates')
->desc('List templates') ->desc('List templates')
->groups(['api'])
->label('scope', 'public') ->label('scope', 'public')
->label('sdk', new Method( ->label('sdk', new Method(
namespace: 'sites', namespace: 'sites',