Skip to content

Commit

Permalink
feat: add chunked method to estates and address
Browse files Browse the repository at this point in the history
  • Loading branch information
Katalam committed May 12, 2024
1 parent 238a8ae commit 5345cc7
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 2 deletions.
29 changes: 29 additions & 0 deletions src/Query/AddressBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,33 @@ public function find(int $id): array

return $response->json('response.results.0.data.records.0');
}

public function each(callable $callback): void
{
$columns = $this->columns;
$filter = $this->getFilters();
$listLimit = $this->limit;
$listOffset = $this->offset;
$orderBy = $this->getOrderBy();

$sortBy = data_get(array_keys($orderBy), 0);
$sortOrder = data_get($orderBy, 0);

$this->onOfficeService->requestAllChunked(/**
* @throws OnOfficeException
*/ function (int $pageSize, int $offset) use ($sortOrder, $sortBy, $filter, $columns) {
return $this->onOfficeService->requestApi(
OnOfficeAction::Read,
OnOfficeResourceType::Address,
parameters: [
OnOfficeService::DATA => $columns,
OnOfficeService::FILTER => $filter,
OnOfficeService::LISTLIMIT => $pageSize,
OnOfficeService::LISTOFFSET => $offset,
OnOfficeService::SORTBY => $sortBy,
OnOfficeService::SORTORDER => $sortOrder,
]
);
}, $callback, pageSize: $listLimit, offset: $listOffset);
}
}
2 changes: 2 additions & 0 deletions src/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,6 @@ abstract public function get(): Collection;
abstract public function first(): array;

abstract public function find(int $id): array;

abstract public function each(callable $callback): void;
}
26 changes: 25 additions & 1 deletion src/Query/EstateBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public function get(): Collection
OnOfficeService::LISTLIMIT => $pageSize,
OnOfficeService::LISTOFFSET => $offset,
OnOfficeService::SORTBY => $orderBy,

]
);
}, pageSize: $listLimit, offset: $listOffset);
Expand Down Expand Up @@ -85,4 +84,29 @@ public function find(int $id): array

return $response->json('response.results.0.data.records.0');
}

public function each(callable $callback): void
{
$columns = $this->columns;
$filter = $this->getFilters();
$listLimit = $this->limit;
$listOffset = $this->offset;
$orderBy = $this->getOrderBy();

$this->onOfficeService->requestAllChunked(/**
* @throws OnOfficeException
*/ function (int $pageSize, int $offset) use ($filter, $orderBy, $columns) {
return $this->onOfficeService->requestApi(
OnOfficeAction::Read,
OnOfficeResourceType::Estate,
parameters: [
OnOfficeService::DATA => $columns,
OnOfficeService::FILTER => $filter,
OnOfficeService::LISTLIMIT => $pageSize,
OnOfficeService::LISTOFFSET => $offset,
OnOfficeService::SORTBY => $orderBy,
]
);
}, $callback, pageSize: $listLimit, offset: $listOffset);
}
}
4 changes: 4 additions & 0 deletions tests/Query/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public function find(int $id): array
{
return [];
}

public function each(callable $callback): void
{
}
}

describe('select', function () {
Expand Down
3 changes: 2 additions & 1 deletion tests/Services/OnOfficeServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@
OnOfficeAction::Get,
OnOfficeResourceType::Estate,
);
}, function () {});
}, function () {
});
})->with([300, 301, 400, 401, 500, 501]);

it('will call the callback', function () {
Expand Down

0 comments on commit 5345cc7

Please sign in to comment.