@@ -13,8 +13,8 @@ public function getAllUser() : void {
1313 try {
1414 $ result = $ this ->user ->getAllUser ();
1515
16- header ('Content-Type: application/json ' );
1716 http_response_code (200 );
17+ header ('Content-Type: application/json ' );
1818 echo json_encode ([
1919 "status " =>"success " ,
2020 "message " => "successfully get all user data from database " ,
@@ -29,14 +29,14 @@ public function getAllUser() : void {
2929 }
3030 }
3131
32- public function getUserById ($ id ) : void {
32+ public function getUserById ($ userId ) : void {
3333 try {
34- $ result = $ this ->user ->getUserById ($ id );
34+ $ result = $ this ->user ->getUserById ($ userId );
3535
3636 $ message = empty ($ result ) ? "User not found " : "Successfully retrieved user data " ;
3737
38- header ('Content-Type: application/json ' );
3938 http_response_code (empty ($ result ) ? 404 : 200 );
39+ header ('Content-Type: application/json ' );
4040 echo json_encode ([
4141 "status " =>"success " ,
4242 "message " => $ message ,
@@ -66,8 +66,8 @@ public function addNewUser() : void {
6666 $ message = "Successfully add new user data " ;
6767 }
6868
69- header ('Content-Type: application/json ' );
7069 http_response_code (empty ($ result ) ? 400 : 201 );
70+ header ('Content-Type: application/json ' );
7171 echo json_encode ([
7272 "status " =>"success " ,
7373 "message " => $ message ,
@@ -128,8 +128,8 @@ public function editUserData($userId) : void {
128128
129129 $ result = $ this ->user ->getUserById ($ userId );
130130
131- header ('Content-Type: application/json ' );
132131 http_response_code (200 );
132+ header ('Content-Type: application/json ' );
133133 echo json_encode ([
134134 "status " =>"success " ,
135135 "message " => "successfully update data " ,
@@ -143,4 +143,32 @@ public function editUserData($userId) : void {
143143 ]);
144144 }
145145 }
146+
147+ public function deleteUserById ($ userId ) : void {
148+ try {
149+ if (empty ($ this ->user ->getUserById ($ userId ))) {
150+ http_response_code (404 );
151+ echo json_encode ([
152+ "status " => "success " ,
153+ "message " => "user not found "
154+ ]);
155+ exit ;
156+ }
157+
158+ $ this ->user ->deleteUserById ($ userId );
159+
160+ http_response_code (200 );
161+ header ('Content-Type: application/json ' );
162+ echo json_encode ([
163+ "status " =>"success " ,
164+ "message " => "successfully update data "
165+ ]);
166+ } catch (Exception $ e ) {
167+ http_response_code (500 );
168+ echo json_encode ([
169+ "status " => "error " ,
170+ "message " => "server error occured "
171+ ]);
172+ }
173+ }
146174}
0 commit comments