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

RestDelivery.get() is missing search params support #423

Open
relaxdiego opened this issue Apr 27, 2022 · 1 comment
Open

RestDelivery.get() is missing search params support #423

relaxdiego opened this issue Apr 27, 2022 · 1 comment

Comments

@relaxdiego
Copy link

relaxdiego commented Apr 27, 2022

I'm referring to this version of the code:

/**
* List all deliveries or paginated range
*/
public function get()
{
try {
if ($this->getRequestMethod() !== Request::HTTP_GET) {
throw new \common_exception_NotImplemented('Only get method is accepted to getting deliveries');
}
$limit = 0;
if ($this->hasRequestParameter('limit')) {
$limit = $this->getRequestParameter('limit');
if (!is_numeric($limit) || (int)$limit != $limit || $limit < 0) {
throw new \common_exception_ValidationFailed('limit', '\'Limit\' should be a positive integer');
}
}
$offset = 0;
if ($this->hasRequestParameter('offset')) {
$offset = $this->getRequestParameter('offset');
if (!is_numeric($offset) || (int)$offset != $offset || $offset < 0) {
throw new \common_exception_ValidationFailed('offset', '\'Offset\' should be a positive integer');
}
}
$service = DeliveryAssemblyService::singleton();
/** @var kernelResource[] $deliveries */
$deliveries = $service->getAllAssemblies();
$overallCount = count($deliveries);
if ($offset || $limit) {
if ($overallCount <= $offset) {
throw new \common_exception_ValidationFailed('offset', '\'Offset\' is too large');
}
$deliveries = array_slice($deliveries, $offset, $limit);
}
$mappedDeliveries = [];
foreach ($deliveries as $delivery) {
$mappedDeliveries[] = [
'uri' => $delivery->getUri(),
'label' => $delivery->getLabel(),
];
}
$response = [
'items' => $mappedDeliveries,
'overallCount' => $overallCount,
];
$this->returnSuccess($response);
} catch (\Exception $e) {
$this->returnFailure($e);
}
}

Currently it just does a simple $deliveries = $service->getAllAssemblies(); call in line 331.

Based on RestDelivery.update(), however, it looks like there's already a facility to support delivery filtering. I'm looking at this line of the update method:

$deliveries = $deliveryModelClass->searchInstances($where, ['like' => false, 'recursive' => true]);

It would be good to have search params be supported in get() because, right now, we have to resort to using update() to just get a filtered list of delivery IDs.

@DanielRuthardt
Copy link

@tikhanovichA ^^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants