Commit 7d046c74 authored by thibaut-felten's avatar thibaut-felten

API URL

parent ba60d466
......@@ -105,7 +105,25 @@ class UserController extends Controller {
$firstname = $userValues->USER_FIRSTNAME;
}
$user = User::updateUser(array("id" => $id, "login" => $login,"email" => $email,"lastname" => $lastname,"firstname" => $firstname));
if(array_key_exists('USER_ROCK',$data)){
$rock = $data['USER_ROCK'];
}else{
$rock = $userValues->USER_ROCK + $data['USER_ROCK'];
}
if(array_key_exists('USER_PAPER',$data)){
$paper = $data['USER_PAPER'] ;
}else{
$paper = $userValues->USER_PAPER + $data['USER_PAPER'];
}
if(array_key_exists('USER_SCISSORS',$data)){
$scissors = $data['USER_SCISSORS'] ;
}else{
$scissors = $userValues->USER_SCISSORS + $data['USER_SCISSORS'];
}
$user = User::updateUser(array("id" => $id, "login" => $login,"email" => $email,"lastname" => $lastname,"firstname" => $firstname, "paper" => $paper, "scissors" => $scissors, "rock" => $rock));
$response = new Response(200,json_encode($user));
return $response;
}
......
......@@ -13,7 +13,7 @@ User::addSqlQuery('USER_BY_ID',
'SELECT * FROM USER WHERE USER_ID=:user_id');
User::addSqlQuery('USER_UPDATE',
"UPDATE USER SET USER_LOGIN=:login, USER_EMAIL=:email, USER_LASTNAME=:lastname, USER_FIRSTNAME=:firstname WHERE USER_ID=:id");
"UPDATE USER SET USER_LOGIN=:login, USER_EMAIL=:email, USER_LASTNAME=:lastname, USER_FIRSTNAME=:firstname, USER_ROCK=:rock, USER_SCISSORS=:scissors, USER_PAPER=:paper WHERE USER_ID=:id");
User::addSqlQuery('USER_DELETE',
"DELETE FROM USER WHERE USER_ID=:id");
......
......@@ -4,6 +4,8 @@ import router from './router'
Vue.config.productionTip = false
sessionStorage.setItem('APIURL', 'http://localhost/projet-cdaw/backend/MVC/api.php')
new Vue({
router,
render: h => h(App)
......
......@@ -34,7 +34,7 @@ export default {
name: 'AdminPrivate',
methods: {
createIdGame: async function(){
const url = "http://localhost/felten/projet-cdaw/backend/MVC/api.php/game"
const url = sessionStorage.getItem('APIURL') + "/game"
let data = {
"GAME_DESC": "testHTML"
......@@ -68,7 +68,7 @@ export default {
await this.JoueurPresent()
},
ajoutAdminGame: async function(){
const url = "http://localhost/felten/projet-cdaw/backend/MVC/api.php/gameuser"
const url = sessionStorage.getItem('APIURL') + "/gameuser"
console.log(game.id)
let data = {
"GAME_ID": game.id,
......@@ -82,7 +82,7 @@ export default {
await fetch(url,params)
},
JoueurPresent: async function(){
let url = "http://localhost/felten/projet-cdaw/backend/MVC/api.php/gameuser/game"
let url = sessionStorage.getItem('APIURL') + "/gameuser/game"
console.log(game.id)
url += "/" + game.id;
var params = {
......
......@@ -39,7 +39,7 @@ const user = require("../model/user.js")
export default {
name: "RockPaperScissors",
data: function () {
return { oponentScore: 0, myScore: 0 }
return { oponentScore: 0, myScore: 0 , rock : 0, paper : 0, scissors: 0}
},
methods: {
select: async function (value) {
......@@ -51,7 +51,7 @@ export default {
havePlayed = true
document.getElementById(value).classList.add("selected")
await fetch(
`http://localhost/felten/projet-cdaw/backend/MVC/api.php/result/${gameID}`,
sessionStorage.getItem('APIURL') + `/result/${gameID}`,
{
method: "POST",
body: JSON.stringify({
......@@ -64,7 +64,7 @@ export default {
},
getResult: async function(gameID,value) {
const res = await fetch(
`http://localhost/felten/projet-cdaw/backend/MVC/api.php/result/${gameID}`,
sessionStorage.getItem('APIURL') + `/result/${gameID}`,
{
method: "GET"
}
......@@ -92,6 +92,7 @@ export default {
}
const valueAgainst = result[i]['RESULT_AWNSER']
if(value === "paper"){
this.paper += 1
if(valueAgainst === "rock"){
this.myScore +=1
}
......@@ -99,6 +100,7 @@ export default {
this.oponentScore +=1
}
}else if(value === "rock"){
this.rock +=1
if(valueAgainst === "paper"){
this.oponentScore+=1
}
......@@ -106,6 +108,7 @@ export default {
this.myScore +=1
}
}else{
this.scissors+=1
if(valueAgainst === "paper"){
this.myScore +=1
}
......@@ -115,13 +118,30 @@ export default {
}
if(this.myScore >= 3){
alert("Vous avez gagné !")
this.updateUser()
this.$router.push("/")
}
else if(this.oponentScore >= 3){
alert("Vous avez perdu ...")
this.updateUser()
this.$router.push("/")
}
},
updateUser: async function(){
let rock = this.rock
let paper = this.paper
let scissors = this.scissors
await fetch(
sessionStorage.getItem('APIURL') + `/user/${user.id}`,
{
method: "PUT",
body: JSON.stringify({USER_PAPER: paper, USER_ROCK: rock, USER_SCISSORS: scissors}),
}
)
}
,
resetGame: async function(result) {
let i = 0;
......@@ -129,7 +149,7 @@ export default {
i = 1
}
await fetch(
'http://localhost/felten/projet-cdaw/backend/MVC/api.php/result',
sessionStorage.getItem('APIURL') + '/result',
{
method: "DELETE",
body: JSON.stringify({USER_ID: result[i]['USER_ID']})
......
......@@ -138,11 +138,7 @@ export default {
},
call: function(data){
// Felten config
// const url = "http://localhost/projet-cdaw/backend/MVC/api.php/user"
// Robin config
const url = "http://localhost/felten/projet-cdaw/backend/MVC/api.php/user"
const url = sessionStorage.getItem('APIURL') + "/user"
var params = {
method: 'POST',
......
......@@ -28,7 +28,7 @@ export default {
console.log(Number(this.idgame) < 0)
return
}
const url = "http://localhost/felten/projet-cdaw/backend/MVC/api.php/gameuser"
const url = sessionStorage.getItem('APIURL') + "/gameuser"
let data = {
"GAME_ID": this.idgame,
......
......@@ -96,11 +96,7 @@ export default {
},
call: function(login, password){
// Felten config
// const url = "http://localhost/projet-cdaw/backend/MVC/api.php/login"
// Robin config
const url = "http://localhost/felten/projet-cdaw/backend/MVC/api.php/login"
const url = sessionStorage.getItem('APIURL') + "/login"
let data = {
login: login,
......
......@@ -37,7 +37,7 @@ export default {
return game.id
},
JoueurPresent: async function(){
let url = "http://localhost/felten/projet-cdaw/backend/MVC/api.php/gameuser/game"
let url = sessionStorage.getItem('APIURL') + "/gameuser/game"
console.log(game.id)
url += "/" + game.id;
var params = {
......
......@@ -138,7 +138,7 @@ export default {
},
call: function(data){
const url = "http://localhost/projet-cdaw/backend/MVC/api.php/user"
const url = sessionStorage.getItem('APIURL') + "/user"
var params = {
method: 'POST',
......
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