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

API URL

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