33namespace RestJS \Controller ;
44
55use RestJS \Message \Response ;
6- use function RestJS \response , RestJS \ checkNull ;
6+ use function RestJS \response ;
77use Slim \Exception \HttpBadRequestException ;
88
99/** Abstract Controller Functions */
@@ -30,13 +30,19 @@ public function findByColumn($req, $res, $args) {
3030 /** Delete Data by Id */
3131 public function delete ($ req , $ res , $ args ) {
3232 $ data = $ this ->_model ->delete ($ args );
33- checkNull ($ data , $ req );
33+
34+ // Check data is deleted
35+ if (!$ data )
36+ throw new HttpBadRequestException ($ req , "Something went wrong... " );
37+
3438 return response ($ req , $ res , new Response (message: "This item has been successfully removed. " , data: $ data ));
3539 }
3640
3741 /** Insert Data */
3842 public function insert ($ req , $ res , $ args ) {
39- if (!$ req ->getParsedBody ())
43+
44+ // Check user input valid form data
45+ if (!$ req ->getParsedBody ())
4046 throw new HttpBadRequestException ($ req , "Please enter valid form data. " );
4147
4248 $ data = $ this ->_model ->insert ([...$ req ->getParsedBody (), ...$ args ]);
@@ -45,11 +51,17 @@ public function insert($req, $res, $args) {
4551
4652 /** Update by Id */
4753 public function update ($ req , $ res , $ args ) {
54+
55+ // check user input valid form data
4856 if (!$ req ->getParsedBody ())
4957 throw new HttpBadRequestException ($ req , "Please enter valid form data. " );
5058
5159 $ data = $ this ->_model ->update ($ req ->getParsedBody (), $ args );
52- checkNull ($ data , $ req );
60+
61+ // Check data is updated
62+ if (!$ data )
63+ throw new HttpBadRequestException ($ req , "Something went wrong... " );
64+
5365 return response ($ req , $ res , new Response (message: "This item has been successfully updated. " , data: $ data ));
5466 }
5567}
0 commit comments