Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Feature Pagination (#125)" #127

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 21 additions & 88 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,6 @@ DocuWare REST API. It is used to query the most common endpoints.
[DocuWare REST API](https://developer.docuware.com/rest/index.html).
See the documentation if you need further functionality. ⚠️

## Table of Contents

<!-- TOC -->
* [Table of Contents](#table-of-contents)
* [💡 What is DocuWare?](#-what-is-docuware)
* [🛠 Requirements](#-requirements)
* [SOmething else](#something-else)
* [> = v4.0 (alpha)](#---v40-alpha)
* [> = v3.0](#---v30)
* [> = v2.0](#---v20)
* [> = v1.2](#---v12)
* [< v1.2](#-v12)
* [⚙️ Installation](#-installation)
* [🏗 Usage](#-usage)
* [Pagination](#pagination)
* [🔍 Search usage](#-search-usage)
* [🖼 Make encrypted URL](#-make-encrypted-url)
* [🏋️ Document Index Fields DTO showcase](#-document-index-fields-dto-showcase)
* [🏋️ DTO showcase](#-dto-showcase)
* [🔐 Authentication](#-authentication)
* [Manual authentication](#manual-authentication)
* [📦 Caching requests](#-caching-requests)
* [💥 Exceptions explained](#-exceptions-explained)
* [✨ Events](#-events)
* [🔧 Configuration file](#-configuration-file)
* [🚧 Testing](#-testing)
* [📝 Changelog](#-changelog)
* [✏️ Contributing](#-contributing)
* [🧑‍💻 Security Vulnerabilities](#-security-vulnerabilities)
* [🙏 Credits](#-credits)
* [🎭 License](#-license)
<!-- TOC -->

## 💡 What is DocuWare?

DocuWare provides cloud document management and workflow automation software
Expand Down Expand Up @@ -276,61 +243,6 @@ $document = $connector->send(new PostDocumentRequest(
$connector->send(new DeleteDocumentRequest($fileCabinetId, $document->id))->dto();
```

## Pagination

Requests that support pagination:

| Requests |
|-------------------------|
| GetDialogsRequest |
| GetDocumentsRequest |
| GetFieldsRequest |
| GetFileCabinetsRequest |
| GetOrganizationsRequest |
| GetSearchRequest |
| GetSectionsRequest |


```php
$paginator = $connector->paginate(new GetDocumentsRequest(
config('laravel-docuware.tests.file_cabinet_id')
));

// You can set the per page limit
$paginator->setPerPageLimit(2);



// You can set the start page and how many pages you want to get

$paginator->setStartPage(3);
$paginator->setMaxPages(3); // Should be equal or more than the start page

// OR

$paginator->getSinglePage(3);



// Get the data from the paginator

$data = collect();

foreach ($paginator->collect() as $collection) {
$data->push($collection);
}

// OR

foreach ($paginator as $response) {
$data->push($response->dto());
}



$data->flatten()
```

## 🔍 Search usage

```php
Expand Down Expand Up @@ -688,6 +600,27 @@ CodebarAg\DocuWare\DTO\TableRow {
}
```

```php
CodebarAg\DocuWare\DTO\DocumentPaginator
+total: 39 // integer
+per_page: 10 // integer
+current_page: 9 // integer
+last_page: 15 // integer
+from: 1 // integer
+to: 10 // integer
+documents: Illuminate\Support\Collection { // Collection|Document[]
#items: array:2 [
0 => CodebarAg\DocuWare\DTO\Document // Document
1 => CodebarAg\DocuWare\DTO\Document // Document
]
}
+error: CodebarAg\DocuWare\DTO\ErrorBag { // ErrorBag|null
+code: 422 // int
+message: "'000' is not valid cabinet id" // string
}
}
```

## 🔐 Authentication

You only need to provide correct credentials. Everything else is automatically
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@
"illuminate/contracts": "^9.0|^10.0",
"nesbot/carbon": "^2.64.0",
"saloonphp/cache-plugin": "^3.0",
"saloonphp/laravel-plugin": "^3.0",
"saloonphp/pagination-plugin": "^2.1",
"saloonphp/saloon": "^3.0",
"saloonphp/laravel-plugin": "^3.0",
"spatie/laravel-package-tools": "^1.14.0"
},
"require-dev": {
Expand Down
10 changes: 1 addition & 9 deletions src/Connectors/DocuWareDynamicConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@
use CodebarAg\DocuWare\Support\Auth;
use GuzzleHttp\Cookie\CookieJar;
use Saloon\Http\Connector;
use Saloon\Http\Request;
use Saloon\PaginationPlugin\Contracts\HasPagination;
use Saloon\PaginationPlugin\OffsetPaginator;

class DocuWareDynamicConnector extends Connector implements HasPagination
class DocuWareDynamicConnector extends Connector
{
public Config $configuration;

Expand Down Expand Up @@ -58,9 +55,4 @@ public function getConfiguration(): Config
{
return $this->configuration;
}

public function paginate(Request $request): OffsetPaginator
{
return new DocuWareOffsetPaginator(connector: $this, request: $request);
}
}
50 changes: 0 additions & 50 deletions src/Connectors/DocuWareOffsetPaginator.php

This file was deleted.

10 changes: 1 addition & 9 deletions src/Connectors/DocuWareStaticConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
use CodebarAg\DocuWare\Support\EnsureValidCredentials;
use GuzzleHttp\Cookie\CookieJar;
use Saloon\Http\Connector;
use Saloon\Http\Request;
use Saloon\PaginationPlugin\Contracts\HasPagination;
use Saloon\PaginationPlugin\OffsetPaginator;

class DocuWareStaticConnector extends Connector implements HasPagination
class DocuWareStaticConnector extends Connector
{
public CookieJar $cookieJar;

Expand Down Expand Up @@ -50,9 +47,4 @@ public function getCoookieJar(): CookieJar
{
return $this->cookieJar;
}

public function paginate(Request $request): OffsetPaginator
{
return new DocuWareOffsetPaginator(connector: $this, request: $request);
}
}
38 changes: 38 additions & 0 deletions src/DocuWareSearchRequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class DocuWareSearchRequestBuilder

protected array $additionalFileCabinetIds = [];

protected int $page = 1;

protected int $perPage = 50;

protected ?string $searchTerm = null;

protected string $orderField = 'DWSTOREDATETIME';
Expand Down Expand Up @@ -50,6 +54,28 @@ public function dialog(string $dialogId): self
return $this;
}

public function page(?int $page): self
{
if (is_null($page)) {
$this->page = 1;
} else {
$this->page = $page;
}

return $this;
}

public function perPage(?int $perPage): self
{
if (is_null($perPage)) {
$this->perPage = 50;
} else {
$this->perPage = $perPage;
}

return $this;
}

public function fulltext(?string $searchTerm): self
{
$this->searchTerm = $searchTerm;
Expand Down Expand Up @@ -148,6 +174,8 @@ public function get(): GetSearchRequest
fileCabinetId: $this->fileCabinetId,
dialogId: $this->dialogId,
additionalFileCabinetIds: $this->additionalFileCabinetIds,
page: $this->page,
perPage: $this->perPage,
searchTerm: $this->searchTerm,
orderField: $this->orderField,
orderDirection: $this->orderDirection,
Expand All @@ -161,6 +189,16 @@ protected function guard(): void
is_null($this->fileCabinetId),
UnableToSearch::cabinetNotSet(),
);

throw_if(
$this->page <= 0,
UnableToSearch::invalidPageNumber($this->page),
);

throw_if(
$this->perPage <= 0,
UnableToSearch::invalidPerPageNumber($this->perPage),
);
}

private function checkDateFilterRangeDivergence(): void
Expand Down
3 changes: 1 addition & 2 deletions src/Requests/Dialogs/GetDialogsRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
use Saloon\Enums\Method;
use Saloon\Http\Request;
use Saloon\Http\Response;
use Saloon\PaginationPlugin\Contracts\Paginatable;

class GetDialogsRequest extends Request implements Cacheable, Paginatable
class GetDialogsRequest extends Request implements Cacheable
{
use HasCaching;

Expand Down
3 changes: 1 addition & 2 deletions src/Requests/Document/GetDocumentsRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
use Saloon\Enums\Method;
use Saloon\Http\Request;
use Saloon\Http\Response;
use Saloon\PaginationPlugin\Contracts\Paginatable;

class GetDocumentsRequest extends Request implements Cacheable, Paginatable
class GetDocumentsRequest extends Request implements Cacheable
{
use HasCaching;

Expand Down
3 changes: 1 addition & 2 deletions src/Requests/Fields/GetFieldsRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
use Saloon\Enums\Method;
use Saloon\Http\Request;
use Saloon\Http\Response;
use Saloon\PaginationPlugin\Contracts\Paginatable;

class GetFieldsRequest extends Request implements Cacheable, Paginatable
class GetFieldsRequest extends Request implements Cacheable
{
use HasCaching;

Expand Down
3 changes: 1 addition & 2 deletions src/Requests/FileCabinets/GetFileCabinetsRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
use Saloon\Enums\Method;
use Saloon\Http\Request;
use Saloon\Http\Response;
use Saloon\PaginationPlugin\Contracts\Paginatable;

class GetFileCabinetsRequest extends Request implements Cacheable, Paginatable
class GetFileCabinetsRequest extends Request implements Cacheable
{
use HasCaching;

Expand Down
3 changes: 1 addition & 2 deletions src/Requests/Organization/GetOrganizationsRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
use Saloon\Enums\Method;
use Saloon\Http\Request;
use Saloon\Http\Response;
use Saloon\PaginationPlugin\Contracts\Paginatable;

class GetOrganizationsRequest extends Request implements Cacheable, Paginatable
class GetOrganizationsRequest extends Request implements Cacheable
{
use HasCaching;

Expand Down
Loading