Commit d186a97c authored by Zohten's avatar Zohten

added post

parent 0aaf1c25
......@@ -33,6 +33,10 @@ class UserController extends Controller
return $this->updateUser(array_merge($body, ['id'=>$uriParams[0]]));
}
break;
case 'POST':
$body = $this->request->getData();
return $this->addUser($body);
break;
}
$message = json_encode(["message" => "unsupported parameters or method in users"]);
return Response::errorResponse($message);
......@@ -63,7 +67,7 @@ class UserController extends Controller
}
/**
* GET all users in USER table
* (GET) Get all users in USER table
*
* @return Response
*/
......@@ -75,7 +79,7 @@ class UserController extends Controller
}
/**
* GET a specific user in USER table based on id
* (GET) Get a specific user in USER table based on id
*
* @param int $id id of the User
* @return Response
......@@ -88,7 +92,21 @@ class UserController extends Controller
}
/**
* Update a specific user in USER table based on id
* (POST) Add a specific user in USER table
*
* @param array $array array containing
* @return Response
*/
protected function addUser($array)
{
User::addRow($array);
$message = json_encode(["message" => 'User succesfully added!']);
$response = Response::okResponse(json_encode($message));
return $response;
}
/**
* (PUT) Update a specific user in USER table based on id
*
* @param array $array array containing id + fields to modify
* @return Response
......@@ -103,7 +121,7 @@ class UserController extends Controller
// Update phase
User::updateUser($array);
$message = json_encode(["message" => 'User succesfully updated !']);
$message = json_encode(["message" => 'User succesfully updated!']);
$response = Response::okResponse($message);
return $response;
......
......@@ -20,6 +20,12 @@ class User extends Model
return $stm->fetchAll();
}
public static function addRow($array)
{
//print_r($array); die();
$stm = parent::exec('USER_CREATE', $array);
}
public static function updateUser($array)
{
$stm = parent::exec('USER_UPDATE', $array);
......
......@@ -18,7 +18,8 @@ User::addSqlQuery(
//TODO
User::addSqlQuery(
'USER_CREATE',
'INSERT INTO MJ_USER (USER_ID, USER_LOGIN, USER_EMAIL, USER_ROLE, USER_PASSWORD, USER_NAME, USER_SURNAME) VALUES (NULL, :login, :email, :role, :pwd, :name, :surname)'
'INSERT INTO MJ_USER (ID_USER ,ID_ROLE ,LOGIN ,PASWORD ,AVATAR ,LASTNAME ,FIRSTNAME ,MAIL ,BAN_ACCOUNT ,LAST_IP)
VALUES (NULL, 1, :login, :pwd, :avatar, :lastname, :firstname, :mail, false, NULL)'
);
User::addSqlQuery(
......
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