33namespace RestJS \Controller ;
44
55use RestJS \Message \Response ;
6- use function RestJS \response ;
6+ use function RestJS \response , RestJS \ filter ;
77use Slim \Exception \HttpBadRequestException ;
88
99/** Abstract Controller Functions */
@@ -18,20 +18,26 @@ public function __construct($model) {
1818
1919 /** Find All Data */
2020 public function findAll ($ req , $ res ) {
21- return response ($ req , $ res , new Response (data: $ this ->_model ->findAll ()));
21+ $ data = filter ($ this ->_model ->findAll (), $ req );
22+ return response ($ req , $ res , new Response (data: $ data ));
2223 }
2324
24- /** Find Data by Column */
25+ /** Find Data by Conditional */
2526 public function findByColumn ($ req , $ res , $ args ) {
26- $ data = $ this ->_model ->findBy ($ args );
27- return response ($ req , $ res , args: new Response (data: [...$ data ]));
27+ $ data = filter ($ this ->_model ->findBy ($ args ), $ req );
28+ return response ($ req , $ res , args: new Response (data: $ data ));
29+ }
30+
31+ /** Filter Data by Conditional */
32+ public function filter ($ req , $ res , $ args ) {
33+ return response ($ req , $ res , args: new Response (data: $ this ->_model ->filter ($ args )));
2834 }
2935
3036 /** Delete Data by Id */
3137 public function delete ($ req , $ res , $ args ) {
3238 $ data = $ this ->_model ->delete ($ args );
3339
34- // Check data is deleted
40+ // Check Data is Deleted
3541 if (!$ data )
3642 throw new HttpBadRequestException ($ req , "Something went wrong... " );
3743
@@ -41,7 +47,7 @@ public function delete($req, $res, $args) {
4147 /** Insert Data */
4248 public function insert ($ req , $ res , $ args ) {
4349
44- // Check user input valid form data
50+ // Check User Input Valid Form Data
4551 if (!$ req ->getParsedBody ())
4652 throw new HttpBadRequestException ($ req , "Please enter valid form data. " );
4753
@@ -52,13 +58,13 @@ public function insert($req, $res, $args) {
5258 /** Update by Id */
5359 public function update ($ req , $ res , $ args ) {
5460
55- // check user input valid form data
61+ // Check User Input Valid Form Data
5662 if (!$ req ->getParsedBody ())
5763 throw new HttpBadRequestException ($ req , "Please enter valid form data. " );
5864
5965 $ data = $ this ->_model ->update ($ req ->getParsedBody (), $ args );
6066
61- // Check data is updated
67+ // Check Data is Updated
6268 if (!$ data )
6369 throw new HttpBadRequestException ($ req , "Something went wrong... " );
6470
0 commit comments