Skip to content

Commit 1c474c5

Browse files
chore: remove relationship on controller
1 parent c22a6f8 commit 1c474c5

File tree

4 files changed

+5
-43
lines changed

4 files changed

+5
-43
lines changed

src/Controller/AbstractController.php

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,21 @@
88
/** Abstract Controller Functions */
99
class AbstractController {
1010

11-
/** Entity All Data */
12-
private $_data;
13-
1411
/** Model Class Object */
1512
protected $_model;
1613

17-
public function __construct($model, $data) {
18-
$this->_data = $data;
14+
public function __construct($model) {
1915
$this->_model = $model;
2016
}
2117

2218
/** Find All Data */
2319
public function findAll($req, $res) {
24-
25-
/** Filter Column Query Params */
26-
$filter = $req->getQueryParams()['filter'] ?? null;
27-
28-
/** Filter Data */
29-
$data = $this->_data;
30-
31-
// Selected Column Fetch All Data
32-
if ($filter):
33-
$data = [];
34-
$filter = explode(",", $filter);
35-
36-
foreach ($this->_data as $item)
37-
array_push($data, array_intersect_key((array) $item, array_flip($filter)));
38-
endif;
39-
40-
return response($req, $res, new Response(data: $data));
20+
return response($req, $res, new Response(data: $this->_model->findAll()));
4121
}
4222

4323
/** Find Data by Column */
4424
public function findByColumn($req, $res, $args) {
45-
46-
foreach ($args as $key => $value)
47-
$data = array_filter($this->_data, fn($item) => $item->$key == $args[$key]);
48-
25+
$data = $this->_model->findBy($args);
4926
checkNull($data, $req);
5027
return response($req, $res, args: new Response(data: [...$data]));
5128
}

src/api/category/controller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
class Controller extends AbstractController {
99

1010
public function __construct(private Model $model) {
11-
parent::__construct($model, $model->findAll());
11+
parent::__construct($model);
1212
}
1313
}

src/api/user/controller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
class Controller extends AbstractAuthController {
99

1010
public function __construct(private Model $model) {
11-
parent::__construct($model, $model->findAll());
11+
parent::__construct($model);
1212
}
1313
}

src/relationship.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,5 @@ function oneToMany($one, $many, $property) {
4242
array_push($result, $oneItem);
4343
endforeach;
4444

45-
return $result;
46-
}
47-
48-
/** One Way Filter Relationship Function */
49-
function oneWayFilter($current, $filter, $addProperty, $findProperty) {
50-
$result = [];
51-
52-
foreach ($current as $currentItem):
53-
$currentItem->$addProperty = [];
54-
55-
$array = array_filter($filter, fn($item) => $currentItem->id == $item->$findProperty);
56-
array_push($currentItem->$addProperty, ...$array);
57-
array_push($result, $currentItem);
58-
endforeach;
59-
6045
return $result;
6146
}

0 commit comments

Comments
 (0)