4
4
5
5
use RestJS \Message \Response ;
6
6
use function RestJS \response , RestJS \checkNull ;
7
+ use Slim \Exception \HttpBadRequestException ;
7
8
8
9
/** Abstract Controller Functions */
9
10
class AbstractController {
@@ -23,7 +24,6 @@ public function findAll($req, $res) {
23
24
/** Find Data by Column */
24
25
public function findByColumn ($ req , $ res , $ args ) {
25
26
$ data = $ this ->_model ->findBy ($ args );
26
- checkNull ($ data , $ req );
27
27
return response ($ req , $ res , args: new Response (data: [...$ data ]));
28
28
}
29
29
@@ -36,12 +36,18 @@ public function delete($req, $res, $args) {
36
36
37
37
/** Insert Data */
38
38
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 ]);
40
43
return response ($ req , $ res , new Response (message: "This item has been successfully added. " , data: $ data ));
41
44
}
42
45
43
46
/** Update by Id */
44
47
public function update ($ req , $ res , $ args ) {
48
+ if (!$ req ->getParsedBody ())
49
+ throw new HttpBadRequestException ($ req , "Please enter valid form data. " );
50
+
45
51
$ data = $ this ->_model ->update ($ req ->getParsedBody (), $ args );
46
52
checkNull ($ data , $ req );
47
53
return response ($ req , $ res , new Response (message: "This item has been successfully updated. " , data: $ data ));
0 commit comments