Skip to content

Commit 0ae6314

Browse files
committed
API - IP address ranges - add search + fix index
1 parent e3ef61b commit 0ae6314

File tree

2 files changed

+69
-4
lines changed

2 files changed

+69
-4
lines changed

config/routes.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,14 @@
107107
$builder->setExtensions(['json']);
108108

109109
$builder->resources('AccessPoints');
110-
$builder->resources('IpAddressRanges');
110+
$builder->resources('IpAddressRanges', [
111+
'map' => [
112+
'search' => [
113+
'action' => 'search',
114+
'method' => 'GET',
115+
],
116+
],
117+
]);
111118
$builder->resources('RouterosDevices', [
112119
'map' => [
113120
'search' => [

src/Controller/Api/IpAddressRangesController.php

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,68 @@ class IpAddressRangesController extends AppController
2020
*/
2121
public function index()
2222
{
23-
$this->paginate = [
24-
'contain' => ['AccessPoints', 'ParentIpAddressRanges'],
23+
$ipAddressRanges = $this->IpAddressRanges->find('all', [
24+
'contain' => [
25+
'AccessPoints',
26+
'ParentIpAddressRanges',
27+
],
28+
])->all();
29+
30+
$this->set(compact('ipAddressRanges'));
31+
$this->viewBuilder()->setOption('serialize', ['ipAddressRanges']);
32+
}
33+
34+
/**
35+
* Search method
36+
*
37+
* @property \App\Model\Table\IpAddressRangesTable $IpAddressRanges
38+
* @return \Cake\Http\Response|null|void Renders view
39+
*/
40+
public function search()
41+
{
42+
$options = [
43+
'contain' => [
44+
'AccessPoints',
45+
'ParentIpAddressRanges',
46+
],
2547
];
26-
$ipAddressRanges = $this->paginate($this->IpAddressRanges);
48+
49+
if ($this->request->getQuery('access_point_id') !== null) {
50+
$options['conditions']['IpAddressRanges.access_point_id'] = $this->request->getQuery('access_point_id');
51+
}
52+
if ($this->request->getQuery('for_subnets') !== null) {
53+
$options['conditions']['IpAddressRanges.for_subnets'] = $this->request->getQuery('for_subnets');
54+
}
55+
if ($this->request->getQuery('for_customer_addresses_set_via_radius') !== null) {
56+
$options['conditions']['IpAddressRanges.for_customer_addresses_set_via_radius']
57+
= $this->request->getQuery('for_customer_addresses_set_via_radius');
58+
}
59+
if ($this->request->getQuery('for_customer_addresses_set_manually') !== null) {
60+
$options['conditions']['IpAddressRanges.for_customer_addresses_set_manually']
61+
= $this->request->getQuery('for_customer_addresses_set_manually');
62+
}
63+
if ($this->request->getQuery('for_technology_addresses_set_manually') !== null) {
64+
$options['conditions']['IpAddressRanges.for_technology_addresses_set_manually']
65+
= $this->request->getQuery('for_technology_addresses_set_manually');
66+
}
67+
if ($this->request->getQuery('for_customer_networks_set_via_radius') !== null) {
68+
$options['conditions']['IpAddressRanges.for_customer_networks_set_via_radius']
69+
= $this->request->getQuery('for_customer_networks_set_via_radius');
70+
}
71+
if ($this->request->getQuery('for_customer_networks_set_manually') !== null) {
72+
$options['conditions']['IpAddressRanges.for_customer_networks_set_manually']
73+
= $this->request->getQuery('for_customer_networks_set_manually');
74+
}
75+
if ($this->request->getQuery('for_technology_networks_set_manually') !== null) {
76+
$options['conditions']['IpAddressRanges.for_technology_networks_set_manually']
77+
= $this->request->getQuery('for_technology_networks_set_manually');
78+
}
79+
80+
if ($this->request->getQuery('ip_address') !== null) {
81+
$options['conditions']['IpAddressRanges.ip_network >>='] = $this->request->getQuery('ip_address');
82+
}
83+
84+
$ipAddressRanges = $this->IpAddressRanges->find('all', $options);
2785

2886
$this->set(compact('ipAddressRanges'));
2987
$this->viewBuilder()->setOption('serialize', ['ipAddressRanges']);

0 commit comments

Comments
 (0)