Ajout: load match
continuous-integration/drone/push Build is passing Details

peristanceBDD
Thomas Chazot 2 years ago
parent 1c30bdffb5
commit 5b2b142646

@ -51,15 +51,28 @@ class GameGateway{
public function getGameById(string $id):?Game{ public function getGameById(string $id):?Game{
$game=null; $game=null;
$gameInfoQuery="SELECT * FROM T_E_GAME_GAM WHERE PK_ID=:id"; $gameInfoQuery="SELECT * FROM T_E_GAME_GAM WHERE PK_ID=:id";
$mapQuery="SELECT * FROM T_J_GAME_MAP_GMP WHERE FK_GAME=:id ORDER BY GMP_KEY";
$arg=array('id'=>array($id,PDO::PARAM_STR)); $arg=array('id'=>array($id,PDO::PARAM_STR));
$this->connection->execQuery($gameInfoQuery,$arg); $this->connection->execQuery($gameInfoQuery,$arg);
$res=$this->connection->getRes(); $res=$this->connection->getRes();
foreach($res as $row){ foreach($res as $row){
$tabKey=[];
$tabValue=[];
$arg=array(':id'=>array($row['PK_ID'], PDO::PARAM_INT));
$this->connection->execQuery($mapQuery,$arg);
$resMap = $this->connection->getRes();
foreach($resMap as $rowMap){
$tabKey[]=$rowMap['GMP_KEY'];
$tabValue[]=$rowMap['GMP_VALUE'];
}
$game= new Game($row['PK_ID'], $game= new Game($row['PK_ID'],
$row['GAM_NAME'], $row['GAM_NAME'],
$row['GAM_IMAGE'], $row['GAM_IMAGE'],
$row['GAM_TYPE'],
$row['GAM_NB_PLAYER_MIN'], $row['GAM_NB_PLAYER_MIN'],
$row['GAM_NB_PLAYER_MAX']); $row['GAM_NB_PLAYER_MAX'],
$tabKey,
$tabValue);
} }
return $game; return $game;
} }

@ -1,18 +1,25 @@
import React from "react"; import React from "react";
import create from "zustand"; import create from "zustand";
import { Match } from "../core/Match/match"; import { Match } from "../core/Match/match";
import { User } from "../core/User/user";
// Define store types // Define store types
interface MatchState { interface MatchState {
match: Match | null; match: Match | null;
tabUser: User[] | null[];
setMatch: (match: Match|null) => void; setMatch: (match: Match|null) => void;
resetMatch: () => void; resetMatch: () => void;
setTabUser: (tabUser: User[] | null[]) => void;
resetTabUser: () => void;
} }
// Define store data and methods // Define store data and methods
export const useMatchStore = create<MatchState>()((set, get) => ({ export const useMatchStore = create<MatchState>()((set, get) => ({
match: null, match: null,
tabUser: [],
setMatch: (match) => set((state) => ({ match: match })), setMatch: (match) => set((state) => ({ match: match })),
resetMatch: () => set((state) => ({ match: null })), resetMatch: () => set((state) => ({ match: null })),
setTabUser: (tabUser) => set((state) => ({ tabUser: tabUser })),
resetTabUser: () => set((state) => ({ tabUser: [] })),
})); }));

@ -9,7 +9,7 @@ import { RootState } from '../redux/store';
import { updateIncorrectCredentials } from '../redux/features/credentialErrorsSlice'; import { updateIncorrectCredentials } from '../redux/features/credentialErrorsSlice';
import Dialog from "react-native-dialog"; import Dialog from "react-native-dialog";
import { useUserStore } from '../context/userContext'; import { useUserStore } from '../context/userContext';
import { MANAGER_CONVERSATION, MANAGER_GAME, MANAGER_SKIN, MANAGER_USER } from '../../appManagers'; import { MANAGER_CONVERSATION, MANAGER_GAME, MANAGER_MATCH, MANAGER_SKIN, MANAGER_USER } from '../../appManagers';
import { socket } from "../../socketConfig"; import { socket } from "../../socketConfig";
import { useConversationStore } from '../context/conversationContext'; import { useConversationStore } from '../context/conversationContext';
import { useGameStore } from '../context/gameContext'; import { useGameStore } from '../context/gameContext';
@ -63,7 +63,8 @@ function SignIn(props: { navigation: any; }) {
socket.on("messageReceived", async () =>{ socket.on("messageReceived", async () =>{
await handleConversationLoad(); await handleConversationLoad();
}); });
const match=await MANAGER_MATCH.getLoaderMatch().loadByID(1);
console.log(match);
navigation.navigate('HomeTab'); navigation.navigate('HomeTab');
} }
else{ else{

@ -13,5 +13,5 @@ export default interface ILoaderGame{
* id the id we want to search * id the id we want to search
* return a Game if found, if not null * return a Game if found, if not null
*/ */
loadByID(id:string): Promise<Game | null>; loadByID(id:number): Promise<Game | null>;
} }

@ -46,8 +46,33 @@ export default class LoaderGameApi implements ILoaderGame{
return tab; return tab;
} }
async loadByID(id: string): Promise<Game | null> { async loadByID(id: number): Promise<Game | null> {
throw new Error("Method not implemented."); let game: Game|null=null;
const url="http://localhost:8888/api-rest/index.php/getGameById/" + id;
await this.axios({
method: 'get',
url: url,
}).then(function (response: any){
if (response.data!=undefined || response.data!==null){
switch(response.data.type){
case "GameSolo":
let mapSolo = new Map();
for (let i=0; i<response.data.keys.length; i++){
mapSolo.set(new Number(response.data.keys[i]), new Number(response.data.values[i]))
}
game = new GameSolo(response.data.id, response.data.name, response.data.image, response.data.nbPlayerMin, response.data.nbPlayerMax, mapSolo);
case "GameMulti":
const mapMulti = new Map();
for (let i=0; i<response.data.keys.length; i++){
mapMulti.set(new Number(response.data.keys[i]), new Number(response.data.values[i]));
}
game = new GameMulti(response.data.id, response.data.name, response.data.image, response.data.nbPlayerMin, response.data.nbPlayerMax, mapMulti);
case "GameCasino":
game = new GameCasino(response.data.id, response.data.name, response.data.image, response.data.nbPlayerMin, response.data.nbPlayerMax);
}
}
});
return game;
} }
} }

