Commit cc6ef9bc authored by Zohten's avatar Zohten

added delete

parent d186a97c
......@@ -37,6 +37,11 @@ class UserController extends Controller
$body = $this->request->getData();
return $this->addUser($body);
break;
case 'DELETE':
if ($uriParams) {
return $this->deleteUser($uriParams[0]);
}
break;
}
$message = json_encode(["message" => "unsupported parameters or method in users"]);
return Response::errorResponse($message);
......@@ -114,8 +119,9 @@ class UserController extends Controller
protected function updateUser($array)
{
// Auth with token phase
if($this->authUser($array['id'])->getCode()!=200){
return authError;
$authResponse = $this->authUser($id);
if($authResponse->getCode()!=200){
return $authResponse;
}
// Update phase
......@@ -126,4 +132,27 @@ class UserController extends Controller
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
public static function addRow($array)
{
//print_r($array); die();
$stm = parent::exec('USER_CREATE', $array);
}
public static function deleteRow($id)
{
$stm = parent::exec('USER_DELETE', ['id' => $id]);
}
public static function updateUser($array)
{
$stm = parent::exec('USER_UPDATE', $array);
......
......@@ -31,3 +31,8 @@ User::addSqlQuery(
'USER_UPDATE',
'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