Skip to content

Commit

Permalink
added having cities filter
Browse files Browse the repository at this point in the history
  • Loading branch information
augusthur committed Oct 15, 2019
1 parent 3c4ad1b commit 033957b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Resource/CountryResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public function retrieveCountries($subject, $options = [])
'from' => [
'type' => 'string',
],
'having' => [
'type' => 'string',
'enum' => ['cities'],
],
'region_id' => [
'type' => 'integer',
'minimum' => 1,
Expand All @@ -42,6 +46,9 @@ public function retrieveCountries($subject, $options = [])
if (isset($options['region_id'])) {
$query->where('region_id', $options['region_id']);
}
if (isset($options['having'])) {
$query->has($options['having']);
}
return new Paginator($query, $options);
}
}
8 changes: 8 additions & 0 deletions src/Resource/RegionResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public function retrieveRegions($subject, $options = [])
'from' => [
'type' => 'string',
],
'having' => [
'type' => 'string',
'enum' => ['cities'],
],
]);
$v = $this->validation->fromSchema($pagSch);
$options = $this->validation->prepareData($pagSch, $options, true);
Expand All @@ -35,6 +39,10 @@ public function retrieveRegions($subject, $options = [])
$q->distance('point', new Point($a, $b), $options['distance']);
});
}
// TODO mejorar porque no es dinámico
if (isset($options['having'])) {
$query->has('countries.cities');
}
return new Paginator($query, $options);
}
}

0 comments on commit 033957b

Please sign in to comment.