44
55use RestJS \Message \Response ;
66use function RestJS \response , RestJS \checkNull ;
7+ use Slim \Exception \HttpBadRequestException ;
78
89/** Abstract Controller Functions */
910class AbstractController {
@@ -23,7 +24,6 @@ public function findAll($req, $res) {
2324 /** Find Data by Column */
2425 public function findByColumn ($ req , $ res , $ args ) {
2526 $ data = $ this ->_model ->findBy ($ args );
26- checkNull ($ data , $ req );
2727 return response ($ req , $ res , args: new Response (data: [...$ data ]));
2828 }
2929
@@ -36,12 +36,18 @@ public function delete($req, $res, $args) {
3636
3737 /** Insert Data */
3838 public function insert ($ req , $ res , $ args ) {
39- $ data = $ this ->_model ->insert ([...$ req ->getParsedBody (), ...$ args ]);
39+ if (!$ req ->getParsedBody ())
40+ throw new HttpBadRequestException ($ req , "Please enter valid form data. " );
41+
42+ $ data = $ this ->_model ->insert ([...$ req ->getParsedBody (), ...$ args ]);
4043 return response ($ req , $ res , new Response (message: "This item has been successfully added. " , data: $ data ));
4144 }
4245
4346 /** Update by Id */
4447 public function update ($ req , $ res , $ args ) {
48+ if (!$ req ->getParsedBody ())
49+ throw new HttpBadRequestException ($ req , "Please enter valid form data. " );
50+
4551 $ data = $ this ->_model ->update ($ req ->getParsedBody (), $ args );
4652 checkNull ($ data , $ req );
4753 return response ($ req , $ res , new Response (message: "This item has been successfully updated. " , data: $ data ));
0 commit comments