File tree Expand file tree Collapse file tree 8 files changed +134
-14
lines changed
DTO/Documents/DocumentsTrashBin
Requests/Documents/DocumentsTrashBin
Responses/Documents/DocumentsTrashBin
Requests/Documents/DocumentsTrashBin Expand file tree Collapse file tree 8 files changed +134
-14
lines changed Original file line number Diff line number Diff line change @@ -133,7 +133,7 @@ then optimize the processes that power the core of your business.
133
133
| Documents/AnnotationsStamps | Get Stamps | ❌ |
134
134
| Documents/DocumentsTrashBin | Get Documents | ✅ |
135
135
| Documents/DocumentsTrashBin | Delete Documents | ✅ |
136
- | Documents/DocumentsTrashBin | Restore Documents | ❌ |
136
+ | Documents/DocumentsTrashBin | Restore Documents | ✅ |
137
137
| Documents/ApplicationProperties | Get Application Properties | ❌ |
138
138
| Documents/ApplicationProperties | Add Application Properties | ❌ |
139
139
| Documents/ApplicationProperties | Delete Application Properties | ❌ |
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 6
6
use CodebarAg \DocuWare \Requests \FileCabinets \Upload \CreateDataRecord ;
7
7
use Illuminate \Support \Facades \Event ;
8
8
9
- it ('can search documents in trash ' , function () {
9
+ it ('can delete documents in trash ' , function () {
10
10
Event::fake ();
11
11
12
12
$ document = $ this ->connector ->send (new CreateDataRecord (
Original file line number Diff line number Diff line change
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 ' );
Original file line number Diff line number Diff line change 8
8
Sleep::for (5 )->seconds ();
9
9
Log::info (now ()->toDateTimeString ());
10
10
11
- })->expectNotToPerformAssertions ();
11
+ })->expectNotToPerformAssertions ()
12
+ ->skip ('Testing sleep function. ' );
Original file line number Diff line number Diff line change @@ -42,17 +42,17 @@ function clearFiles(): void
42
42
))->dto ();
43
43
}
44
44
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
+ }
56
56
}
57
57
58
58
function setUsersInactive (): void
You can’t perform that action at this time.
0 commit comments