Commit d186a97c authored by Zohten's avatar Zohten

added post

parent 0aaf1c25
...@@ -33,6 +33,10 @@ class UserController extends Controller ...@@ -33,6 +33,10 @@ class UserController extends Controller
return $this->updateUser(array_merge($body, ['id'=>$uriParams[0]])); return $this->updateUser(array_merge($body, ['id'=>$uriParams[0]]));
} }
break; break;
case 'POST':
$body = $this->request->getData();
return $this->addUser($body);
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);
...@@ -63,7 +67,7 @@ class UserController extends Controller ...@@ -63,7 +67,7 @@ class UserController extends Controller
} }
/** /**
* GET all users in USER table * (GET) Get all users in USER table
* *
* @return Response * @return Response
*/ */
...@@ -75,7 +79,7 @@ class UserController extends Controller ...@@ -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 * @param int $id id of the User
* @return Response * @return Response
...@@ -88,7 +92,21 @@ class UserController extends Controller ...@@ -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 * @param array $array array containing id + fields to modify
* @return Response * @return Response
...@@ -103,7 +121,7 @@ class UserController extends Controller ...@@ -103,7 +121,7 @@ class UserController extends Controller
// Update phase // Update phase
User::updateUser($array); User::updateUser($array);
$message = json_encode(["message" => 'User succesfully updated !']); $message = json_encode(["message" => 'User succesfully updated!']);
$response = Response::okResponse($message); $response = Response::okResponse($message);
return $response; return $response;
......
...@@ -20,6 +20,12 @@ class User extends Model ...@@ -20,6 +20,12 @@ class User extends Model
return $stm->fetchAll(); return $stm->fetchAll();
} }
public static function addRow($array)
{
//print_r($array); die();
$stm = parent::exec('USER_CREATE', $array);
}
public static function updateUser($array) public static function updateUser($array)
{ {
$stm = parent::exec('USER_UPDATE', $array); $stm = parent::exec('USER_UPDATE', $array);
......
...@@ -18,7 +18,8 @@ User::addSqlQuery( ...@@ -18,7 +18,8 @@ User::addSqlQuery(
//TODO //TODO
User::addSqlQuery( User::addSqlQuery(
'USER_CREATE', '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( 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