Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
RhysLees committed Jun 5, 2024
1 parent 3703752 commit 413ecd6
Show file tree
Hide file tree
Showing 7 changed files with 267 additions and 31 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ then optimize the processes that power the core of your business.
| Documents/DocumentsTrashBin | Get Documents || |
| Documents/DocumentsTrashBin | Delete Documents || |
| Documents/DocumentsTrashBin | Restore Documents || |
| Documents/ApplicationProperties | Get Application Properties | | - |
| Documents/ApplicationProperties | Add Application Properties | | - |
| Documents/ApplicationProperties | Delete Application Properties | | - |
| Documents/ApplicationProperties | Update Application Properties | | - |
| Documents/ApplicationProperties | Get Application Properties | | - |
| Documents/ApplicationProperties | Add Application Properties | | - |
| Documents/ApplicationProperties | Delete Application Properties | | - |
| Documents/ApplicationProperties | Update Application Properties | | - |
| Documents/Sections | Get All Sections from a Document || - |
| Documents/Sections | Get a Specific Section || - |
| Documents/Sections | Delete Section || - |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace CodebarAg\DocuWare\Requests\Documents\ApplicationProperties;

use CodebarAg\DocuWare\Responses\Documents\ApplicationProperties\GetApplicationPropertiesResponse;
use Illuminate\Support\Facades\Cache;
use Saloon\CachePlugin\Contracts\Cacheable;
use Saloon\CachePlugin\Drivers\LaravelCacheDriver;
use Saloon\CachePlugin\Traits\HasCaching;
use Saloon\Contracts\Body\HasBody;
use Saloon\Enums\Method;
use Saloon\Http\Request;
use Saloon\Http\Response;
use Saloon\Traits\Body\HasJsonBody;

