Skip to content

Commit

Permalink
Fixed the product page endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Dec 6, 2024
1 parent 82ad9ad commit 5944839
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 46 deletions.
23 changes: 15 additions & 8 deletions src/Client/Endpoint/ProductEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Setono\PeakWMS\DataTransferObject\Collection;
use Setono\PeakWMS\DataTransferObject\PaginatedCollection;
use Setono\PeakWMS\DataTransferObject\Product\Product;
use Setono\PeakWMS\Request\Query\Product\PageQuery;
use Setono\PeakWMS\Request\Query\KeySetPageQuery;

/**
* @extends Endpoint<Product>
Expand All @@ -29,9 +29,9 @@ final class ProductEndpoint extends Endpoint implements ProductEndpointInterface
/**
* @return PaginatedCollection<Product>
*/
public function getPage(PageQuery $query = null): PaginatedCollection
public function getPage(KeySetPageQuery $query = null): PaginatedCollection
{
$query ??= PageQuery::create();
$query ??= KeySetPageQuery::create();

/** @var class-string<PaginatedCollection<Product>> $signature */
$signature = sprintf('%s<%s>', PaginatedCollection::class, self::getDataClass());
Expand All @@ -42,7 +42,7 @@ public function getPage(PageQuery $query = null): PaginatedCollection
->map(
$signature,
$this->createSource(
$this->client->get($this->endpoint, $query),
$this->client->get(sprintf('%s/keySet', $this->endpoint), $query),
)->map(['data' => 'items']),
);
}
Expand All @@ -66,16 +66,23 @@ public function getByProductId(string $productId): Collection
/**
* @return \Generator<Product>
*/
public function iterate(PageQuery $query = null): \Generator
public function iterate(KeySetPageQuery $query = null): \Generator
{
$query ??= PageQuery::create();
$query ??= KeySetPageQuery::create();

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

yield from $collection;
$lastId = null;

$query->incrementPage();
foreach ($collection as $item) {
yield $item;
$lastId = $item->id;
}

if (null !== $lastId) {
$query->setLastId($lastId);
}
} while (!$collection->empty());
}

Expand Down
6 changes: 3 additions & 3 deletions src/Client/Endpoint/ProductEndpointInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Setono\PeakWMS\DataTransferObject\Collection;
use Setono\PeakWMS\DataTransferObject\PaginatedCollection;
use Setono\PeakWMS\DataTransferObject\Product\Product;
use Setono\PeakWMS\Request\Query\Product\PageQuery;
use Setono\PeakWMS\Request\Query\KeySetPageQuery;

/**
* @extends EndpointInterface<Product>
Expand All @@ -19,7 +19,7 @@ interface ProductEndpointInterface extends EndpointInterface, CreatableEndpointI
/**
* @return PaginatedCollection<Product>
*/
public function getPage(PageQuery $query = null): PaginatedCollection;
public function getPage(KeySetPageQuery $query = null): PaginatedCollection;

/**
* @return Collection<Product>
Expand All @@ -29,5 +29,5 @@ public function getByProductId(string $productId): Collection;
/**
* @return iterable<Product>
*/
public function iterate(PageQuery $query = null): iterable;
public function iterate(KeySetPageQuery $query = null): iterable;
}
35 changes: 0 additions & 35 deletions src/Request/Query/Product/PageQuery.php

This file was deleted.

0 comments on commit 5944839

Please sign in to comment.