Browse Source

some work on the DELETE query

dev
Cerys 4 weeks ago
parent
commit
bfc699be33
  1. 31
      src/QueryBuilder/DeleteQuery/DeleteQuery.php
  2. 35
      src/QueryBuilder/DeleteQuery/DeleteQueryBuilder.php
  3. 10
      src/QueryBuilder/DeleteQuery/DeleteQueryResponse.php
  4. 5
      src/QueryBuilder/QueryBuilder.php
  5. 4
      src/QueryBuilder/QueryBuilderTrait.php
  6. 22
      tests/QueryBuilderDeleteTest.php

31
src/QueryBuilder/DeleteQuery/DeleteQuery.php

@ -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);
}
}

35
src/QueryBuilder/DeleteQuery/DeleteQueryBuilder.php

@ -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);
}
}

10
src/QueryBuilder/DeleteQuery/DeleteQueryResponse.php

@ -0,0 +1,10 @@
<?php
namespace Darksparrow\DeegraphInteractions\QueryBuilder\DeleteQuery;
class DeleteQueryResponse
{
public function __construct(array $deegraphResponse)
{
}
}

5
src/QueryBuilder/QueryBuilder.php

@ -2,6 +2,7 @@
namespace Darksparrow\DeegraphInteractions\QueryBuilder; namespace Darksparrow\DeegraphInteractions\QueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\DeleteQuery\DeleteQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\DirectoryQuery\DirectoryQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\DirectoryQuery\DirectoryQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\InsertQuery\InsertQuery; use Darksparrow\DeegraphInteractions\QueryBuilder\InsertQuery\InsertQuery;
use Darksparrow\DeegraphInteractions\QueryBuilder\LinkQuery\LinkQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\LinkQuery\LinkQueryBuilder;
@ -45,4 +46,8 @@ final class QueryBuilder
{ {
return new UnlinkQueryBuilder(); return new UnlinkQueryBuilder();
} }
public static function Delete(): DeleteQueryBuilder
{
return new DeleteQueryBuilder();
}
} }

4
src/QueryBuilder/QueryBuilderTrait.php

@ -5,6 +5,7 @@ namespace Darksparrow\DeegraphInteractions\QueryBuilder;
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderRequiredField; use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderRequiredField;
use Darksparrow\DeegraphInteractions\Exceptions\QueryBuilderConflictingFieldAlreadyExistsException; use Darksparrow\DeegraphInteractions\Exceptions\QueryBuilderConflictingFieldAlreadyExistsException;
use Darksparrow\DeegraphInteractions\Exceptions\QueryBuilderInvalidInputException; use Darksparrow\DeegraphInteractions\Exceptions\QueryBuilderInvalidInputException;
use Darksparrow\DeegraphInteractions\QueryBuilder\DeleteQuery\DeleteQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\DirectoryQuery\DirectoryQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\DirectoryQuery\DirectoryQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\InsertQuery\InsertQuery; use Darksparrow\DeegraphInteractions\QueryBuilder\InsertQuery\InsertQuery;
use Darksparrow\DeegraphInteractions\QueryBuilder\InsertQuery\InsertQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\InsertQuery\InsertQueryBuilder;
@ -42,7 +43,8 @@ trait QueryBuilderTrait
public function ValidateValues( public function ValidateValues(
DirectoryQueryBuilder DeleteQueryBuilder
|DirectoryQueryBuilder
|InsertQueryBuilder |InsertQueryBuilder
|LinkQueryBuilder |LinkQueryBuilder
|PermissionQueryBuilder |PermissionQueryBuilder

22
tests/QueryBuilderDeleteTest.php

@ -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…
Cancel
Save