-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
134 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
41
src/Requests/Documents/DocumentsTrashBin/RestoreDocuments.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Responses/Documents/DocumentsTrashBin/RestoreDocumentsResponse.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
tests/Feature/Requests/Documents/DocumentsTrashBin/RestoreDocumentsFromTrashBinTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters