Browse Source

some work on the UNLINK query

dev
Cerys 4 weeks ago
parent
commit
5dd2f95891
  1. 5
      src/QueryBuilder/QueryBuilder.php
  2. 3
      src/QueryBuilder/QueryBuilderTrait.php
  3. 31
      src/QueryBuilder/UnlinkQuery/UnlinkQuery.php
  4. 65
      src/QueryBuilder/UnlinkQuery/UnlinkQueryBuilder.php
  5. 10
      src/QueryBuilder/UnlinkQuery/UnlinkQueryResponse.php
  6. 49
      tests/QueryBuilderUnlinkTest.php

5
src/QueryBuilder/QueryBuilder.php

@ -9,6 +9,7 @@ use Darksparrow\DeegraphInteractions\QueryBuilder\PermissionsQuery\PermissionQue
use Darksparrow\DeegraphInteractions\QueryBuilder\PutQuery\PutQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\PutQuery\PutQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\ReferencesQuery\ReferencesQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\ReferencesQuery\ReferencesQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\SelectQuery\SelectQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\SelectQuery\SelectQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\UnlinkQuery\UnlinkQueryBuilder;
final class QueryBuilder final class QueryBuilder
{ {
@ -40,4 +41,8 @@ final class QueryBuilder
{ {
return new LinkQueryBuilder(); return new LinkQueryBuilder();
} }
public static function Unlink(): UnlinkQueryBuilder
{
return new UnlinkQueryBuilder();
}
} }

3
src/QueryBuilder/QueryBuilderTrait.php

@ -13,6 +13,8 @@ use Darksparrow\DeegraphInteractions\QueryBuilder\PermissionsQuery\PermissionQue
use Darksparrow\DeegraphInteractions\QueryBuilder\PutQuery\PutQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\PutQuery\PutQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\ReferencesQuery\ReferencesQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\ReferencesQuery\ReferencesQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\SelectQuery\SelectQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\SelectQuery\SelectQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\UnlinkQuery\UnlinkQuery;
use Darksparrow\DeegraphInteractions\QueryBuilder\UnlinkQuery\UnlinkQueryBuilder;
use Darksparrow\DeegraphInteractions\Utilities\RelativePath; use Darksparrow\DeegraphInteractions\Utilities\RelativePath;
use ReflectionClass; use ReflectionClass;
@ -47,6 +49,7 @@ trait QueryBuilderTrait
|PutQueryBuilder |PutQueryBuilder
|ReferencesQueryBuilder |ReferencesQueryBuilder
|SelectQueryBuilder |SelectQueryBuilder
|UnlinkQueryBuilder
$target $target
): void ): void
{ {

31
src/QueryBuilder/UnlinkQuery/UnlinkQuery.php

@ -0,0 +1,31 @@
<?php
namespace Darksparrow\DeegraphInteractions\QueryBuilder\UnlinkQuery;
use Darksparrow\DeegraphInteractions\Core\DeegraphServer;
use Darksparrow\DeegraphInteractions\QueryBuilder\LinkQuery\LinkQueryResponse;
class UnlinkQuery
{
protected string $QueryString;
public function __construct(string $queryString)
{
$this->QueryString = $queryString;
}
public function __toString()
{
return $this->QueryString;
}
public function RunQuery(DeegraphServer $server): UnlinkQueryResponse
{
$response = $server->RunRawRequest(
endpoint: "/api/v1/@query",
method: "POST",
body: $this->QueryString
);
$temp = json_decode($response, true);
return new UnlinkQueryResponse($temp);
}
}

65
src/QueryBuilder/UnlinkQuery/UnlinkQueryBuilder.php

@ -0,0 +1,65 @@
<?php
namespace Darksparrow\DeegraphInteractions\QueryBuilder\UnlinkQuery;
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderQuery;
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderRequiredField;
use Darksparrow\DeegraphInteractions\QueryBuilder\LinkQuery\LinkQuery;
use Darksparrow\DeegraphInteractions\QueryBuilder\LinkQuery\LinkQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilderTrait;
#[QueryBuilderQuery]
class UnlinkQueryBuilder
{
use QueryBuilderTrait;
#[QueryBuilderRequiredField]
protected string $PropertyName = "";
#[QueryBuilderRequiredField]
protected string $Mode = "";
#[QueryBuilderRequiredField]
protected string $RelativePath = "";
public function PropertyName(string $propertyName): UnlinkQueryBuilder
{
$this->PropertyName = $propertyName;
return $this;
}
public function From(): UnlinkQueryBuilder
{
self::EnsureNotSet($this->Mode);
$this->Mode = "FROM";
return $this;
}
public function Of(): UnlinkQueryBuilder
{
self::EnsureNotSet($this->Mode);
$this->Mode = "OF";
return $this;
}
public function RelativePath(string $relativePath): UnlinkQueryBuilder
{
$this->RelativePath = $relativePath;
return $this;
}
public function Build(): UnlinkQuery
{
self::ValidateValues(target: $this);
$builder = "UNLINK "
. $this->PropertyName
. " "
. $this->Mode
. " "
. $this->RelativePath;
return new UnlinkQuery(queryString: $builder);
}
}

10
src/QueryBuilder/UnlinkQuery/UnlinkQueryResponse.php

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

49
tests/QueryBuilderUnlinkTest.php

@ -0,0 +1,49 @@
<?php
use Darksparrow\DeegraphInteractions\Exceptions\QueryBuilderConflictingFieldAlreadyExistsException;
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilder;
use PHPUnit\Framework\TestCase;
final class QueryBuilderUnlinkTest extends TestCase
{
private string $TestUUID = "{00000000-0000-0000-0000-000000000000}";
public function test0()
{
self::assertEquals(
expected: "UNLINK test FROM {$this->TestUUID}",
actual: QueryBuilder::Unlink()
->PropertyName("test")
->From()
->RelativePath($this->TestUUID)
->Build()
);
}
public function test1()
{
self::assertEquals(
expected: "UNLINK test OF {$this->TestUUID}",
actual: QueryBuilder::Unlink()
->PropertyName("test")
->Of()
->RelativePath($this->TestUUID)
->Build()
);
}
public function test2()
{
self::expectException(QueryBuilderConflictingFieldAlreadyExistsException::class);
self::assertEquals(
expected: "UNLINK test FROM {$this->TestUUID}",
actual: QueryBuilder::Unlink()
->PropertyName("test")
->From()
->Of()
->RelativePath($this->TestUUID)
->Build()
);
}
}
Loading…
Cancel
Save