@ -13,5 +13,5 @@ export default interface ILoaderMatch{
* id the id we want to search * id the id we want to search
* return a Match if found, if not null * return a Match if found, if not null
*/ */
loadByID(id:string): Promise<Match | null>; loadByID(id:number): Promise<Match | null>;
} }

@ -1,13 +1,66 @@
import { rejects } from "assert";
import { MANAGER_GAME, MANAGER_USER } from "../../../appManagers";
import { GameCasino } from "../../core/gameCasino";
import { GameMulti } from "../../core/gameMulti";
import { Match } from "../../core/Match/match"; import { Match } from "../../core/Match/match";
import MatchCasino from "../../core/Match/matchCasino";
import MatchMulti from "../../core/Match/matchMulti";
import { User } from "../../core/User/user";
import ILoaderMatch from "./ILoaderMatch"; import ILoaderMatch from "./ILoaderMatch";
export default class LoaderMatchApi implements ILoaderMatch{ export default class LoaderMatchApi implements ILoaderMatch{
private axios = require('axios').default;
async loadAllMatch(): Promise<Match[]> { async loadAllMatch(): Promise<Match[]> {
throw new Error("Method not implemented."); throw new Error("Method not implemented.");
} }
async loadByID(id: string): Promise<Match | null> {
throw new Error("Method not implemented."); async loadByID(id: number): Promise<Match | null> {
let match:Match|null=null;
const url='http://localhost:8888/api-rest/index.php/getMatchById/' + id;
await this.axios({
method: 'get',
url: url,
})
.then(async function (response: any) {
if (response.data != null || response.data != undefined){
match=await jsonToMatch(response);
} }
});
return match;
}
}
async function jsonToMatch(response: any){
let match: Match| null=null;
const tabUs: User[]=[];
let users=new Promise<void>((resolve, reject) => {
response.data.listIdUsers.forEach(async (idUser: number) => {
await MANAGER_USER.getLoaderUser().loadByID(idUser).then((res) =>{
if (res!==null){
tabUs.push(res);
}
});
if (tabUs.length===response.data.listIdUsers.length){
resolve();
}
});
});
const game = await MANAGER_GAME.getLoaderGame().loadByID(response.data.idGame);
await Promise.all([users]);
if (game!==null){
if (game instanceof GameMulti){
match = new MatchMulti(response.data.id, response.data.inGame, tabUs, game);
}
else if (game instanceof GameCasino){
match = new MatchCasino(response.data.id, response.data.inGame, tabUs, game)
}
}
return match;
} }
Loading…
Cancel
Save