Add DeleteEntity class and integrate it into Method for handling entity deletion requests
This commit is contained in:
parent
14effd7ef8
commit
6e68877a08
2 changed files with 54 additions and 1 deletions
|
@ -8,6 +8,7 @@
|
|||
use FederationServer\Methods\Attachments\UploadAttachment;
|
||||
use FederationServer\Methods\Audit\ListAuditLogs;
|
||||
use FederationServer\Methods\Audit\ViewAuditEntry;
|
||||
use FederationServer\Methods\Entities\DeleteEntity;
|
||||
use FederationServer\Methods\Entities\GetEntity;
|
||||
use FederationServer\Methods\Entities\ListEntities;
|
||||
use FederationServer\Methods\Entities\PushEntity;
|
||||
|
@ -42,6 +43,7 @@
|
|||
case MANAGE_CLIENT_PERMISSION;
|
||||
|
||||
case GET_ENTITY;
|
||||
case DELETE_ENTITY;
|
||||
case LIST_ENTITIES;
|
||||
case QUERY_ENTITY;
|
||||
case PUSH_ENTITY;
|
||||
|
@ -86,6 +88,9 @@
|
|||
case self::GET_ENTITY:
|
||||
GetEntity::handleRequest();
|
||||
break;
|
||||
case self::DELETE_ENTITY:
|
||||
DeleteEntity::handleRequest();
|
||||
break;
|
||||
case self::PUSH_ENTITY:
|
||||
PushEntity::handleRequest();
|
||||
break;
|
||||
|
@ -146,8 +151,9 @@
|
|||
|
||||
$path === '/entities' && $requestMethod === 'GET' => Method::LIST_ENTITIES,
|
||||
$path === '/entities' && $requestMethod === 'POST' => Method::PUSH_ENTITY,
|
||||
preg_match('#^/entities/([a-fA-F0-9\-]{36,})$#', $path) && $requestMethod === 'GET' => Method::GET_ENTITY,
|
||||
$path === '/entities/query' && $requestMethod === 'POST' => Method::QUERY_ENTITY,
|
||||
preg_match('#^/entities/([a-fA-F0-9\-]{36,})$#', $path) && $requestMethod === 'GET' => Method::GET_ENTITY,
|
||||
preg_match('#^/entities/([a-fA-F0-9\-]{36,})$#', $path) && $requestMethod === 'DELETE' => Method::DELETE_ENTITY,
|
||||
|
||||
$path === '/operators' && $requestMethod === 'GET' => Method::LIST_OPERATORS,
|
||||
$path === '/operators' && $requestMethod === 'POST' => Method::CREATE_OPERATOR,
|
||||
|
|
47
src/FederationServer/Methods/Entities/DeleteEntity.php
Normal file
47
src/FederationServer/Methods/Entities/DeleteEntity.php
Normal file
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
namespace FederationServer\Methods\Entities;
|
||||
|
||||
use FederationServer\Classes\Managers\EntitiesManager;
|
||||
use FederationServer\Classes\RequestHandler;
|
||||
use FederationServer\Classes\Validate;
|
||||
use FederationServer\Exceptions\DatabaseOperationException;
|
||||
use FederationServer\Exceptions\RequestException;
|
||||
use FederationServer\FederationServer;
|
||||
|
||||
class DeleteEntity extends RequestHandler
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function handleRequest(): void
|
||||
{
|
||||
if(!preg_match('#^/entities/([a-fA-F0-9\-]{36,})$#', FederationServer::getPath(), $matches))
|
||||
{
|
||||
throw new RequestException('Bad Request: Entity UUID is required', 400);
|
||||
}
|
||||
|
||||
$entityUuid = $matches[1];
|
||||
if(!$entityUuid || !Validate::uuid($entityUuid))
|
||||
{
|
||||
throw new RequestException('Bad Request: Entity UUID is required', 400);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if(!EntitiesManager::entityExistsByUuid($entityUuid))
|
||||
{
|
||||
throw new RequestException('Not Found: Entity does not exist', 404);
|
||||
}
|
||||
|
||||
EntitiesManager::deleteEntity($entityUuid);
|
||||
}
|
||||
catch (DatabaseOperationException $e)
|
||||
{
|
||||
throw new RequestException('Internal Server Error: Unable to delete entity', 500, $e);
|
||||
}
|
||||
|
||||
self::successResponse();
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue