Cerys
4 weeks ago
6 changed files with 106 additions and 1 deletions
@ -0,0 +1,31 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace Darksparrow\DeegraphInteractions\QueryBuilder\DeleteQuery; |
||||
|
|
||||
|
use Darksparrow\DeegraphInteractions\Core\DeegraphServer; |
||||
|
use Darksparrow\DeegraphInteractions\QueryBuilder\DirectoryQuery\DirectoryQueryResponse; |
||||
|
|
||||
|
class DeleteQuery |
||||
|
{ |
||||
|
protected string $QueryString; |
||||
|
|
||||
|
public function __construct(string $queryString) |
||||
|
{ |
||||
|
$this->QueryString = $queryString; |
||||
|
} |
||||
|
public function __toString() |
||||
|
{ |
||||
|
return $this->QueryString; |
||||
|
} |
||||
|
|
||||
|
public function RunQuery(DeegraphServer $server): DeleteQueryResponse |
||||
|
{ |
||||
|
$response = $server->RunRawRequest( |
||||
|
endpoint: "/api/v1/@query", |
||||
|
method: "POST", |
||||
|
body: $this->QueryString |
||||
|
); |
||||
|
$temp = json_decode($response, true); |
||||
|
return new DeleteQueryResponse($temp); |
||||
|
} |
||||
|
} |
@ -0,0 +1,35 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace Darksparrow\DeegraphInteractions\QueryBuilder\DeleteQuery; |
||||
|
|
||||
|
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderQuery; |
||||
|
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderRequiredField; |
||||
|
use Darksparrow\DeegraphInteractions\QueryBuilder\DirectoryQuery\DirectoryQuery; |
||||
|
use Darksparrow\DeegraphInteractions\QueryBuilder\DirectoryQuery\DirectoryQueryBuilder; |
||||
|
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilderTrait; |
||||
|
|
||||
|
#[QueryBuilderQuery] |
||||
|
class DeleteQueryBuilder |
||||
|
{ |
||||
|
use QueryBuilderTrait; |
||||
|
|
||||
|
#[QueryBuilderRequiredField] |
||||
|
protected string $RelativePath = ""; |
||||
|
|
||||
|
|
||||
|
public function RelativePath(string $relativePath): DeleteQueryBuilder |
||||
|
{ |
||||
|
self::ValidateDeegraphPath(target: $relativePath); |
||||
|
$this->RelativePath = $relativePath; |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
public function Build(): DeleteQuery |
||||
|
{ |
||||
|
self::ValidateValues(target: $this); |
||||
|
|
||||
|
$builder = "DELETE " . $this->RelativePath; |
||||
|
|
||||
|
return new DeleteQuery(queryString: $builder); |
||||
|
} |
||||
|
} |
@ -0,0 +1,10 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace Darksparrow\DeegraphInteractions\QueryBuilder\DeleteQuery; |
||||
|
|
||||
|
class DeleteQueryResponse |
||||
|
{ |
||||
|
public function __construct(array $deegraphResponse) |
||||
|
{ |
||||
|
} |
||||
|
} |
@ -0,0 +1,22 @@ |
|||||
|
<?php |
||||
|
|
||||
|
|
||||
|
use Darksparrow\DeegraphInteractions\Exceptions\QueryBuilderConflictingFieldAlreadyExistsException; |
||||
|
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilder; |
||||
|
use PHPUnit\Framework\TestCase; |
||||
|
|
||||
|
final class QueryBuilderDeleteTest extends TestCase |
||||
|
{ |
||||
|
private string $TestUUID = "{00000000-0000-0000-0000-000000000000}"; |
||||
|
|
||||
|
public function test0() |
||||
|
{ |
||||
|
$query = QueryBuilder::Delete() |
||||
|
->RelativePath($this->TestUUID) |
||||
|
->Build(); |
||||
|
self::assertEquals( |
||||
|
expected: "DELETE {$this->TestUUID}", |
||||
|
actual: $query |
||||
|
); |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue