Skip to content

Commit 72945be

Browse files
committed
WIP
1 parent 9076c34 commit 72945be

File tree

8 files changed

+134
-14
lines changed

8 files changed

+134
-14
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ then optimize the processes that power the core of your business.
133133
| Documents/AnnotationsStamps | Get Stamps ||
134134
| Documents/DocumentsTrashBin | Get Documents ||
135135
| Documents/DocumentsTrashBin | Delete Documents ||
136-
| Documents/DocumentsTrashBin | Restore Documents | |
136+
| Documents/DocumentsTrashBin | Restore Documents | |
137137
| Documents/ApplicationProperties | Get Application Properties ||
138138
| Documents/ApplicationProperties | Add Application Properties ||
139139
| Documents/ApplicationProperties | Delete Application Properties ||
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace CodebarAg\DocuWare\DTO\Documents\DocumentsTrashBin;
4+
5+
use Illuminate\Support\Arr;
6+
7+
final class RestoreDocuments
8+
{
9+
public static function fromData(array $data): self
10+
{
11+
$failedItems = Arr::get($data, 'FailedItems');
12+
$successCount = Arr::get($data, 'SuccessCount');
13+
14+
return new self(
15+
failedItems: $failedItems,
16+
successCount: $successCount,
17+
);
18+
}
19+
20+
public function __construct(
21+
public array $failedItems = [],
22+
public int $successCount = 0,
23+
) {
24+
}
25+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace CodebarAg\DocuWare\Requests\Documents\DocumentsTrashBin;
4+
5+
use CodebarAg\DocuWare\DTO\Documents\DocumentsTrashBin\RestoreDocuments as RestoreDocumentsDto;
6+
use CodebarAg\DocuWare\Responses\Documents\DocumentsTrashBin\RestoreDocumentsResponse;
7+
use Illuminate\Support\Collection;
8+
use Saloon\Contracts\Body\HasBody;
9+
use Saloon\Enums\Method;
10+
use Saloon\Http\Request;
11+
use Saloon\Http\Response;
12+
use Saloon\Traits\Body\HasJsonBody;
13+
14+
class RestoreDocuments extends Request implements HasBody
15+
{
16+
use HasJsonBody;
17+
18+
protected Method $method = Method::POST;
19+
20+
public function __construct(
21+
protected readonly array|Collection $ids = [],
22+
) {
23+
}
24+
25+
public function resolveEndpoint(): string
26+
{
27+
return '/TrashBin/BatchRestore';
28+
}
29+
30+
public function defaultBody(): array
31+
{
32+
return [
33+
'Id' => $this->ids instanceof Collection ? $this->ids->toArray() : $this->ids,
34+
];
35+
}
36+
37+
public function createDtoFromResponse(Response $response): RestoreDocumentsDto
38+
{
39+
return RestoreDocumentsResponse::fromResponse($response);
40+
}
41+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace CodebarAg\DocuWare\Responses\Documents\DocumentsTrashBin;
4+
5+
use CodebarAg\DocuWare\DTO\Documents\DocumentsTrashBin\RestoreDocuments;
6+
use CodebarAg\DocuWare\Events\DocuWareResponseLog;
7+
use CodebarAg\DocuWare\Support\EnsureValidResponse;
8+
use Saloon\Http\Response;
9+
10+
final class RestoreDocumentsResponse
11+
{
12+
public static function fromResponse(Response $response): RestoreDocuments
13+
{
14+
event(new DocuWareResponseLog($response));
15+
16+
EnsureValidResponse::from($response);
17+
18+
return RestoreDocuments::fromData($response->throw()->json());
19+
}
20+
}

tests/Feature/Requests/Documents/DocumentsTrashBin/DeleteDocumentsFromTrashBinTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use CodebarAg\DocuWare\Requests\FileCabinets\Upload\CreateDataRecord;
77
use Illuminate\Support\Facades\Event;
88

9-
it('can search documents in trash', function () {
9+
it('can delete documents in trash', function () {
1010
Event::fake();
1111

1212
$document = $this->connector->send(new CreateDataRecord(
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
use CodebarAg\DocuWare\DocuWare;
4+
use CodebarAg\DocuWare\Requests\Documents\DocumentsTrashBin\RestoreDocuments;
5+
use CodebarAg\DocuWare\Requests\Documents\ModifyDocuments\DeleteDocument;
6+
use CodebarAg\DocuWare\Requests\FileCabinets\Upload\CreateDataRecord;
7+
use Illuminate\Support\Facades\Event;
8+
9+
it('can restore documents in trash', function () {
10+
Event::fake();
11+
12+
$document = $this->connector->send(new CreateDataRecord(
13+
config('laravel-docuware.tests.file_cabinet_id'),
14+
file_get_contents(__DIR__.'/../../../../Fixtures/files/test-1.pdf'),
15+
'test-1.pdf',
16+
))->dto();
17+
18+
$this->connector->send(new DeleteDocument(
19+
config('laravel-docuware.tests.file_cabinet_id'),
20+
$document->id,
21+
))->dto();
22+
23+
$paginatorRequest = (new DocuWare())
24+
->searchRequestBuilder()
25+
->trashBin()
26+
->get();
27+
28+
$paginator = $this->connector->send($paginatorRequest)->dto();
29+
30+
$delete = $this->connector->send(new RestoreDocuments($paginator->mappedDocuments->pluck('ID')->all()))->dto();
31+
32+
expect($delete->successCount)->toBe($paginator->total);
33+
})->group('restore', 'trash');

tests/Feature/SleepTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
Sleep::for(5)->seconds();
99
Log::info(now()->toDateTimeString());
1010

11-
})->expectNotToPerformAssertions();
11+
})->expectNotToPerformAssertions()
12+
->skip('Testing sleep function.');

tests/Pest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,17 @@ function clearFiles(): void
4242
))->dto();
4343
}
4444

45-
// $paginatorRequest = (new DocuWare())
46-
// ->searchRequestBuilder()
47-
// ->trashBin()
48-
// ->perPage(1000)
49-
// ->get();
50-
//
51-
// $paginator = $connector->send($paginatorRequest)->dto();
52-
//
53-
// if ($paginator->total > 0) {
54-
// $connector->send(new DeleteDocuments($paginator->mappedDocuments->pluck('ID')->all()))->dto();
55-
// }
45+
$paginatorRequest = (new DocuWare())
46+
->searchRequestBuilder()
47+
->trashBin()
48+
->perPage(1000)
49+
->get();
50+
51+
$paginator = $connector->send($paginatorRequest)->dto();
52+
53+
if ($paginator->total > 0) {
54+
$connector->send(new DeleteDocuments($paginator->mappedDocuments->pluck('ID')->all()))->dto();
55+
}
5656
}
5757

5858
function setUsersInactive(): void

0 commit comments

Comments
 (0)