class AddApplicationProperties extends Request implements Cacheable, HasBody
{
use HasCaching;
use HasJsonBody;

protected Method $method = Method::POST;

public function __construct(
protected readonly string $fileCabinetId,
protected readonly string $documentId,
protected readonly array $properties,
) {
}

public function resolveEndpoint(): string
{
return '/FileCabinets/'.$this->fileCabinetId.'/Documents/'.$this->documentId.'/DocumentApplicationProperties';
}

public function defaultBody()
{
return [
'DocumentApplicationProperty' => $this->properties,
];
}

public function resolveCacheDriver(): LaravelCacheDriver
{
return new LaravelCacheDriver(Cache::store(config('laravel-docuware.configurations.cache.driver')));
}

public function cacheExpiryInSeconds(): int
{
return config('laravel-docuware.configurations.cache.lifetime_in_seconds', 3600);
}

public function createDtoFromResponse(Response $response): mixed
{
return GetApplicationPropertiesResponse::fromResponse($response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace CodebarAg\DocuWare\Requests\Documents\ApplicationProperties;

use CodebarAg\DocuWare\Responses\Documents\ApplicationProperties\GetApplicationPropertiesResponse;
use Illuminate\Support\Facades\Cache;
use Saloon\CachePlugin\Contracts\Cacheable;
use Saloon\CachePlugin\Drivers\LaravelCacheDriver;
use Saloon\CachePlugin\Traits\HasCaching;
use Saloon\Contracts\Body\HasBody;
use Saloon\Enums\Method;
use Saloon\Http\Request;
use Saloon\Http\Response;
use Saloon\Traits\Body\HasJsonBody;

class DeleteApplicationProperties extends Request implements Cacheable, HasBody
{
use HasCaching;
use HasJsonBody;

protected Method $method = Method::POST;

public function __construct(
protected readonly string $fileCabinetId,
protected readonly string $documentId,
protected readonly array $propertyNames,
) {
}

public function resolveEndpoint(): string
{
return '/FileCabinets/'.$this->fileCabinetId.'/Documents/'.$this->documentId.'/DocumentApplicationProperties';
}

public function defaultBody()
{
$props = collect($this->propertyNames)->map(function ($name) {
return [
'Name' => $name,
'Value' => null,
];
});

return [
'DocumentApplicationProperty' => $props,
];
}

public function resolveCacheDriver(): LaravelCacheDriver
{
return new LaravelCacheDriver(Cache::store(config('laravel-docuware.configurations.cache.driver')));
}

public function cacheExpiryInSeconds(): int
{
return config('laravel-docuware.configurations.cache.lifetime_in_seconds', 3600);
}

public function createDtoFromResponse(Response $response): mixed
{
return GetApplicationPropertiesResponse::fromResponse($response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace CodebarAg\DocuWare\Requests\Documents\ApplicationProperties;

use CodebarAg\DocuWare\Responses\Documents\ApplicationProperties\GetApplicationPropertiesResponse;
use Illuminate\Support\Facades\Cache;
use Saloon\CachePlugin\Contracts\Cacheable;
use Saloon\CachePlugin\Drivers\LaravelCacheDriver;
use Saloon\CachePlugin\Traits\HasCaching;
use Saloon\Contracts\Body\HasBody;
use Saloon\Enums\Method;
use Saloon\Http\Request;
use Saloon\Http\Response;
use Saloon\Traits\Body\HasJsonBody;

class UpdateApplicationProperties extends Request implements Cacheable, HasBody
{
use HasCaching;
use HasJsonBody;

protected Method $method = Method::POST;

public function __construct(
protected readonly string $fileCabinetId,
protected readonly string $documentId,
protected readonly array $properties,
) {
}

public function resolveEndpoint(): string
{
return '/FileCabinets/'.$this->fileCabinetId.'/Documents/'.$this->documentId.'/DocumentApplicationProperties';
}

public function defaultBody()
{
return [
'DocumentApplicationProperty' => $this->properties,
];
}

public function resolveCacheDriver(): LaravelCacheDriver
{
return new LaravelCacheDriver(Cache::store(config('laravel-docuware.configurations.cache.driver')));
}

public function cacheExpiryInSeconds(): int
{
return config('laravel-docuware.configurations.cache.lifetime_in_seconds', 3600);
}

public function createDtoFromResponse(Response $response): mixed
{
return GetApplicationPropertiesResponse::fromResponse($response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public static function fromResponse(Response $response): mixed

EnsureValidResponse::from($response);

return $response->throw()->json();
return collect($response->throw()->json('DocumentApplicationProperty'));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

use CodebarAg\DocuWare\Events\DocuWareResponseLog;
use CodebarAg\DocuWare\Requests\Documents\ApplicationProperties\AddApplicationProperties;
use CodebarAg\DocuWare\Requests\Documents\ApplicationProperties\DeleteApplicationProperties;
use CodebarAg\DocuWare\Requests\Documents\ApplicationProperties\GetApplicationProperties;
use CodebarAg\DocuWare\Requests\Documents\ApplicationProperties\UpdateApplicationProperties;
use CodebarAg\DocuWare\Requests\FileCabinets\Upload\CreateDataRecord;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Event;

it('can add get update delete application properties to a document', function () {
Event::fake();

$fileCabinetId = config('laravel-docuware.tests.file_cabinet_id');

$document = $this->connector->send(new CreateDataRecord(
$fileCabinetId,
'::fake-file-content::',
'example.txt'
))->dto();

$addProperties = $this->connector->send(new AddApplicationProperties(
$fileCabinetId,
$document->id,
[
[
'Name' => 'Key1',
'Value' => 'Key1 Value',
],
[
'Name' => 'Key2',
'Value' => 'Key2 Value',
],
],
))->dto();

expect($addProperties)->toBeInstanceOf(Collection::class)
->and($addProperties->count())->toBe(2)
->and($addProperties->first()['Name'])->toBe('Key1')
->and($addProperties->first()['Value'])->toBe('Key1 Value')
->and($addProperties->last()['Name'])->toBe('Key2')
->and($addProperties->last()['Value'])->toBe('Key2 Value');

$updateProperties = $this->connector->send(new UpdateApplicationProperties(
$fileCabinetId,
$document->id,
[
[
'Name' => 'Key1',
'Value' => 'Key1 Value Updated',
],
],
))->dto()->sortBy('Name');

expect($updateProperties)->toBeInstanceOf(Collection::class)
->and($updateProperties->count())->toBe(2)
->and($updateProperties->first()['Name'])->toBe('Key1')
->and($updateProperties->first()['Value'])->toBe('Key1 Value Updated')
->and($updateProperties->last()['Name'])->toBe('Key2')
->and($updateProperties->last()['Value'])->toBe('Key2 Value');

$deleteProperties = $this->connector->send(new DeleteApplicationProperties(
$fileCabinetId,
$document->id,
[
'Key1',
],
))->dto();

expect($deleteProperties)->toBeInstanceOf(Collection::class)
->and($deleteProperties->count())->toBe(1)
->and($deleteProperties->first()['Name'])->toBe('Key2')
->and($deleteProperties->first()['Value'])->toBe('Key2 Value');

$properties = $this->connector->send(new GetApplicationProperties(
$fileCabinetId,
$document->id,
))->dto();

expect($properties)->toBeInstanceOf(Collection::class)
->and($properties->count())->toBe(1)
->and($properties->first()['Name'])->toBe('Key2')
->and($properties->first()['Value'])->toBe('Key2 Value');

Event::assertDispatched(DocuWareResponseLog::class);
})->only();

This file was deleted.

0 comments on commit 413ecd6

Please sign in to comment.