Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
RhysLees committed May 30, 2024
1 parent 9076c34 commit 72945be
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ then optimize the processes that power the core of your business.
| Documents/AnnotationsStamps | Get Stamps ||
| Documents/DocumentsTrashBin | Get Documents ||
| Documents/DocumentsTrashBin | Delete Documents ||
| Documents/DocumentsTrashBin | Restore Documents | |
| Documents/DocumentsTrashBin | Restore Documents | |
| Documents/ApplicationProperties | Get Application Properties ||
| Documents/ApplicationProperties | Add Application Properties ||
| Documents/ApplicationProperties | Delete Application Properties ||
Expand Down
25 changes: 25 additions & 0 deletions src/DTO/Documents/DocumentsTrashBin/RestoreDocuments.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace CodebarAg\DocuWare\DTO\Documents\DocumentsTrashBin;

use Illuminate\Support\Arr;

final class RestoreDocuments
{
public static function fromData(array $data): self
{
$failedItems = Arr::get($data, 'FailedItems');
$successCount = Arr::get($data, 'SuccessCount');

return new self(
failedItems: $failedItems,
successCount: $successCount,
);
}

public function __construct(
public array $failedItems = [],
public int $successCount = 0,
) {
}
}
41 changes: 41 additions & 0 deletions src/Requests/Documents/DocumentsTrashBin/RestoreDocuments.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace CodebarAg\DocuWare\Requests\Documents\DocumentsTrashBin;

use CodebarAg\DocuWare\DTO\Documents\DocumentsTrashBin\RestoreDocuments as RestoreDocumentsDto;
use CodebarAg\DocuWare\Responses\Documents\DocumentsTrashBin\RestoreDocumentsResponse;
use Illuminate\Support\Collection;
use Saloon\Contracts\Body\HasBody;
use Saloon\Enums\Method;
use Saloon\Http\Request;
use Saloon\Http\Response;
use Saloon\Traits\Body\HasJsonBody;

class RestoreDocuments extends Request implements HasBody
{
use HasJsonBody;

protected Method $method = Method::POST;

public function __construct(
protected readonly array|Collection $ids = [],
) {
}

public function resolveEndpoint(): string
{
return '/TrashBin/BatchRestore';
}

public function defaultBody(): array
{
return [
'Id' => $this->ids instanceof Collection ? $this->ids->toArray() : $this->ids,
];
}

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

namespace CodebarAg\DocuWare\Responses\Documents\DocumentsTrashBin;

use CodebarAg\DocuWare\DTO\Documents\DocumentsTrashBin\RestoreDocuments;
use CodebarAg\DocuWare\Events\DocuWareResponseLog;
use CodebarAg\DocuWare\Support\EnsureValidResponse;
use Saloon\Http\Response;

final class RestoreDocumentsResponse
{
public static function fromResponse(Response $response): RestoreDocuments
{
event(new DocuWareResponseLog($response));

EnsureValidResponse::from($response);

return RestoreDocuments::fromData($response->throw()->json());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use CodebarAg\DocuWare\Requests\FileCabinets\Upload\CreateDataRecord;
use Illuminate\Support\Facades\Event;

it('can search documents in trash', function () {
it('can delete documents in trash', function () {
Event::fake();

$document = $this->connector->send(new CreateDataRecord(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use CodebarAg\DocuWare\DocuWare;
use CodebarAg\DocuWare\Requests\Documents\DocumentsTrashBin\RestoreDocuments;
use CodebarAg\DocuWare\Requests\Documents\ModifyDocuments\DeleteDocument;
use CodebarAg\DocuWare\Requests\FileCabinets\Upload\CreateDataRecord;
use Illuminate\Support\Facades\Event;

it('can restore documents in trash', function () {
Event::fake();

$document = $this->connector->send(new CreateDataRecord(
config('laravel-docuware.tests.file_cabinet_id'),
file_get_contents(__DIR__.'/../../../../Fixtures/files/test-1.pdf'),
'test-1.pdf',
))->dto();

$this->connector->send(new DeleteDocument(
config('laravel-docuware.tests.file_cabinet_id'),
$document->id,
))->dto();

$paginatorRequest = (new DocuWare())
->searchRequestBuilder()
->trashBin()
->get();

$paginator = $this->connector->send($paginatorRequest)->dto();

$delete = $this->connector->send(new RestoreDocuments($paginator->mappedDocuments->pluck('ID')->all()))->dto();

expect($delete->successCount)->toBe($paginator->total);
})->group('restore', 'trash');
3 changes: 2 additions & 1 deletion tests/Feature/SleepTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
Sleep::for(5)->seconds();
Log::info(now()->toDateTimeString());

})->expectNotToPerformAssertions();
})->expectNotToPerformAssertions()
->skip('Testing sleep function.');
22 changes: 11 additions & 11 deletions tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ function clearFiles(): void
))->dto();
}

// $paginatorRequest = (new DocuWare())
// ->searchRequestBuilder()
// ->trashBin()
// ->perPage(1000)
// ->get();
//
// $paginator = $connector->send($paginatorRequest)->dto();
//
// if ($paginator->total > 0) {
// $connector->send(new DeleteDocuments($paginator->mappedDocuments->pluck('ID')->all()))->dto();
// }
$paginatorRequest = (new DocuWare())
->searchRequestBuilder()
->trashBin()
->perPage(1000)
->get();

$paginator = $connector->send($paginatorRequest)->dto();

if ($paginator->total > 0) {
$connector->send(new DeleteDocuments($paginator->mappedDocuments->pluck('ID')->all()))->dto();
}
}

function setUsersInactive(): void
Expand Down

0 comments on commit 72945be

Please sign in to comment.