6 changed files with 163 additions and 0 deletions
			
			
		@ -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); | 
				
			||||
 | 
					    } | 
				
			||||
 | 
					} | 
				
			||||
@ -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); | 
				
			||||
 | 
					    } | 
				
			||||
 | 
					} | 
				
			||||
@ -0,0 +1,10 @@ | 
				
			|||||
 | 
					<?php | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					namespace Darksparrow\DeegraphInteractions\QueryBuilder\UnlinkQuery; | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					class UnlinkQueryResponse | 
				
			||||
 | 
					{ | 
				
			||||
 | 
					    public function __construct(array $deegraphResponse) | 
				
			||||
 | 
					    { | 
				
			||||
 | 
					    } | 
				
			||||
 | 
					} | 
				
			||||
@ -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…
					
					
				
		Reference in new issue