Commit cc6ef9bc authored by Zohten's avatar Zohten

added delete

parent d186a97c
...@@ -37,6 +37,11 @@ class UserController extends Controller ...@@ -37,6 +37,11 @@ class UserController extends Controller
$body = $this->request->getData(); $body = $this->request->getData();
return $this->addUser($body); return $this->addUser($body);
break; break;
case 'DELETE':
if ($uriParams) {
return $this->deleteUser($uriParams[0]);
}
break;
} }
$message = json_encode(["message" => "unsupported parameters or method in users"]); $message = json_encode(["message" => "unsupported parameters or method in users"]);
return Response::errorResponse($message); return Response::errorResponse($message);
...@@ -114,8 +119,9 @@ class UserController extends Controller ...@@ -114,8 +119,9 @@ class UserController extends Controller
protected function updateUser($array) protected function updateUser($array)
{ {
// Auth with token phase // Auth with token phase
if($this->authUser($array['id'])->getCode()!=200){ $authResponse = $this->authUser($id);
return authError; if($authResponse->getCode()!=200){
return $authResponse;
} }
// Update phase // Update phase
...@@ -126,4 +132,27 @@ class UserController extends Controller ...@@ -126,4 +132,27 @@ class UserController extends Controller
return $response; return $response;
} }
/**
* (DELETE) Delete a specific user in USER table based on id
*
* @param int $id id of the User
* @return Response
*/
protected function deleteUser($id)
{
// Auth with token phase
$authResponse = $this->authUser($id);
if($authResponse->getCode()!=200){
return $authResponse;
}
// Update phase
User::deleteRow($id);
$message = json_encode(["message" => 'User succesfully deleted!']);
$response = Response::okResponse($message);
return $response;
}
} }
...@@ -22,10 +22,14 @@ class User extends Model ...@@ -22,10 +22,14 @@ class User extends Model
public static function addRow($array) public static function addRow($array)
{ {
//print_r($array); die();
$stm = parent::exec('USER_CREATE', $array); $stm = parent::exec('USER_CREATE', $array);
} }
public static function deleteRow($id)
{
$stm = parent::exec('USER_DELETE', ['id' => $id]);
}
public static function updateUser($array) public static function updateUser($array)
{ {
$stm = parent::exec('USER_UPDATE', $array); $stm = parent::exec('USER_UPDATE', $array);
......
...@@ -31,3 +31,8 @@ User::addSqlQuery( ...@@ -31,3 +31,8 @@ User::addSqlQuery(
'USER_UPDATE', 'USER_UPDATE',
'UPDATE MJ_USER SET MAIL = :email WHERE ID_USER = :id' 'UPDATE MJ_USER SET MAIL = :email WHERE ID_USER = :id'
); );
User::addSqlQuery(
'USER_DELETE',
'DELETE FROM MJ_USER WHERE ID_USER=:id'
);
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment