7
7
use Setono \PeakWMS \DataTransferObject \Collection ;
8
8
use Setono \PeakWMS \DataTransferObject \PaginatedCollection ;
9
9
use Setono \PeakWMS \DataTransferObject \Product \Product ;
10
- use Setono \PeakWMS \Request \Query \Product \ PageQuery ;
10
+ use Setono \PeakWMS \Request \Query \KeySetPageQuery ;
11
11
12
12
/**
13
13
* @extends Endpoint<Product>
@@ -29,9 +29,9 @@ final class ProductEndpoint extends Endpoint implements ProductEndpointInterface
29
29
/**
30
30
* @return PaginatedCollection<Product>
31
31
*/
32
- public function getPage (PageQuery $ query = null ): PaginatedCollection
32
+ public function getPage (KeySetPageQuery $ query = null ): PaginatedCollection
33
33
{
34
- $ query ??= PageQuery ::create ();
34
+ $ query ??= KeySetPageQuery ::create ();
35
35
36
36
/** @var class-string<PaginatedCollection<Product>> $signature */
37
37
$ signature = sprintf ('%s<%s> ' , PaginatedCollection::class, self ::getDataClass ());
@@ -42,7 +42,7 @@ public function getPage(PageQuery $query = null): PaginatedCollection
42
42
->map (
43
43
$ signature ,
44
44
$ this ->createSource (
45
- $ this ->client ->get ($ this ->endpoint , $ query ),
45
+ $ this ->client ->get (sprintf ( ' %s/keySet ' , $ this ->endpoint ) , $ query ),
46
46
)->map (['data ' => 'items ' ]),
47
47
);
48
48
}
@@ -66,16 +66,23 @@ public function getByProductId(string $productId): Collection
66
66
/**
67
67
* @return \Generator<Product>
68
68
*/
69
- public function iterate (PageQuery $ query = null ): \Generator
69
+ public function iterate (KeySetPageQuery $ query = null ): \Generator
70
70
{
71
- $ query ??= PageQuery ::create ();
71
+ $ query ??= KeySetPageQuery ::create ();
72
72
73
73
do {
74
74
$ collection = $ this ->getPage ($ query );
75
75
76
- yield from $ collection ;
76
+ $ lastId = null ;
77
77
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
+ }
79
86
} while (!$ collection ->empty ());
80
87
}
81
88
0 commit comments