ADD : request POST PUT DELETE readOneId and readOneUsername for User
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
parent
8ca5766a11
commit
8a7eb760e0
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
//Headers
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
header("Content-Type: application.json; charset=UTF-8");
|
||||
header("Access-Control-Allow-Method: GET");
|
||||
header("Access-Control-Max-Age: 3600");
|
||||
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
|
||||
|
||||
// Checking that the method is correct and dealing with the error
|
||||
if($_SERVER['REQUEST_METHOD'] != 'DELETE'){
|
||||
http_response_code(405);
|
||||
echo json_encode(["message" => "Unauthorized method"]);
|
||||
}else{
|
||||
include_once '../dbConnection.php';
|
||||
include_once '../models/User.php';
|
||||
|
||||
$db= new Database();
|
||||
$db= $db->establishConnection();
|
||||
|
||||
$user = new User($db);
|
||||
$user->id="4";
|
||||
$user->username="petitFilou";
|
||||
$user->password="blblbl";
|
||||
$user->nationality="Francaise";
|
||||
$user->sex="M";
|
||||
$user->dateOfBirth="2002-05-10";
|
||||
|
||||
|
||||
$stmt = $user->delete();
|
||||
|
||||
if($stmt->rowCount() > 0){
|
||||
|
||||
echo "User deleted successfully";
|
||||
http_response_code(200);
|
||||
|
||||
}
|
||||
else{
|
||||
echo "The user can't be deleted because not found in database";
|
||||
http_response_code(200);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
//Headers
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
header("Content-Type: application.json; charset=UTF-8");
|
||||
header("Access-Control-Allow-Method: GET");
|
||||
header("Access-Control-Max-Age: 3600");
|
||||
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
|
||||
|
||||
// Checking that the method is correct and dealing with the error
|
||||
if($_SERVER['REQUEST_METHOD'] != 'POST'){
|
||||
http_response_code(405);
|
||||
echo json_encode(["message" => "Unauthorized method"]);
|
||||
}else{
|
||||
include_once '../dbConnection.php';
|
||||
include_once '../models/User.php';
|
||||
|
||||
$db= new Database();
|
||||
$db= $db->establishConnection();
|
||||
|
||||
$user = new User($db);
|
||||
$user->id="U0004";
|
||||
$user->username="petitFilou";
|
||||
$user->password="blblbl";
|
||||
$user->nationality="Francaise";
|
||||
$user->sex="M";
|
||||
$user->dateOfBirth="2002-05-10";
|
||||
|
||||
|
||||
$stmt = $user->post();
|
||||
|
||||
if($stmt != false){
|
||||
|
||||
echo "user created successfully :)";
|
||||
http_response_code(200);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
//Headers
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
header("Content-Type: application.json; charset=UTF-8");
|
||||
header("Access-Control-Allow-Method: GET");
|
||||
header("Access-Control-Max-Age: 3600");
|
||||
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
|
||||
|
||||
// Checking that the method is correct and dealing with the error
|
||||
if($_SERVER['REQUEST_METHOD'] != 'PUT'){
|
||||
http_response_code(405);
|
||||
echo json_encode(["message" => "Unauthorized method"]);
|
||||
}else{
|
||||
include_once '../dbConnection.php';
|
||||
include_once '../models/User.php';
|
||||
|
||||
$db= new Database();
|
||||
$db= $db->establishConnection();
|
||||
|
||||
$user = new User($db);
|
||||
$user->id="U0004";
|
||||
$user->username="petitFilou";
|
||||
$user->password="blblbl";
|
||||
$user->nationality="Francaise";
|
||||
$user->sex="M";
|
||||
$user->dateOfBirth="2002-05-10";
|
||||
$user->currentBobCoins=10;
|
||||
$user->totalBobCoins=10;
|
||||
$user->nbGamesPlayed=1;
|
||||
|
||||
$stmt = $user->put();
|
||||
|
||||
if($stmt != false){
|
||||
|
||||
http_response_code(200);
|
||||
echo "User updated successfully :)";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
//Headers
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
header("Content-Type: application.json; charset=UTF-8");
|
||||
header("Access-Control-Allow-Method: GET");
|
||||
header("Access-Control-Max-Age: 3600");
|
||||
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
|
||||
|
||||
// Checking that the method is correct and dealing with the error
|
||||
if($_SERVER['REQUEST_METHOD'] != 'GET'){
|
||||
http_response_code(405);
|
||||
echo json_encode(["message" => "Unauthorized method"]);
|
||||
}else{
|
||||
include_once '../dbConnection.php';
|
||||
include_once '../models/User.php';
|
||||
|
||||
$db= new Database();
|
||||
$db= $db->establishConnection();
|
||||
|
||||
$user = new User($db);
|
||||
$user->id="U0004";
|
||||
|
||||
$stmt = $user->readOneId();
|
||||
|
||||
if($stmt != false){
|
||||
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
extract($row);
|
||||
|
||||
$user= [
|
||||
"id" => $id,
|
||||
"username" => $username,
|
||||
"password" => $password,
|
||||
"nationality" => $nationality,
|
||||
"sex" => $sex,
|
||||
"dateofBirth" => $dateOfBirth,
|
||||
"currentBobCoins"=>$currentBobCoins,
|
||||
"totalBobCoins" => $totalBobCoins,
|
||||
"nbGamesPlayed" => $nbGamesPlayed,
|
||||
];
|
||||
|
||||
http_response_code(200);
|
||||
|
||||
echo json_encode($user);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
//Headers
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
header("Content-Type: application.json; charset=UTF-8");
|
||||
header("Access-Control-Allow-Method: GET");
|
||||
header("Access-Control-Max-Age: 3600");
|
||||
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
|
||||
|
||||
// Checking that the method is correct and dealing with the error
|
||||
if($_SERVER['REQUEST_METHOD'] != 'GET'){
|
||||
http_response_code(405);
|
||||
echo json_encode(["message" => "Unauthorized method"]);
|
||||
}else{
|
||||
include_once '../dbConnection.php';
|
||||
include_once '../models/User.php';
|
||||
|
||||
$db= new Database();
|
||||
$db= $db->establishConnection();
|
||||
|
||||
$user = new User($db);
|
||||
$user->username="lulu";
|
||||
|
||||
$stmt = $user->readOneUsername();
|
||||
|
||||
if($stmt != false){
|
||||
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
extract($row);
|
||||
|
||||
$user= [
|
||||
"id" => $id,
|
||||
"username" => $username,
|
||||
"password" => $password,
|
||||
"nationality" => $nationality,
|
||||
"sex" => $sex,
|
||||
"dateofBirth" => $dateOfBirth,
|
||||
"currentBobCoins"=>$currentBobCoins,
|
||||
"totalBobCoins" => $totalBobCoins,
|
||||
"nbGamesPlayed" => $nbGamesPlayed,
|
||||
];
|
||||
|
||||
http_response_code(200);
|
||||
|
||||
echo json_encode($user);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in new issue