Skip to content

Commit 5944839

Browse files
committed
Fixed the product page endpoint
1 parent 82ad9ad commit 5944839

File tree

3 files changed

+18
-46
lines changed

3 files changed

+18
-46
lines changed

src/Client/Endpoint/ProductEndpoint.php

+15-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Setono\PeakWMS\DataTransferObject\Collection;
88
use Setono\PeakWMS\DataTransferObject\PaginatedCollection;
99
use Setono\PeakWMS\DataTransferObject\Product\Product;
10-
use Setono\PeakWMS\Request\Query\Product\PageQuery;
10+
use Setono\PeakWMS\Request\Query\KeySetPageQuery;
1111

1212
/**
1313
* @extends Endpoint<Product>
@@ -29,9 +29,9 @@ final class ProductEndpoint extends Endpoint implements ProductEndpointInterface
2929
/**
3030
* @return PaginatedCollection<Product>
3131
*/
32-
public function getPage(PageQuery $query = null): PaginatedCollection
32+
public function getPage(KeySetPageQuery $query = null): PaginatedCollection
3333
{
34-
$query ??= PageQuery::create();
34+
$query ??= KeySetPageQuery::create();
3535

3636
/** @var class-string<PaginatedCollection<Product>> $signature */
3737
$signature = sprintf('%s<%s>', PaginatedCollection::class, self::getDataClass());
@@ -42,7 +42,7 @@ public function getPage(PageQuery $query = null): PaginatedCollection
4242
->map(
4343
$signature,
4444
$this->createSource(
45-
$this->client->get($this->endpoint, $query),
45+
$this->client->get(sprintf('%s/keySet', $this->endpoint), $query),
4646
)->map(['data' => 'items']),
4747
);
4848
}
@@ -66,16 +66,23 @@ public function getByProductId(string $productId): Collection
6666
/**
6767
* @return \Generator<Product>
6868
*/
69-
public function iterate(PageQuery $query = null): \Generator
69+
public function iterate(KeySetPageQuery $query = null): \Generator
7070
{
71-
$query ??= PageQuery::create();
71+
$query ??= KeySetPageQuery::create();
7272

7373
do {
7474
$collection = $this->getPage($query);
7575

76-
yield from $collection;
76+
$lastId = null;
7777

78-
$query->incrementPage();
78+
foreach ($collection as $item) {
79+
yield $item;
80+
$lastId = $item->id;
81+
}
82+
83+
if (null !== $lastId) {
84+
$query->setLastId($lastId);
85+
}
7986
} while (!$collection->empty());
8087
}
8188

src/Client/Endpoint/ProductEndpointInterface.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Setono\PeakWMS\DataTransferObject\Collection;
88
use Setono\PeakWMS\DataTransferObject\PaginatedCollection;
99
use Setono\PeakWMS\DataTransferObject\Product\Product;
10-
use Setono\PeakWMS\Request\Query\Product\PageQuery;
10+
use Setono\PeakWMS\Request\Query\KeySetPageQuery;
1111

1212
/**
1313
* @extends EndpointInterface<Product>
@@ -19,7 +19,7 @@ interface ProductEndpointInterface extends EndpointInterface, CreatableEndpointI
1919
/**
2020
* @return PaginatedCollection<Product>
2121
*/
22-
public function getPage(PageQuery $query = null): PaginatedCollection;
22+
public function getPage(KeySetPageQuery $query = null): PaginatedCollection;
2323

2424
/**
2525
* @return Collection<Product>
@@ -29,5 +29,5 @@ public function getByProductId(string $productId): Collection;
2929
/**
3030
* @return iterable<Product>
3131
*/
32-
public function iterate(PageQuery $query = null): iterable;
32+
public function iterate(KeySetPageQuery $query = null): iterable;
3333
}

src/Request/Query/Product/PageQuery.php

-35
This file was deleted.

0 commit comments

Comments
 (0)