Merge branch 'Persistance' of https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY into stub-api
commit
ba54ed12df
@ -0,0 +1,2 @@
|
|||||||
|
{
|
||||||
|
}
|
@ -1,6 +1,34 @@
|
|||||||
import React from 'react'
|
|
||||||
import MainTabNavigator from './src/navigation/AppNavigator'
|
import MainTabNavigator from './src/navigation/AppNavigator'
|
||||||
|
import store from './src/redux/store'
|
||||||
|
import { Provider } from 'react-redux'
|
||||||
|
import LoaderUserApi from './src/services/userServices/loaderUserApi'
|
||||||
|
import ManagerUser from './src/services/userServices/managerUser'
|
||||||
|
import FakeSaverUser from './src/services/userServices/fakeSaverUser'
|
||||||
|
import React, { useCallback } from 'react';
|
||||||
|
import { useUserStore } from './src/context/userContext';
|
||||||
|
import ManagerConversation from './src/services/conversationService/managerConversation'
|
||||||
|
import { LoaderConversationApi } from './src/services/conversationService/loaderConversationApi'
|
||||||
|
import { FakeSaverConversation } from './src/services/conversationService/fakeSaverConversation'
|
||||||
|
import ManagerMatch from './src/services/matchServices/managerMatch'
|
||||||
|
import LoaderMatchApi from './src/services/matchServices/loaderMatchApi'
|
||||||
|
import SaverMatchApi from './src/services/matchServices/saverMatchApi'
|
||||||
|
import LoaderGameApi from './src/services/gameService/loaderGameApi'
|
||||||
|
import ManagerGame from './src/services/gameService/managerGame'
|
||||||
|
|
||||||
|
|
||||||
|
export const MANAGER_USER = new ManagerUser(new LoaderUserApi, new FakeSaverUser);
|
||||||
|
export const MANAGER_CONVERSATION = new ManagerConversation(new LoaderConversationApi, new FakeSaverConversation);
|
||||||
|
export const MANAGER_MATCH = new ManagerMatch(new LoaderMatchApi, new SaverMatchApi);
|
||||||
|
export const MANAGER_GAME = new ManagerGame(new LoaderGameApi);
|
||||||
|
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
return <MainTabNavigator/>
|
|
||||||
|
return (
|
||||||
|
<Provider store={store}>
|
||||||
|
<MainTabNavigator/>
|
||||||
|
</Provider>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
After Width: | Height: | Size: 35 KiB |
@ -1,6 +1,13 @@
|
|||||||
module.exports = function(api) {
|
module.exports = function(api) {
|
||||||
api.cache(true);
|
api.cache(true);
|
||||||
return {
|
return {
|
||||||
presets: ['babel-preset-expo'],
|
presets: [
|
||||||
|
['babel-preset-expo'],
|
||||||
|
'@babel/preset-typescript',
|
||||||
|
],
|
||||||
|
presets: [
|
||||||
|
['@babel/preset-env', { targets: { node: 'current' } }],
|
||||||
|
'@babel/preset-typescript', '@babel/preset-react'
|
||||||
|
],
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
module.exports = {
|
||||||
|
preset: 'ts-jest',
|
||||||
|
testEnvironment: 'node',
|
||||||
|
testMatch: ["**/__tests__/**/*.ts?(x)", "**/?(*.)+(test).ts?(x)"],
|
||||||
|
transformIgnorePatterns: ['/node_modules/(?!(foo|bar)/)', '/bar/'],
|
||||||
|
};
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,221 @@
|
|||||||
|
import React, { Component, useCallback, useEffect, useState } from 'react'
|
||||||
|
import {
|
||||||
|
StyleSheet,
|
||||||
|
TouchableOpacity,
|
||||||
|
Text,
|
||||||
|
View,
|
||||||
|
Pressable,
|
||||||
|
Image,
|
||||||
|
TouchableHighlight,
|
||||||
|
Alert,
|
||||||
|
} from 'react-native'
|
||||||
|
import { MANAGER_MATCH, MANAGER_USER } from '../../../App';
|
||||||
|
import { useMatchStore } from '../../context/matchContext';
|
||||||
|
import { useUserStore } from '../../context/userContext';
|
||||||
|
import { Match } from '../../core/Match/match';
|
||||||
|
import { User } from '../../core/User/user';
|
||||||
|
|
||||||
|
|
||||||
|
let points=0;
|
||||||
|
|
||||||
|
function CookieClicker(props: { navigation: any}){
|
||||||
|
const { navigation } = props
|
||||||
|
|
||||||
|
const GAMING_TIME=45;
|
||||||
|
|
||||||
|
const setUser = useUserStore((state) => state.setUser);
|
||||||
|
|
||||||
|
const resetMatch = useMatchStore((state) => state.resetMatch);
|
||||||
|
|
||||||
|
const [count, setCount] = useState(0);
|
||||||
|
const [money, setMoney] = useState(0);
|
||||||
|
const [clickSpeed, setClickSpeed] = useState(1);
|
||||||
|
const [grandmaCost, setGrandmaCost] = useState(10);
|
||||||
|
const [farmCost, setFarmCost] = useState(250);
|
||||||
|
const [factoryCost, setFactoryCost] = useState(2000);
|
||||||
|
const [wizardCost, setWizardCost] = useState(25000);
|
||||||
|
const [portalCost, setPortalCost] = useState(200000);
|
||||||
|
|
||||||
|
const [timer, setTimer] = useState(GAMING_TIME);
|
||||||
|
|
||||||
|
|
||||||
|
function onPressCookie(){
|
||||||
|
setMoney(money+clickSpeed);
|
||||||
|
setCount(count+clickSpeed);
|
||||||
|
points=count+clickSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onPressGrandma(){
|
||||||
|
if (money>=grandmaCost){
|
||||||
|
setMoney(money-grandmaCost);
|
||||||
|
setClickSpeed(clickSpeed+1);
|
||||||
|
setGrandmaCost(grandmaCost+10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onPressFarm(){
|
||||||
|
if (money>=farmCost){
|
||||||
|
setMoney(money-farmCost);
|
||||||
|
setClickSpeed(clickSpeed+25);
|
||||||
|
setFarmCost(farmCost+250);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onPressFactory(){
|
||||||
|
if (money>=factoryCost){
|
||||||
|
setMoney(money-factoryCost);
|
||||||
|
setClickSpeed(clickSpeed+200);
|
||||||
|
setFactoryCost(factoryCost+2000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onPressWizard(){
|
||||||
|
if (money>=wizardCost){
|
||||||
|
setMoney(money-wizardCost);
|
||||||
|
setClickSpeed(clickSpeed+2500);
|
||||||
|
setWizardCost(wizardCost+25000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onPressPortal(){
|
||||||
|
if (money>=portalCost){
|
||||||
|
setMoney(money-portalCost);
|
||||||
|
setClickSpeed(clickSpeed+20000);
|
||||||
|
setPortalCost(portalCost+200000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function endGame(){
|
||||||
|
let tmp: User | null;
|
||||||
|
tmp=MANAGER_USER.getCurrentUser();
|
||||||
|
if (tmp!=null){
|
||||||
|
if (MANAGER_MATCH.getCurrentMatch()?.getTabUsers().includes(tmp)){
|
||||||
|
MANAGER_MATCH.getCurrentMatch()?.updatePostMatch(tmp, points);
|
||||||
|
setUser(tmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resetMatch();
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let counter=GAMING_TIME;
|
||||||
|
var oneSecInterval = setInterval(() => {
|
||||||
|
setTimer(timer => timer - 1);
|
||||||
|
counter --;
|
||||||
|
|
||||||
|
if (counter == 0) {
|
||||||
|
clearInterval(oneSecInterval);
|
||||||
|
endGame();
|
||||||
|
Alert.alert("fin du jeu");
|
||||||
|
navigation.navigate('Home');
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
|
},[]);
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={styles.container}>
|
||||||
|
<View >
|
||||||
|
<Text>
|
||||||
|
Timer: {timer}
|
||||||
|
</Text>
|
||||||
|
<TouchableHighlight onPress={onPressCookie} >
|
||||||
|
<Image style={styles.photo} source={{uri: 'https://cdn-icons-png.flaticon.com/512/614/614131.png'}}/>
|
||||||
|
</TouchableHighlight>
|
||||||
|
<Text>
|
||||||
|
Argent {money}
|
||||||
|
</Text>
|
||||||
|
<Text>
|
||||||
|
Points {count}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
<View style={styles.containerRight}>
|
||||||
|
<TouchableHighlight onPress={onPressGrandma}>
|
||||||
|
<Image style={styles.photo} source={{uri: 'https://www.pngall.com/wp-content/uploads/12/Grandma-Happy-PNG-Photo.png'}}/>
|
||||||
|
</TouchableHighlight>
|
||||||
|
<View>
|
||||||
|
<Text style={styles.cout}>
|
||||||
|
Cost {grandmaCost}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<TouchableHighlight onPress={onPressFarm} style={styles.photo}>
|
||||||
|
<Image style={styles.photo} source={{uri: 'https://www.pngall.com/wp-content/uploads/8/Farming-PNG-Picture.png'}}/>
|
||||||
|
</TouchableHighlight>
|
||||||
|
<View>
|
||||||
|
<Text style={styles.cout}>
|
||||||
|
Cost {farmCost}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<TouchableHighlight onPress={onPressFactory}>
|
||||||
|
<Image style={styles.photo} source={{uri: 'https://cdn.pixabay.com/photo/2018/04/16/09/12/factory-3323977_960_720.png'}}/>
|
||||||
|
</TouchableHighlight>
|
||||||
|
<View>
|
||||||
|
<Text style={styles.cout}>
|
||||||
|
Cost {factoryCost}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<TouchableHighlight onPress={onPressWizard}>
|
||||||
|
<Image style={styles.photo} source={{uri: 'https://www.clasher.us/images/coc/units/Wizard_Tower7.png'}}/>
|
||||||
|
</TouchableHighlight>
|
||||||
|
<View>
|
||||||
|
<Text style={styles.cout}>
|
||||||
|
Cost {wizardCost}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<TouchableHighlight onPress={onPressPortal}>
|
||||||
|
<Image style={styles.photo} source={{uri: 'https://i.pinimg.com/originals/98/29/21/9829215db6f9210c0ae4e318e854cb1f.png'}}/>
|
||||||
|
</TouchableHighlight>
|
||||||
|
<View>
|
||||||
|
<Text style={styles.cout}>
|
||||||
|
Cost {portalCost}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
container: {
|
||||||
|
top: 75,
|
||||||
|
margin: 10,
|
||||||
|
flex: 1,
|
||||||
|
justifyContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
|
},
|
||||||
|
containerRight: {
|
||||||
|
flex: 1,
|
||||||
|
flexWrap: "wrap",
|
||||||
|
top: 100,
|
||||||
|
marginBottom: 20,
|
||||||
|
left: 100,
|
||||||
|
},
|
||||||
|
|
||||||
|
button: {
|
||||||
|
alignItems: 'center',
|
||||||
|
backgroundColor: '#DDDDDD',
|
||||||
|
padding: 10,
|
||||||
|
marginBottom: 10
|
||||||
|
},
|
||||||
|
button2: {
|
||||||
|
alignItems: 'center',
|
||||||
|
backgroundColor: '#FFDDFF',
|
||||||
|
padding: 10,
|
||||||
|
marginBottom: 10
|
||||||
|
},
|
||||||
|
photo: {
|
||||||
|
width: 50,
|
||||||
|
height: 50
|
||||||
|
},
|
||||||
|
cout: {
|
||||||
|
marginBottom: 20
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
export default CookieClicker;
|
@ -0,0 +1,21 @@
|
|||||||
|
import { FC} from "react"
|
||||||
|
import { Pressable, Text} from "react-native"
|
||||||
|
import React from "react"
|
||||||
|
import styles from "./style/PickerGreySmall"
|
||||||
|
import RNPickerSelect from "react-native-picker-select";
|
||||||
|
|
||||||
|
export const PickerGreySmall:
|
||||||
|
FC<{ valueChange: any, title: string, donePress?: any, values?: any;}>
|
||||||
|
=
|
||||||
|
({valueChange, donePress, title, values}) =>
|
||||||
|
{
|
||||||
|
return(
|
||||||
|
<RNPickerSelect
|
||||||
|
placeholder={{label:title, value: null}}
|
||||||
|
onValueChange={valueChange}
|
||||||
|
onDonePress={donePress}
|
||||||
|
items={values}
|
||||||
|
style={styles}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
import { StyleSheet } from "react-native";
|
||||||
|
|
||||||
|
export default StyleSheet.create(
|
||||||
|
{inputIOS: {
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
padding: 3,
|
||||||
|
marginTop: 5,
|
||||||
|
borderRadius: 10,
|
||||||
|
backgroundColor: '#2D2C33',
|
||||||
|
paddingHorizontal: 10,
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: 'bold',
|
||||||
|
letterSpacing: 0.25,
|
||||||
|
textAlign: 'center',
|
||||||
|
color: 'white',
|
||||||
|
},
|
||||||
|
placeholder: {
|
||||||
|
color: 'white',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{inputAndroid: {
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
padding: 3,
|
||||||
|
marginTop: 5,
|
||||||
|
borderRadius: 10,
|
||||||
|
backgroundColor: '#2D2C33',
|
||||||
|
paddingHorizontal: 10,
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: 'bold',
|
||||||
|
letterSpacing: 0.25,
|
||||||
|
textAlign: 'center',
|
||||||
|
color: 'white',
|
||||||
|
},
|
||||||
|
placeholder: {
|
||||||
|
color: 'white',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
@ -1,25 +0,0 @@
|
|||||||
import { Message } from "./core/message"
|
|
||||||
import { Conversation } from "./core/conversation"
|
|
||||||
import tabSkinApp from './constSkin'
|
|
||||||
import { User } from "./core/User/user";
|
|
||||||
|
|
||||||
|
|
||||||
let UserActu:User=new User("14", "leBg", "MdpDeOuf", "ouioui", "grand", new Date(2022,12,12), 12222, 123324, 12, tabSkinApp[0], tabSkinApp, undefined);
|
|
||||||
let UserTest:User=new User("48", "Wesh Wesh", "MdpDeOuf", "ouioui", "grand", new Date(2022,12,12), 12222, 123324, 12, tabSkinApp[5], tabSkinApp, undefined);
|
|
||||||
|
|
||||||
let tabMessageTest:Message[]=[
|
|
||||||
new Message("Salut", UserActu, new Date(2022,12,12,11,30,40)),
|
|
||||||
new Message("Wesh", UserTest, new Date(2022,12,13,12,20,40)),
|
|
||||||
new Message("Ca va", UserActu, new Date(2022,12,14, 12, 30, 35)),
|
|
||||||
new Message("Ouais et toi?", UserTest, new Date(2022,12,14,12,35,0)),
|
|
||||||
]
|
|
||||||
|
|
||||||
let tabUS:User[]=[UserActu, UserTest];
|
|
||||||
|
|
||||||
let conv = new Conversation(tabUS, tabMessageTest, "le super nom");
|
|
||||||
|
|
||||||
let tabConv:Conversation[]=[conv];
|
|
||||||
|
|
||||||
export default tabConv;
|
|
||||||
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
|||||||
|
|
||||||
const tabNat = [
|
|
||||||
{ label: "France", value: "Français" },
|
|
||||||
{ label: "Allemagne", value: "Allemand" },
|
|
||||||
{ label: "Espagne", value: "Espagnol" },
|
|
||||||
{ label: "Royaume-Uni", value: "Anglais" },
|
|
||||||
{ label: "États-Unis", value: "Américain" },
|
|
||||||
{ label: "Italie", value: "Italien" },
|
|
||||||
]
|
|
||||||
|
|
||||||
export default tabNat;
|
|
@ -1,9 +0,0 @@
|
|||||||
|
|
||||||
const tabSex = [
|
|
||||||
{ label: "Homme", value: "Homme" },
|
|
||||||
{ label: "Femmme", value: "Femmme" },
|
|
||||||
{ label: "Non-binaire", value: "Non-binaire" },
|
|
||||||
{ label: "Autre", value: "Autre" },
|
|
||||||
]
|
|
||||||
|
|
||||||
export default tabSex;
|
|
@ -1,15 +1,13 @@
|
|||||||
import { Message } from "./core/message"
|
|
||||||
import { Conversation } from "./core/conversation"
|
|
||||||
import tabSkinApp from './constSkin'
|
import tabSkinApp from './constSkin'
|
||||||
import { User } from "./core/User/user";
|
import { User } from "./core/User/user";
|
||||||
import tabConv from "./constCov";
|
|
||||||
|
|
||||||
|
|
||||||
let UserActu:User=new User("14", "leBg", "MdpDeOuf", "ouioui", "grand", new Date(2022,12,12), 12222, 123324, 12, tabSkinApp[0], tabSkinApp, undefined);
|
let UserActu:User=new User(14, "leBg", "MdpDeOuf", "ouioui", "grand", new Date(2022,12,12), 12222, 123324, 12, tabSkinApp[0], tabSkinApp);
|
||||||
let UserTest:User=new User("48", "WeshWesh", "MdpDeOuf", "ouioui", "grand", new Date(2022,12,12), 12222, 123324, 12, tabSkinApp[2], tabSkinApp, undefined);
|
let Alban:User=new User(17, "Alban", "oui", "ouioui", "homme", new Date(2022,12,12), 555, 667, 12, tabSkinApp[1], tabSkinApp);
|
||||||
let Alban:User=new User("17", "Alban", "oui", "ouioui", "homme", new Date(2022,12,12), 555, 667, 12, tabSkinApp[1], tabSkinApp, tabConv);
|
let Fefe63:User=new User(18, "Fefe63", "jesuishm", "ouioui", "homme", new Date(2022,12,12), 12222, 123324, 12, tabSkinApp[6], tabSkinApp);
|
||||||
let Fefe63:User=new User("17", "Fefe63", "jesuishm", "ouioui", "homme", new Date(2022,12,12), 12222, 123324, 12, tabSkinApp[6], tabSkinApp, undefined);
|
let UserTest:User=new User(48, "WeshWesh", "MdpDeOuf", "ouioui", "grand", new Date(2022,12,12), 12222, 123324, 12, tabSkinApp[2], tabSkinApp);
|
||||||
|
|
||||||
let tabUS:User[]=[UserActu, UserTest, Alban, Fefe63];
|
|
||||||
|
let tabUS:User[]=[UserTest, Alban, UserActu, Fefe63];
|
||||||
|
|
||||||
export default tabUS;
|
export default tabUS;
|
@ -0,0 +1,20 @@
|
|||||||
|
import React from "react";
|
||||||
|
import create from "zustand";
|
||||||
|
import { MANAGER_USER } from "../../App";
|
||||||
|
import { Conversation } from "../core/conversation";
|
||||||
|
|
||||||
|
|
||||||
|
// Define store types
|
||||||
|
interface ConversationState {
|
||||||
|
tabConv: Conversation[] | undefined;
|
||||||
|
setTabConv: (tabConv: Conversation[]) => void;
|
||||||
|
resetTabConv: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define store data and methods
|
||||||
|
export const useConversationStore = create<ConversationState>()((set, get) => ({
|
||||||
|
tabConv: undefined,
|
||||||
|
setTabConv: (tabConv) => set((state) => ({ tabConv: tabConv })),
|
||||||
|
resetTabConv: () => set((state) => ({tabConv: undefined})),
|
||||||
|
}));
|
||||||
|
|
@ -0,0 +1,23 @@
|
|||||||
|
import React from "react";
|
||||||
|
import create from "zustand";
|
||||||
|
import { MANAGER_USER } from "../../App";
|
||||||
|
import tabSkinApp from "../constSkin";
|
||||||
|
import { Game } from "../core/game";
|
||||||
|
import { Skin } from "../core/Skin";
|
||||||
|
import { User } from "../core/User/user";
|
||||||
|
|
||||||
|
|
||||||
|
// Define store types
|
||||||
|
interface GameState {
|
||||||
|
tabGame: Game[] | undefined;
|
||||||
|
setTabGame: (tabGame: Game[]) => void;
|
||||||
|
resetTabGame: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define store data and methods
|
||||||
|
export const useGameStore = create<GameState>()((set, get) => ({
|
||||||
|
tabGame: undefined,
|
||||||
|
setTabGame: (tabGame) => set((state) => ({ tabGame: tabGame })),
|
||||||
|
resetTabGame: () => set((state) => ({ tabGame: undefined })),
|
||||||
|
}));
|
||||||
|
|
@ -0,0 +1,18 @@
|
|||||||
|
import React from "react";
|
||||||
|
import create from "zustand";
|
||||||
|
import { Match } from "../core/Match/match";
|
||||||
|
|
||||||
|
|
||||||
|
// Define store types
|
||||||
|
interface MatchState {
|
||||||
|
match: Match | null;
|
||||||
|
setMatch: (match: Match|null) => void;
|
||||||
|
resetMatch: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define store data and methods
|
||||||
|
export const useMatchStore = create<MatchState>()((set, get) => ({
|
||||||
|
match: null,
|
||||||
|
setMatch: (match) => set((state) => ({ match: match })),
|
||||||
|
resetMatch: () => set((state) => ({ match: null })),
|
||||||
|
}));
|
@ -0,0 +1,22 @@
|
|||||||
|
import React from "react";
|
||||||
|
import create from "zustand";
|
||||||
|
import { MANAGER_USER } from "../../App";
|
||||||
|
import tabSkinApp from "../constSkin";
|
||||||
|
import { Skin } from "../core/Skin";
|
||||||
|
import { User } from "../core/User/user";
|
||||||
|
|
||||||
|
|
||||||
|
// Define store types
|
||||||
|
interface StoreState {
|
||||||
|
tabSkin: Skin[];
|
||||||
|
setTabSkin: (tabSkin: Skin[]) => void;
|
||||||
|
resetTabSkin: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define store data and methods
|
||||||
|
export const useStoreStore = create<StoreState>()((set, get) => ({
|
||||||
|
tabSkin: tabSkinApp,
|
||||||
|
setTabSkin: (tabSkin) => set((state) => ({ tabSkin: tabSkin })),
|
||||||
|
resetTabSkin: () => set((state) => ({ tabSkin: tabSkinApp })),
|
||||||
|
}));
|
||||||
|
|
@ -0,0 +1,18 @@
|
|||||||
|
import React from "react";
|
||||||
|
import create from "zustand";
|
||||||
|
import { User } from "../core/User/user";
|
||||||
|
|
||||||
|
|
||||||
|
// Define store types
|
||||||
|
interface UserState {
|
||||||
|
user: User | null;
|
||||||
|
setUser: (user: User|null) => void;
|
||||||
|
resetUser: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define store data and methods
|
||||||
|
export const useUserStore = create<UserState>()((set, get) => ({
|
||||||
|
user: null,
|
||||||
|
setUser: (user) => set((state) => ({ user: user })),
|
||||||
|
resetUser: () => set((state) => ({ user: null })),
|
||||||
|
}));
|
@ -0,0 +1,71 @@
|
|||||||
|
|
||||||
|
import { loginUser } from '../../redux/features/currentUserSlice';
|
||||||
|
import tabUS from "../../constUser";
|
||||||
|
import { User } from '../User/user';
|
||||||
|
import { updateAlreadyUsedPseudo,updateImpossibleBirthDate,updateUndefinedBirthDate,updateUndefinedNationality,updateTooLongPseudo,updateUndefinedPseudo,updateUndefinedSex, updateTooShortPassword, updateInvalidPassword, updateInvalidPseudo, updateUndefinedPassword } from '../../redux/features/credentialErrorsSlice';
|
||||||
|
|
||||||
|
function max(array: User[]){
|
||||||
|
let max: string = "";
|
||||||
|
for (let index = 0; index < array.length; index++) {
|
||||||
|
const element = array[index].getId();
|
||||||
|
if (element > max) max = element;
|
||||||
|
}
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export const checkNewUserValidity = (login: string, password: string, dateOfBirth: Date, nationality: string, sexe: string, dispatch: any, nav: any) => {
|
||||||
|
let actualDate : number = Date.now();
|
||||||
|
let givenDate : number = dateOfBirth.getTime();
|
||||||
|
let passwordRegex : RegExp = /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-])(?!.*?[.\n\\{}[\],]).{8,}$/;
|
||||||
|
let loginRegex : RegExp = /^[A-Za-z0-9_-]{1,22}$/;
|
||||||
|
|
||||||
|
switch(true){
|
||||||
|
case (login === ''):
|
||||||
|
dispatch(updateUndefinedPseudo(true));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case (password === ''):
|
||||||
|
dispatch(updateUndefinedPassword(true));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case (givenDate == null):
|
||||||
|
dispatch(updateUndefinedBirthDate(true));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case (nationality == ''):
|
||||||
|
dispatch(updateUndefinedNationality(true))
|
||||||
|
break;
|
||||||
|
|
||||||
|
case (sexe == ''):
|
||||||
|
dispatch(updateUndefinedSex(true));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case (login.length > 22):
|
||||||
|
dispatch(updateTooLongPseudo(true));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case (! loginRegex.test(login)):
|
||||||
|
dispatch(updateInvalidPseudo(true));
|
||||||
|
break;
|
||||||
|
|
||||||
|
//ALREADY USED PSEUDO
|
||||||
|
|
||||||
|
case (password.length < 8):
|
||||||
|
dispatch(updateTooShortPassword(true));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case (! passwordRegex.test(password)):
|
||||||
|
dispatch(updateInvalidPassword(true));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ((actualDate-givenDate) < 409968000000):
|
||||||
|
dispatch(updateImpossibleBirthDate(true));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
const newUser : User = new User(0,login,password,nationality,sexe,dateOfBirth);
|
||||||
|
dispatch(loginUser(newUser));
|
||||||
|
nav.navigate('HomeTab');
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1,72 @@
|
|||||||
|
import { ImageSourcePropType } from 'react-native';
|
||||||
|
import { Game } from '../game';
|
||||||
|
import { User } from "../User/user";
|
||||||
|
|
||||||
|
|
||||||
|
export abstract class Match{
|
||||||
|
readonly code:number;
|
||||||
|
private inGame:Boolean=false;
|
||||||
|
private tabUsers:User[];
|
||||||
|
private theGame:Game;
|
||||||
|
|
||||||
|
constructor(code:number, inGame:Boolean, tabUser:User[], game:Game){
|
||||||
|
this.code=code;
|
||||||
|
this.inGame=inGame;
|
||||||
|
this.tabUsers=[...tabUser];
|
||||||
|
this.theGame=game;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Brief : Fuction getting if the match is currently in a game */
|
||||||
|
|
||||||
|
getInGame(){
|
||||||
|
return this.inGame;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Brief : Fuction setting the boolean inGame */
|
||||||
|
|
||||||
|
setInGame(inGame:Boolean){
|
||||||
|
this.inGame=inGame;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Brief : Fuction getting the array of User */
|
||||||
|
|
||||||
|
getTabUsers(){
|
||||||
|
return this.tabUsers;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Brief : Fuction setting the array of User */
|
||||||
|
|
||||||
|
setTabUser(tabUser:User[]){
|
||||||
|
this.tabUsers=[...tabUser];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Brief : Fuction getting code of a match */
|
||||||
|
|
||||||
|
getCode(){
|
||||||
|
return this.code;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Brief : Fuction getting the game of a match */
|
||||||
|
|
||||||
|
getGame(){
|
||||||
|
return this.theGame;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Brief : Fuction setting the game of a match */
|
||||||
|
|
||||||
|
setGame(game:Game){
|
||||||
|
this.theGame=game;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
abstract updatePostMatch(user:User, points:number):void;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
import { Match } from "./match";
|
||||||
|
import { User } from "../User/user";
|
||||||
|
import { Game } from "../game";
|
||||||
|
import { GameCasino } from "../gameCasino";
|
||||||
|
import { ManagerCoinsUser } from "../User/userCoinsModifier";
|
||||||
|
|
||||||
|
export default class MatchCasino extends Match{
|
||||||
|
|
||||||
|
constructor(code:number, inGame:Boolean, tabUser:User[], game:GameCasino){
|
||||||
|
super(code, inGame, tabUser, game);
|
||||||
|
}
|
||||||
|
|
||||||
|
updatePostMatch(user:User, points: number): void {
|
||||||
|
const manage= new ManagerCoinsUser();
|
||||||
|
manage.addCoins(user, this.getGame().coinsCalculator(points));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
import { MANAGER_MATCH } from "../../../App";
|
||||||
|
import ManagerMatch from "../../services/matchServices/managerMatch";
|
||||||
|
import { Game } from "../game";
|
||||||
|
import { User } from "../User/user";
|
||||||
|
import { Match } from "./match";
|
||||||
|
|
||||||
|
export default class MatchCreator{
|
||||||
|
|
||||||
|
async createMatch(u:User, g:Game): Promise<Match>{
|
||||||
|
return await MANAGER_MATCH.getsaverMatch().saveMatch(u, g);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
import { Match } from "./match";
|
||||||
|
import { User } from "../User/user";
|
||||||
|
import { Game } from "../game";
|
||||||
|
import { GameMulti } from "../gameMulti";
|
||||||
|
import { ManagerCoinsUser } from "../User/userCoinsModifier";
|
||||||
|
|
||||||
|
export default class MatchMulti extends Match{
|
||||||
|
|
||||||
|
constructor(code:number, inGame:Boolean, tabUser:User[], game:GameMulti){
|
||||||
|
super(code, inGame, tabUser, game);
|
||||||
|
}
|
||||||
|
|
||||||
|
updatePostMatch(user:User, points: number): void {
|
||||||
|
const manage= new ManagerCoinsUser();
|
||||||
|
manage.addCoins(user, this.getGame().coinsCalculator(points));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
import { Match } from "./match";
|
||||||
|
import { GameSolo } from "../gameSolo";
|
||||||
|
import { User } from "../User/user";
|
||||||
|
import { Game } from "../game";
|
||||||
|
import { ManagerCoinsUser } from "../User/userCoinsModifier";
|
||||||
|
|
||||||
|
export default class MatchSolo extends Match{
|
||||||
|
|
||||||
|
constructor(code:number, inGame:Boolean, tabUser:User[], game:GameSolo){
|
||||||
|
super(code, inGame, tabUser, game);
|
||||||
|
}
|
||||||
|
|
||||||
|
updatePostMatch(user:User, points: number): void {
|
||||||
|
const manage= new ManagerCoinsUser();
|
||||||
|
manage.addCoins(user, this.getGame().coinsCalculator(points));
|
||||||
|
}
|
||||||
|
}
|
@ -1,14 +0,0 @@
|
|||||||
import { User } from "./user";
|
|
||||||
import { Skin } from "../Skin";
|
|
||||||
import { ManagerCoinsUser } from "./managerCoinsUser";
|
|
||||||
//import ManagerCoinsUser
|
|
||||||
|
|
||||||
|
|
||||||
export class SkinBuyer{
|
|
||||||
buy(u:User, s:Skin){
|
|
||||||
const manage=new ManagerCoinsUser();
|
|
||||||
u.getTabSkin().push(s);
|
|
||||||
manage.removeCoins(u, s.getSkinCost());
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
import { User } from "./user";
|
|
||||||
|
|
||||||
export class ManagerCoinsUser{
|
|
||||||
addCoins(u:User, coins:number){
|
|
||||||
u.setCurrentCoins(u.getCurrentCoins()+coins);
|
|
||||||
u.setTotalCoins(u.getTotalCoins()+coins);
|
|
||||||
}
|
|
||||||
|
|
||||||
removeCoins(u:User, coins:number){
|
|
||||||
u.setCurrentCoins(u.getCurrentCoins()-coins);
|
|
||||||
}
|
|
||||||
|
|
||||||
changeCurrentCoins(u:User, coins:number){
|
|
||||||
u.setCurrentCoins(coins);
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,27 @@
|
|||||||
|
import { MANAGER_USER } from "../../../App";
|
||||||
|
import ManagerUser from "../../services/userServices/managerUser";
|
||||||
|
import { User } from "./user";
|
||||||
|
|
||||||
|
export class ManagerCoinsUser{
|
||||||
|
|
||||||
|
|
||||||
|
async addCoins(u:User, coins:number){
|
||||||
|
u.setCurrentCoins(u.getCurrentCoins()+coins);
|
||||||
|
u.setTotalCoins(u.getTotalCoins()+coins);
|
||||||
|
await MANAGER_USER.getsaverUser().updateUser(u);
|
||||||
|
}
|
||||||
|
|
||||||
|
async removeCoins(u:User, coins:number): Promise<boolean>{
|
||||||
|
if (u.getCurrentCoins()>=coins){
|
||||||
|
u.setCurrentCoins(u.getCurrentCoins()-coins);
|
||||||
|
await MANAGER_USER.getsaverUser().updateUser(u);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
async changeCurrentCoins(u:User, coins:number){
|
||||||
|
u.setCurrentCoins(coins);
|
||||||
|
await MANAGER_USER.getsaverUser().updateUser(u);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
import { User } from "./user";
|
||||||
|
import tabSkinApp from "../../constSkin";
|
||||||
|
import { Conversation } from "../conversation";
|
||||||
|
import ManagerUser from "../../services/userServices/managerUser";
|
||||||
|
import { MANAGER_USER } from "../../../App";
|
||||||
|
|
||||||
|
export class UserCreator{
|
||||||
|
|
||||||
|
async createUser(username:string, password:string, nationality:string, sexe:string, date:Date){
|
||||||
|
//Récup l'ID d'après dans la bdd
|
||||||
|
let u:null|User = await MANAGER_USER.getsaverUser().saveUser(username, password, nationality, sexe, date);
|
||||||
|
MANAGER_USER.setCurrentUser(u);
|
||||||
|
return u;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
import { MANAGER_USER } from "../../../App";
|
||||||
|
import { User } from "./user";
|
||||||
|
|
||||||
|
|
||||||
|
export default class UserModificationManager{
|
||||||
|
async changePassword(user:User, password:string){
|
||||||
|
user.setPassword(password);
|
||||||
|
await MANAGER_USER.getsaverUser().updateUser(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
async changeUsername(user:User, username:string){
|
||||||
|
user.setUsername(username);
|
||||||
|
await MANAGER_USER.getsaverUser().updateUser(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
async changeNationality(user:User, nationality:string){
|
||||||
|
user.setNationality(nationality);
|
||||||
|
await MANAGER_USER.getsaverUser().updateUser(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
async changeSexe(user:User, sexe:string){
|
||||||
|
user.setSexe(sexe);
|
||||||
|
await MANAGER_USER.getsaverUser().updateUser(user);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
import { MANAGER_USER } from '../../../App';
|
||||||
|
import { Skin } from '../Skin'
|
||||||
|
import { User } from './user'
|
||||||
|
|
||||||
|
|
||||||
|
export default class UserSkinModifier{
|
||||||
|
async addSkin(user:User, skin:Skin){
|
||||||
|
user.addSkin(skin);
|
||||||
|
await MANAGER_USER.getsaverUser().updateUser(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
async changeCurrentSkin(user:User, skin:Skin){
|
||||||
|
user.setCurrentSkin(skin);
|
||||||
|
await MANAGER_USER.getsaverUser().updateUser(user);
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,12 @@
|
|||||||
import { ImageSourcePropType } from 'react-native';
|
|
||||||
import { Game } from './game'
|
import { Game } from './game'
|
||||||
|
|
||||||
export class GameCasino extends Game{
|
export class GameCasino extends Game{
|
||||||
|
|
||||||
constructor(name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayerMin:number, nbPlayerMax:number){
|
constructor(id:number, name:string, imageSource:string, gameSource:string, nbPlayerMin:number, nbPlayerMax:number){
|
||||||
super(name, imageSource, gameSource, nbPlayerMin, nbPlayerMax);
|
super(id, name, imageSource, gameSource, nbPlayerMin, nbPlayerMax);
|
||||||
|
}
|
||||||
|
|
||||||
|
coinsCalculator(points: number): number {
|
||||||
|
return points;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,56 +0,0 @@
|
|||||||
import { ImageSourcePropType } from 'react-native';
|
|
||||||
import { Game } from './game';
|
|
||||||
import { GameCasino } from './gameCasino';
|
|
||||||
import { GameMulti } from './gameMulti';
|
|
||||||
import { GameSolo } from './gameSolo';
|
|
||||||
import { User } from "./User/user";
|
|
||||||
|
|
||||||
|
|
||||||
export abstract class Match{
|
|
||||||
readonly code:string;
|
|
||||||
private tabUsers:User[];
|
|
||||||
private theGame:Game;
|
|
||||||
|
|
||||||
constructor(code:string, tabUser:User[], game:Game){
|
|
||||||
this.code=code;
|
|
||||||
this.tabUsers=[...tabUser];
|
|
||||||
this.theGame=game;
|
|
||||||
}
|
|
||||||
|
|
||||||
getTabUsers(){
|
|
||||||
return this.tabUsers;
|
|
||||||
}
|
|
||||||
|
|
||||||
setTabUser(tabUser:User[]){
|
|
||||||
this.tabUsers=[...tabUser];
|
|
||||||
}
|
|
||||||
|
|
||||||
getCode(){
|
|
||||||
return this.code;
|
|
||||||
}
|
|
||||||
|
|
||||||
getGame(){
|
|
||||||
return this.theGame;
|
|
||||||
}
|
|
||||||
|
|
||||||
setGame(game:Game){
|
|
||||||
this.theGame=game;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
convertMechanismToCoins(){
|
|
||||||
if (this.TheGame instanceof GameSolo){
|
|
||||||
return this.TheGame.CoinsWithPoints(this.GainingMechanism);
|
|
||||||
}
|
|
||||||
else if (this.TheGame instanceof GameMulti){
|
|
||||||
return this.TheGame.CoinsWithRank(this.GainingMechanism);
|
|
||||||
}
|
|
||||||
else if (this.TheGame instanceof GameCasino){
|
|
||||||
return this.TheGame.betToCoins(this.GainingMechanism);
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
import { Match } from "./match";
|
|
||||||
import { User } from "./User/user";
|
|
||||||
import { Game } from "./game";
|
|
||||||
import { GameCasino } from "./gameCasino";
|
|
||||||
|
|
||||||
export class MatchMulti extends Match{
|
|
||||||
|
|
||||||
constructor(code:string, tabUser:User[], game:GameCasino){
|
|
||||||
super(code, tabUser, game);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
import { Match } from "./match";
|
|
||||||
import { User } from "./User/user";
|
|
||||||
import { Game } from "./game";
|
|
||||||
import { GameMulti } from "./gameMulti";
|
|
||||||
|
|
||||||
export class MatchMulti extends Match{
|
|
||||||
|
|
||||||
constructor(code:string, tabUser:User[], game:GameMulti){
|
|
||||||
super(code, tabUser, game);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
import { Match } from "./match";
|
|
||||||
import { GameSolo } from "./gameSolo";
|
|
||||||
import { User } from "./User/user";
|
|
||||||
import { Game } from "./game";
|
|
||||||
|
|
||||||
export class MatchSolo extends Match{
|
|
||||||
|
|
||||||
constructor(code:string, tabUser:User[], game:GameSolo){
|
|
||||||
super(code, tabUser, game);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
import { Match } from '../Match';
|
|
||||||
|
|
||||||
|
|
@ -1,49 +1,47 @@
|
|||||||
import { Message } from '../Message';
|
import { Message } from '../Message';
|
||||||
import { User } from '../User/user';
|
import { User } from '../User/user';
|
||||||
import { Conversation } from '../Conversation';
|
|
||||||
import { Skin } from '../Skin';
|
import { Skin } from '../Skin';
|
||||||
|
|
||||||
// Instances
|
// Instances
|
||||||
let conv:Conversation[] = [];
|
const img = "";
|
||||||
let tab:Skin[] = [];
|
let classique = new Skin(1, "Bob", img, 0);
|
||||||
let classique = new Skin("S0001", "Bob", require('bob_party/assets/BobsSkins/BobClassic.png'), 0);
|
|
||||||
let dateBirth = new Date(2010,0o3,0o7);
|
let dateBirth = new Date(2010,0o3,0o7);
|
||||||
let usr = new User('00001', 'Killyan', 'password', 'France', 'M', dateBirth, 0, 0, 0, classique, tab, conv);
|
let usr = new User(1, 'Killyan', 'password', 'France', 'M', dateBirth, 0, 0, 0, classique, []);
|
||||||
let usr2 = new User('00002', 'Karina', '1234', 'France', 'F', dateBirth, 5, 6, 8, classique, tab, conv);
|
let usr2 = new User(2, 'Karina', '1234', 'France', 'F', dateBirth, 5, 6, 8, classique, []);
|
||||||
let theDate = new Date(2022,10,14);
|
let theDate = new Date(2022,10,14);
|
||||||
let theDate2 = new Date(2022,10,13);
|
let theDate2 = new Date(2022,10,13);
|
||||||
let mess = new Message('Bob Party est le meilleur projet', usr, theDate);
|
let mess = new Message(1, 'Bob Party est le meilleur projet', usr, theDate);
|
||||||
|
|
||||||
|
|
||||||
// Get tests
|
// Get tests
|
||||||
describe('Message get tests', () => {
|
describe('Message get tests', () => {
|
||||||
|
it('should return 1', () => {
|
||||||
|
expect(mess.getMessageId()).toBe(1);
|
||||||
|
})
|
||||||
it('should return Bob Party est le meilleur projet', () => {
|
it('should return Bob Party est le meilleur projet', () => {
|
||||||
expect(mess.getMessageContent()).toBe('Bob Party est le meilleur projet');
|
expect(mess.getMessageContent()).toBe('Bob Party est le meilleur projet');
|
||||||
})
|
})
|
||||||
it('should return usr', () => {
|
it('should return usr', () => {
|
||||||
expect(mess.getMessageSender()).toBe(usr);
|
expect(mess.getMessageSender()).toEqual(usr);
|
||||||
})
|
})
|
||||||
it('should return wouhou', () => {
|
it('should return theDate', () => {
|
||||||
expect(mess.getMessageDate()).toBe(theDate);
|
expect(mess.getMessageDate()).toEqual(theDate);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
// Setting new values
|
|
||||||
mess.setMessageContent('Vive Bob Party');
|
|
||||||
mess.setMessageSender(usr2);
|
|
||||||
mess.setMessageDate(theDate2);
|
|
||||||
|
|
||||||
|
|
||||||
// Set tests
|
// Set tests
|
||||||
describe('Message set tests', () => {
|
describe('Message set tests', () => {
|
||||||
it('should return Vive Bob Party', () => {
|
it('should return Vive Bob Party', () => {
|
||||||
|
mess.setMessageContent('Vive Bob Party');
|
||||||
expect(mess.getMessageContent()).toBe('Vive Bob Party');
|
expect(mess.getMessageContent()).toBe('Vive Bob Party');
|
||||||
})
|
})
|
||||||
it('should return usr2', () => {
|
it('should return usr2', () => {
|
||||||
expect(mess.getMessageSender()).toBe(usr2);
|
mess.setMessageSender(usr2);
|
||||||
|
expect(mess.getMessageSender()).toEqual(usr2);
|
||||||
})
|
})
|
||||||
it('should return theDate2', () => {
|
it('should return theDate2', () => {
|
||||||
expect(mess.getMessageDate()).toBe(theDate2);
|
mess.setMessageDate(theDate2);
|
||||||
|
expect(mess.getMessageDate()).toEqual(theDate2);
|
||||||
})
|
})
|
||||||
})
|
})
|
@ -0,0 +1,174 @@
|
|||||||
|
import { createSlice, PayloadAction } from "@reduxjs/toolkit"
|
||||||
|
|
||||||
|
var incorrectCredentialsBool : boolean = false;
|
||||||
|
var tooLongPseudodBool : boolean = false;
|
||||||
|
var tooShortPasswordBool : boolean = false;
|
||||||
|
var invalidPseudoBool : boolean = false;
|
||||||
|
var invalidPasswordBool : boolean = false;
|
||||||
|
var impossibleBirthDateBool : boolean = false;
|
||||||
|
var undefinedPseudoBool : boolean = false;
|
||||||
|
var undefinedPasswordBool : boolean = false;
|
||||||
|
var undefinedBirthDateBool : boolean = false;
|
||||||
|
var undefinedNationalityBool : boolean = false;
|
||||||
|
var undefinedSexBool : boolean = false;
|
||||||
|
var alreadyUsedPseudoBool : boolean = false;
|
||||||
|
|
||||||
|
|
||||||
|
export const credentialErrorsSlice = createSlice({
|
||||||
|
name: "credentialErrors",
|
||||||
|
initialState:{
|
||||||
|
newUserErrorList : {
|
||||||
|
tooLongPseudo: tooLongPseudodBool,
|
||||||
|
tooShortPassword : tooShortPasswordBool,
|
||||||
|
invalidPseudo: invalidPseudoBool,
|
||||||
|
invalidPassword: invalidPasswordBool,
|
||||||
|
impossibleBirthDate: impossibleBirthDateBool,
|
||||||
|
undefinedPseudo: undefinedPseudoBool,
|
||||||
|
undefinedPassword: undefinedPasswordBool,
|
||||||
|
undefinedBirthDate: undefinedBirthDateBool,
|
||||||
|
undefinedNationality: undefinedNationalityBool,
|
||||||
|
undefinedSex: undefinedSexBool,
|
||||||
|
alreadyUsedPseudo: alreadyUsedPseudoBool,
|
||||||
|
},
|
||||||
|
loginErrorList : {
|
||||||
|
incorrectCredentials: incorrectCredentialsBool,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
reducers: {
|
||||||
|
updateIncorrectCredentials: (state, action: PayloadAction<boolean>) => {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
newUserErrorList:{
|
||||||
|
...state.newUserErrorList,
|
||||||
|
incorrectCredentials: action.payload
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
updateTooLongPseudo: (state, action: PayloadAction<boolean>) => {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
newUserErrorList:{
|
||||||
|
...state.newUserErrorList,
|
||||||
|
tooShortPseudo: action.payload
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
updateTooLongPassword: (state, action: PayloadAction<boolean>) => {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
newUserErrorList:{
|
||||||
|
...state.newUserErrorList,
|
||||||
|
tooLongPassword: action.payload
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
updateTooShortPassword: (state, action: PayloadAction<boolean>) => {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
newUserErrorList:{
|
||||||
|
...state.newUserErrorList,
|
||||||
|
tooShortPassword: action.payload
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
updateInvalidPseudo: (state, action: PayloadAction<boolean>) => {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
newUserErrorList:{
|
||||||
|
...state.newUserErrorList,
|
||||||
|
invalidPseudo: action.payload
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
updateInvalidPassword: (state, action: PayloadAction<boolean>) => {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
newUserErrorList:{
|
||||||
|
...state.newUserErrorList,
|
||||||
|
invalidPassword: action.payload
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
updateImpossibleBirthDate: (state, action: PayloadAction<boolean>) => {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
newUserErrorList:{
|
||||||
|
...state.newUserErrorList,
|
||||||
|
impossibleBirthDate: action.payload
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
updateUndefinedPseudo: (state, action: PayloadAction<boolean>) => {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
newUserErrorList:{
|
||||||
|
...state.newUserErrorList,
|
||||||
|
undefinedPseudo: action.payload
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
updateUndefinedPassword: (state, action: PayloadAction<boolean>) => {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
newUserErrorList:{
|
||||||
|
...state.newUserErrorList,
|
||||||
|
undefinedPassword: action.payload
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
updateUndefinedBirthDate: (state, action: PayloadAction<boolean>) => {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
newUserErrorList:{
|
||||||
|
...state.newUserErrorList,
|
||||||
|
undefinedBirthDate: action.payload
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
updateUndefinedNationality: (state, action: PayloadAction<boolean>) => {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
newUserErrorList:{
|
||||||
|
...state.newUserErrorList,
|
||||||
|
undefinedNationality: action.payload
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
updateUndefinedSex: (state, action: PayloadAction<boolean>) => {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
newUserErrorList:{
|
||||||
|
...state.newUserErrorList,
|
||||||
|
undefinedSex: action.payload
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
updateAlreadyUsedPseudo: (state, action: PayloadAction<boolean>) => {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
newUserErrorList:{
|
||||||
|
...state.newUserErrorList,
|
||||||
|
alreadyUsedPseudo: action.payload
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export const { updateIncorrectCredentials } = credentialErrorsSlice.actions
|
||||||
|
export const { updateTooShortPassword } = credentialErrorsSlice.actions
|
||||||
|
export const { updateTooLongPseudo } = credentialErrorsSlice.actions
|
||||||
|
export const { updateTooLongPassword } = credentialErrorsSlice.actions
|
||||||
|
export const { updateInvalidPseudo } = credentialErrorsSlice.actions
|
||||||
|
export const { updateInvalidPassword } = credentialErrorsSlice.actions
|
||||||
|
export const { updateImpossibleBirthDate } = credentialErrorsSlice.actions
|
||||||
|
export const { updateUndefinedPseudo } = credentialErrorsSlice.actions
|
||||||
|
export const { updateUndefinedPassword } = credentialErrorsSlice.actions
|
||||||
|
export const { updateUndefinedBirthDate } = credentialErrorsSlice.actions
|
||||||
|
export const { updateUndefinedNationality } = credentialErrorsSlice.actions
|
||||||
|
export const { updateUndefinedSex } = credentialErrorsSlice.actions
|
||||||
|
export const { updateAlreadyUsedPseudo } = credentialErrorsSlice.actions
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export default credentialErrorsSlice.reducer;
|
@ -0,0 +1,40 @@
|
|||||||
|
import { StatusBar } from 'expo-status-bar'
|
||||||
|
import { View, Image} from 'react-native'
|
||||||
|
import React from 'react';
|
||||||
|
import stylesScreen from './style/screens.style'
|
||||||
|
import { TopBar } from '../components/TopBar';
|
||||||
|
import { BotBar } from '../components/BotBar';
|
||||||
|
import { Conversation } from '../core/conversation';
|
||||||
|
import { ButtonGameTypeChoice } from '../components/ButtonGameTypeChoice';
|
||||||
|
import { MANAGER_MATCH } from '../../App';
|
||||||
|
import { useMatchStore } from '../context/matchContext';
|
||||||
|
|
||||||
|
|
||||||
|
function LobbySolo(props: { navigation: any; }) {
|
||||||
|
|
||||||
|
const { navigation } = props
|
||||||
|
|
||||||
|
const match = useMatchStore().match;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={stylesScreen.container}>
|
||||||
|
<TopBar
|
||||||
|
nav={navigation}
|
||||||
|
state='matchmacking'
|
||||||
|
/>
|
||||||
|
<View style={stylesScreen.bodyCenter}>
|
||||||
|
<ButtonGameTypeChoice
|
||||||
|
title='Lancer la partie'
|
||||||
|
onPress={() => navigation.navigate(match?.getGame().getName().replace(/\s/g, ''))}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<Image
|
||||||
|
style={{width:100, height:100}}
|
||||||
|
source={{uri: match?.getGame().getImageSource()}}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default LobbySolo
|
@ -1,29 +1,140 @@
|
|||||||
// import { StatusBar } from 'expo-status-bar'
|
import { StatusBar } from 'expo-status-bar'
|
||||||
// import { StyleSheet, View, ImageSourcePropType, Pressable, Text} from 'react-native'
|
import { StyleSheet, View, ImageSourcePropType, Pressable, Text, Alert} from 'react-native'
|
||||||
// import React from 'react';
|
import React, { useState } from 'react';
|
||||||
// import stylesScreen from './style/screens.style'
|
import stylesScreen from './style/screens.style'
|
||||||
// import { TextInput } from 'react-native-gesture-handler';
|
import { TextInput } from 'react-native-gesture-handler';
|
||||||
// import { ButtonGameTypeChoice } from '../components/ButtonGameTypeChoice';
|
import { ButtonGameTypeChoice } from '../components/ButtonGameTypeChoice';
|
||||||
|
import styleScreen from "./style/screens.style";
|
||||||
// import styles from "./style/SignIn.style"
|
import styles from "./style/SignUp.style";
|
||||||
|
import { useDispatch, useSelector } from 'react-redux';
|
||||||
// function SignUp(props: { navigation: any; }) {
|
import { checkNewUserValidity } from '../core/Auth/newUser';
|
||||||
// const { navigation } = props
|
import DateTimePicker, { DateTimePickerEvent } from '@react-native-community/datetimepicker';
|
||||||
// return (
|
import RNPickerSelect from "react-native-picker-select";
|
||||||
// <View style={stylesScreen.container}>
|
import { PickerGreySmall } from '../components/PickerGreySmall';
|
||||||
// <View style={stylesScreen.bodyCenter}>
|
import { loginUser } from '../redux/features/currentUserSlice';
|
||||||
// <CustomTextInput placeholder={""} text="Pseudo"/>
|
import { RootState } from '../redux/store';
|
||||||
// <CustomTextInput placeholder={""} text="Mot de passe"/>
|
import { updateImpossibleBirthDate, updateInvalidPassword, updateInvalidPseudo, updateTooLongPseudo, updateTooShortPassword, updateUndefinedBirthDate, updateUndefinedNationality, updateUndefinedPassword, updateUndefinedPseudo, updateUndefinedSex } from '../redux/features/credentialErrorsSlice';
|
||||||
// <CustomTextInput placeholder={""} text="Mot de passe"/>
|
import { getSystemErrorMap } from 'util';
|
||||||
// <CustomTextInput placeholder={""} text="Nationalité"/>
|
import RNDateTimePicker from '@react-native-community/datetimepicker';
|
||||||
// <CustomTextInput placeholder={""} text="Date de naisance"/>
|
|
||||||
// <CustomTextInput placeholder={""} text="Sexe"/>
|
function SignUp(props: { navigation: any; }) {
|
||||||
// <Pressable style={styles.button} onPress={navigation.navigate('Home')}>
|
const { navigation } = props
|
||||||
// <Text style={styles.text}>S'inscrire</Text>
|
|
||||||
// </Pressable>
|
const [pseudo, setPseudo] = useState('');
|
||||||
// </View>
|
const [password, setPassword] = useState('');
|
||||||
// </View>
|
const [date, setDate] = useState(new Date())
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
function onDateSelected(event : DateTimePickerEvent, value : Date | undefined) {
|
||||||
// export default SignUp
|
console.log(value);
|
||||||
|
if (value != undefined) {
|
||||||
|
setDate(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const [selectedSex, setSelectedSex] = useState('');
|
||||||
|
const [selectedNationality, setSelectedNationality] = useState('')
|
||||||
|
|
||||||
|
const errorList = useSelector((state: RootState) => state.credentialErrors.newUserErrorList);
|
||||||
|
|
||||||
|
|
||||||
|
const dispatch=useDispatch();
|
||||||
|
|
||||||
|
switch(true){
|
||||||
|
case (errorList.undefinedPseudo):
|
||||||
|
Alert.alert("Veuillez définir un pseudo");
|
||||||
|
dispatch(updateUndefinedPseudo(false));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case (errorList.undefinedPassword):
|
||||||
|
Alert.alert("Veuillez définir un mot de passe");
|
||||||
|
dispatch(updateUndefinedPassword(false));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case (errorList.undefinedBirthDate):
|
||||||
|
Alert.alert("Veuillez définir une date de naissance");
|
||||||
|
dispatch(updateUndefinedBirthDate(false));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case (errorList.undefinedNationality):
|
||||||
|
Alert.alert("Veuillez définir une nationalité");
|
||||||
|
dispatch(updateUndefinedNationality(false))
|
||||||
|
break;
|
||||||
|
|
||||||
|
case (errorList.undefinedSex):
|
||||||
|
Alert.alert("Veuillez définir un sexe");
|
||||||
|
dispatch(updateUndefinedSex(false));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case (errorList.tooLongPseudo):
|
||||||
|
Alert.alert("Votre pseudo ne doit pas dépasser 22 caractères");
|
||||||
|
dispatch(updateTooLongPseudo(false));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case (errorList.invalidPseudo):
|
||||||
|
Alert.alert("Votre pseudo doit contenir uniquement des lettres des chiffres et des - ou _");
|
||||||
|
dispatch(updateInvalidPseudo(false));
|
||||||
|
break;
|
||||||
|
|
||||||
|
//ALREADY USED PSEUDO
|
||||||
|
|
||||||
|
case (errorList.tooShortPassword):
|
||||||
|
Alert.alert("Votre mot de passe doit faire au moins 8 caractères");
|
||||||
|
dispatch(updateTooShortPassword(false));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case (errorList.invalidPassword):
|
||||||
|
Alert.alert("Votre pseudo doit contenir au moins une majuscule, une majuscule, un chiffre et un caractère spécial (#?!@$%^&*-)");
|
||||||
|
dispatch(updateInvalidPassword(false));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case (errorList.impossibleBirthDate):
|
||||||
|
Alert.alert("Vous devez avoir au moins 13 ans");
|
||||||
|
dispatch(updateImpossibleBirthDate(false));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={stylesScreen.container}>
|
||||||
|
<View style={stylesScreen.bodyCenter}>
|
||||||
|
|
||||||
|
<View style={{width: '60%', alignItems: 'center'}}>
|
||||||
|
<Text style={styles.text}>Login</Text>
|
||||||
|
<TextInput style={styles.textInput} placeholder='Login' onChangeText={(val) => setPseudo(val)} autoCapitalize='none' />
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<View style={{width: '60%', alignItems: 'center'}}>
|
||||||
|
<Text style={styles.text}>Password</Text>
|
||||||
|
<TextInput style={styles.textInput} placeholder='Password' onChangeText={(val) => setPassword(val)} autoCapitalize='none' />
|
||||||
|
</View>
|
||||||
|
|
||||||
|
|
||||||
|
<View style={{width: '70%', alignItems: 'center'}}>
|
||||||
|
<Text style={styles.text}>Date de naissance</Text>
|
||||||
|
<View style={{width: 150, margin: 10}}>
|
||||||
|
<RNDateTimePicker onChange={(event, value) => onDateSelected(event, value)} mode='date' value={date} themeVariant='dark'/>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<View style={{width: '60%', alignItems: 'center'}}>
|
||||||
|
<Text style={styles.text}>Nationalité</Text>
|
||||||
|
<PickerGreySmall title='Choisir la Nationalité' valueChange={(value:string) =>
|
||||||
|
setSelectedNationality(value)} values={["Français", "Anglais"]} />
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<View style={{width: '60%', alignItems: 'center'}}>
|
||||||
|
<Text style={styles.text}>Sexe</Text>
|
||||||
|
<PickerGreySmall title='Choisir le sexe' valueChange={(value:string) => setSelectedSex(value)} values={["Homme","Femme", "Autre"]} />
|
||||||
|
</View>
|
||||||
|
<Pressable style={styles.button} onPress={() => checkNewUserValidity(pseudo,password,date,selectedNationality,selectedSex, dispatch, navigation)}>
|
||||||
|
<Text style={styles.text}>S'inscrire</Text>
|
||||||
|
</Pressable>
|
||||||
|
<Pressable onPress={() => navigation.navigate('SignIn')}>
|
||||||
|
<Text style={styles.textLink}>J'ai déjà un compte</Text>
|
||||||
|
</Pressable>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default SignUp
|
||||||
|
@ -0,0 +1,35 @@
|
|||||||
|
import { StyleSheet } from "react-native";
|
||||||
|
|
||||||
|
|
||||||
|
export default StyleSheet.create({
|
||||||
|
textInput: {
|
||||||
|
width: '100%',
|
||||||
|
height: '5%',
|
||||||
|
backgroundColor: 'white',
|
||||||
|
padding: 10,
|
||||||
|
marginTop: 10,
|
||||||
|
},
|
||||||
|
button: {
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
height: 50,
|
||||||
|
width: 225,
|
||||||
|
margin:'10%',
|
||||||
|
borderRadius: 10,
|
||||||
|
elevation: 3,
|
||||||
|
backgroundColor: '#0085FF',
|
||||||
|
},
|
||||||
|
text: {
|
||||||
|
fontSize: 16,
|
||||||
|
lineHeight: 21,
|
||||||
|
fontWeight: 'bold',
|
||||||
|
letterSpacing: 0.25,
|
||||||
|
color: 'white',
|
||||||
|
},
|
||||||
|
textLink:{
|
||||||
|
fontSize:15,
|
||||||
|
color:'white',
|
||||||
|
textDecorationLine:"underline",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
@ -0,0 +1,25 @@
|
|||||||
|
import { Conversation } from "../../core/conversation";
|
||||||
|
import { User } from "../../core/User/user";
|
||||||
|
|
||||||
|
export default interface ILoaderConversation{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* loadAllConversation methode that load every Conversation in the data management system
|
||||||
|
* return an array of Conversation
|
||||||
|
*/
|
||||||
|
loadAllConversation(): Promise<Conversation[]>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* loadByID methode that load an array of Conversation from the data management system by its id
|
||||||
|
* id the id we want to search
|
||||||
|
* return a Conversation if found, if not null
|
||||||
|
*/
|
||||||
|
loadByID(id:string): Promise<Conversation | null>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* loadByUser methode that load an array of Conversation from the data management system using a user
|
||||||
|
* u the user we want the conversations of
|
||||||
|
* return an array of Conversation
|
||||||
|
*/
|
||||||
|
loadByUser(u:User): Promise<Conversation[]>;
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
import { Conversation } from "../../core/conversation";
|
||||||
|
|
||||||
|
export default interface ISaverConversation{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* saveConversation methode that save a Conversation in the data management system
|
||||||
|
* c the Conversation we want to save
|
||||||
|
*/
|
||||||
|
|
||||||
|
saveConversation(c:Conversation): Promise<void>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* deleteConversation methode that delete a Conversation in the data management system
|
||||||
|
* c the Conversation we want to delete
|
||||||
|
*/
|
||||||
|
deleteConversation(c:Conversation): Promise<void>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* updateConversation methode that update a Conversation in the data management system
|
||||||
|
* c the Conversation we want to update
|
||||||
|
*/
|
||||||
|
updateConversation(c:Conversation): Promise<void>;
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
import { Conversation } from "../../core/conversation";
|
||||||
|
import ISaverConversation from "./ISaverConversation";
|
||||||
|
|
||||||
|
export class FakeSaverConversation implements ISaverConversation{
|
||||||
|
async saveConversation(c: Conversation): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
async deleteConversation(c: Conversation): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
async updateConversation(c: Conversation): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
import { Conversation } from "../../core/conversation";
|
||||||
|
import { Message } from "../../core/message";
|
||||||
|
import { Skin } from "../../core/skin";
|
||||||
|
import { User } from "../../core/User/user";
|
||||||
|
import ILoaderConversation from "./ILoaderConversation";
|
||||||
|
|
||||||
|
export class LoaderConversationApi implements ILoaderConversation{
|
||||||
|
|
||||||
|
private axios = require('axios').default;
|
||||||
|
|
||||||
|
loadAllConversation(): Promise<Conversation[]> {
|
||||||
|
throw new Error("Method not implemented.");
|
||||||
|
}
|
||||||
|
loadByID(id: string): Promise<Conversation | null> {
|
||||||
|
throw new Error("Method not implemented.");
|
||||||
|
}
|
||||||
|
async loadByUser(u: User): Promise<Conversation[]> {
|
||||||
|
|
||||||
|
let tabConv:Conversation[]=[];
|
||||||
|
await this.axios({
|
||||||
|
method: 'get',
|
||||||
|
url: 'https://jsonplaceholder.typicode.com/todos/1',
|
||||||
|
params: {
|
||||||
|
name: "getConversationByUser",
|
||||||
|
//Les params genre nom de la fonction en php
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(function (response: any) {
|
||||||
|
let skin= new Skin(1, "Bob","https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/BobsSkins/BobClassic.png", 0);
|
||||||
|
tabConv=[new Conversation(1,
|
||||||
|
[new User(1, "Alban", "oui", "ouioui", "homme", new Date(2022,12,12), 555, 667, 12, skin, [skin]),
|
||||||
|
new User(3, "Fefe63", "jesuishm", "ouioui", "homme", new Date(2022,12,12), 12222, 123324, 12, skin, [skin])],
|
||||||
|
[new Message(1, "bonjour", new User(1, "Alban", "oui", "ouioui", "homme", new Date(2022,12,12), 555, 667, 12, skin, [skin]), new Date(2022,12,12)),
|
||||||
|
new Message(2, "test", new User(2, "Fefe63", "oui", "ouioui", "homme", new Date(2022,12,12), 555, 667, 12, skin, [skin]), new Date(2022,12,13))], "leNom")];
|
||||||
|
});
|
||||||
|
return tabConv;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
import { Conversation } from "../../core/conversation";
|
||||||
|
import ILoaderConversation from "./ILoaderConversation";
|
||||||
|
import ISaverConversation from "./ISaverConversation";
|
||||||
|
|
||||||
|
export default class ManagerConversation{
|
||||||
|
|
||||||
|
private currentTabConv:Conversation[]=[];
|
||||||
|
|
||||||
|
private loaderConversation: ILoaderConversation;
|
||||||
|
|
||||||
|
private saverConversation: ISaverConversation;
|
||||||
|
|
||||||
|
constructor(loaderConversation:ILoaderConversation, saverConversation:ISaverConversation){
|
||||||
|
this.loaderConversation=loaderConversation;
|
||||||
|
this.saverConversation=saverConversation;
|
||||||
|
}
|
||||||
|
|
||||||
|
getCurrentTabConv(){
|
||||||
|
return this.currentTabConv;
|
||||||
|
}
|
||||||
|
|
||||||
|
setCurrentTabConv(c:Conversation[]){
|
||||||
|
this.currentTabConv=c;
|
||||||
|
}
|
||||||
|
|
||||||
|
getLoaderConversation(){
|
||||||
|
return this.loaderConversation;
|
||||||
|
}
|
||||||
|
|
||||||
|
getsaverConversation(){
|
||||||
|
return this.saverConversation;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
import { Game } from "../../core/game";
|
||||||
|
|
||||||
|
export default interface ILoaderGame{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* loadAllGame methode that load every Game from the data management system
|
||||||
|
* return an array of Game
|
||||||
|
*/
|
||||||
|
loadAllGame(): Promise<Game[]>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* loadByID methode that load a match from the data management system by its id
|
||||||
|
* id the id we want to search
|
||||||
|
* return a Game if found, if not null
|
||||||
|
*/
|
||||||
|
loadByID(id:string): Promise<Game | null>;
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
import { Game } from "../../core/game";
|
||||||
|
import { GameSolo } from "../../core/gameSolo";
|
||||||
|
import ILoaderGame from "./ILoaderGame";
|
||||||
|
|
||||||
|
export default class LoaderGameApi implements ILoaderGame{
|
||||||
|
|
||||||
|
private axios = require('axios').default;
|
||||||
|
|
||||||
|
|
||||||
|
async loadAllGame(): Promise<Game[]> {
|
||||||
|
let tab: Game[]=[];
|
||||||
|
await this.axios({
|
||||||
|
method: 'get',
|
||||||
|
url: 'https://jsonplaceholder.typicode.com/todos/1',
|
||||||
|
params: {
|
||||||
|
name: "getAllUser",
|
||||||
|
//Les params genre nom de la fonction en php
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(function (response: any) {
|
||||||
|
const map = new Map();
|
||||||
|
map.set(0,0);
|
||||||
|
map.set(100,50);
|
||||||
|
map.set(300,150);
|
||||||
|
map.set(450,1000);
|
||||||
|
const cookieClicker= new GameSolo(1, "Cookie Clicker", "https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/ImagesJeux/Pong.png", "/Games/CookieClicker/cookieClicker.tsx", 1, 1, map);
|
||||||
|
const test= new GameSolo(1, "Test", "https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/ImagesJeux/Pendu.jpg", "/Games/CookieClicker/cookieClicker.tsx", 1, 1, map);
|
||||||
|
tab=[cookieClicker, test];
|
||||||
|
console.log(tab);
|
||||||
|
});
|
||||||
|
return tab;
|
||||||
|
|
||||||
|
}
|
||||||
|
async loadByID(id: string): Promise<Game | null> {
|
||||||
|
throw new Error("Method not implemented.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
import { Game } from "../../core/game";
|
||||||
|
import ILoaderGame from "./ILoaderGame";
|
||||||
|
|
||||||
|
export default class ManagerGame{
|
||||||
|
|
||||||
|
private tabGame: Game[] | null=null;
|
||||||
|
|
||||||
|
private loaderGame: ILoaderGame;
|
||||||
|
|
||||||
|
constructor(loader:ILoaderGame){
|
||||||
|
this.loaderGame=loader;
|
||||||
|
}
|
||||||
|
|
||||||
|
getTabGame(){
|
||||||
|
return this.tabGame;
|
||||||
|
}
|
||||||
|
|
||||||
|
setTabGame(g:Game[] | null){
|
||||||
|
this.tabGame=g;
|
||||||
|
}
|
||||||
|
|
||||||
|
getLoaderGame(){
|
||||||
|
return this.loaderGame;
|
||||||
|
}
|
||||||
|
|
||||||
|
setLoaderGame(l:ILoaderGame){
|
||||||
|
this.loaderGame=l;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
import { Match } from "../../core/Match/match";
|
||||||
|
|
||||||
|
export default interface ILoaderMatch{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* loadAllMatch methode that load every Match from the data management system
|
||||||
|
* return an array of Match
|
||||||
|
*/
|
||||||
|
loadAllMatch(): Promise<Match[]>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* loadByID methode that load a match from the data management system by its id
|
||||||
|
* id the id we want to search
|
||||||
|
* return a Match if found, if not null
|
||||||
|
*/
|
||||||
|
loadByID(id:string): Promise<Match | null>;
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
import { Game } from "../../core/game";
|
||||||
|
import { Match } from "../../core/Match/match";
|
||||||
|
import { User } from "../../core/User/user";
|
||||||
|
|
||||||
|
export default interface ISaverMatch{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* saveMatch methode that save a Match in the data management system
|
||||||
|
* m the Match we want to save
|
||||||
|
*/
|
||||||
|
|
||||||
|
saveMatch(u:User, g:Game): Promise<Match>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* deleteMatch methode that delete a Match in the data management system
|
||||||
|
* m the Match we want to delete
|
||||||
|
*/
|
||||||
|
deleteMatch(m:Match): Promise<void>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* updateMatch methode that update a Match in the data management system
|
||||||
|
* m the Match we want to update
|
||||||
|
*/
|
||||||
|
updateMatch(m:Match): Promise<void>;
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
import { Match } from "../../core/Match/match";
|
||||||
|
import ILoaderMatch from "./ILoaderMatch";
|
||||||
|
|
||||||
|
export default class LoaderMatchApi implements ILoaderMatch{
|
||||||
|
|
||||||
|
async loadAllMatch(): Promise<Match[]> {
|
||||||
|
throw new Error("Method not implemented.");
|
||||||
|
}
|
||||||
|
async loadByID(id: string): Promise<Match | null> {
|
||||||
|
throw new Error("Method not implemented.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
import { Match } from "../../core/Match/Match";
|
||||||
|
import ILoaderMatch from "./ILoaderMatch";
|
||||||
|
import ISaverMatch from "./ISaverMatch";
|
||||||
|
|
||||||
|
export default class ManagerMatch{
|
||||||
|
|
||||||
|
private currentMatch: Match | null=null;
|
||||||
|
|
||||||
|
private loaderMatch: ILoaderMatch;
|
||||||
|
|
||||||
|
private saverMatch: ISaverMatch;
|
||||||
|
|
||||||
|
constructor(loader:ILoaderMatch, saver:ISaverMatch){
|
||||||
|
this.loaderMatch=loader;
|
||||||
|
this.saverMatch=saver;
|
||||||
|
}
|
||||||
|
|
||||||
|
getCurrentMatch(){
|
||||||
|
return this.currentMatch;
|
||||||
|
}
|
||||||
|
|
||||||
|
setCurrentMatch(u:Match | null){
|
||||||
|
this.currentMatch=u;
|
||||||
|
}
|
||||||
|
|
||||||
|
getLoaderMatch(){
|
||||||
|
return this.loaderMatch;
|
||||||
|
}
|
||||||
|
|
||||||
|
setLoaderMatch(l:ILoaderMatch){
|
||||||
|
this.loaderMatch=l;
|
||||||
|
}
|
||||||
|
|
||||||
|
getsaverMatch(){
|
||||||
|
return this.saverMatch;
|
||||||
|
}
|
||||||
|
|
||||||
|
setsaverMatch(s:ISaverMatch){
|
||||||
|
this.saverMatch=s;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
import { Game } from "../../core/game";
|
||||||
|
import { Match } from "../../core/Match/match";
|
||||||
|
|
||||||
|
import { User } from "../../core/User/user";
|
||||||
|
import ISaverMatch from "./ISaverMatch";
|
||||||
|
import { GameSolo } from "../../core/gameSolo";
|
||||||
|
import { GameMulti } from "../../core/gameMulti";
|
||||||
|
import MatchSolo from "../../core/Match/matchSolo";
|
||||||
|
import MatchMulti from "../../core/Match/matchMulti";
|
||||||
|
import MatchCasino from "../../core/Match/matchCasino";
|
||||||
|
|
||||||
|
export default class SaverMatchApi implements ISaverMatch{
|
||||||
|
|
||||||
|
async saveMatch(u:User, g:Game): Promise<Match> {
|
||||||
|
//match = mettre dans bdd
|
||||||
|
if (g instanceof GameSolo){
|
||||||
|
return new MatchSolo(12, false, [u], g);
|
||||||
|
}
|
||||||
|
else if(g instanceof GameMulti){
|
||||||
|
return new MatchMulti(12, false, [u], g);
|
||||||
|
}
|
||||||
|
return new MatchCasino(12, false, [u], g);
|
||||||
|
|
||||||
|
}
|
||||||
|
async deleteMatch(m: Match): Promise<void> {
|
||||||
|
throw new Error("Method not implemented.");
|
||||||
|
}
|
||||||
|
async updateMatch(m: Match): Promise<void> {
|
||||||
|
throw new Error("Method not implemented.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
import { Conversation } from "../../core/conversation";
|
||||||
|
import { Message } from "../../core/message";
|
||||||
|
|
||||||
|
export default interface ILoaderMessage{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* loadAllMessage methode that load every Message from the data management system
|
||||||
|
* return an array of Message
|
||||||
|
*/
|
||||||
|
loadAllMessage(): Promise<Message[]>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* loadByID methode that load a Message from the data management system by its id
|
||||||
|
* id the id we want to search
|
||||||
|
* return a Message if found, if not null
|
||||||
|
*/
|
||||||
|
loadByID(id:string): Promise<Message | null>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* loadByUser methode that load an array of Message from the data management system using a Conversation
|
||||||
|
* c the Conversation we want the Messages of
|
||||||
|
* return an array of Message
|
||||||
|
*/
|
||||||
|
loadByConversation(c:Conversation): Promise<Message[]>;
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
import { Message } from "../../core/message";
|
||||||
|
|
||||||
|
export default interface ISaverMessage{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* saveMessage methode that save a Message in the data management system
|
||||||
|
* m the Message we want to save
|
||||||
|
*/
|
||||||
|
|
||||||
|
saveMessage(m:Message): Promise<void>;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,62 @@
|
|||||||
|
import LoaderUserApi from '../userServices/loaderUserApi';
|
||||||
|
import ILoaderUser from '../userServices/ILoaderUser';
|
||||||
|
import { Match } from '../../core/Match/match';
|
||||||
|
import MatchSolo from '../../core/Match/matchSolo';
|
||||||
|
import { GameSolo } from '../../core/gameSolo';
|
||||||
|
import tabUS from '../../constUser';
|
||||||
|
import { Conversation } from '../../core/conversation';
|
||||||
|
|
||||||
|
// Instances
|
||||||
|
const img = "";
|
||||||
|
let loader:ILoaderUser = new LoaderUserApi();
|
||||||
|
let map = new Map<number, number>([
|
||||||
|
[50, 3],
|
||||||
|
[75, 4],
|
||||||
|
[100, 5],
|
||||||
|
[150, 6]
|
||||||
|
]);
|
||||||
|
let game:GameSolo = new GameSolo(1, 'SuperJeu', img, 'source', 1, 1, map);
|
||||||
|
let match:Match = new MatchSolo(1, false, tabUS, game);
|
||||||
|
let convo:Conversation = new Conversation(1, tabUS, [], 'superConvo');
|
||||||
|
|
||||||
|
|
||||||
|
// Tests
|
||||||
|
describe('LoaderUserApi tests', () => {
|
||||||
|
describe('loadById tests', () => {
|
||||||
|
it('should return UserTest (id: 48)', () => {
|
||||||
|
expect(loader.loadByID(48)).toEqual(tabUS[0]);
|
||||||
|
})
|
||||||
|
it('should return null', () => {
|
||||||
|
expect(loader.loadByID(99999999999)).toBe(null);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
describe('loadByUserName tests', () => {
|
||||||
|
it('should return USerTest (name: WeshWesh)', () => {
|
||||||
|
expect(loader.loadByUsername('WeshWesh')).toEqual(tabUS[0]);
|
||||||
|
})
|
||||||
|
it('should return null', () => {
|
||||||
|
expect(loader.loadByUsername('jExistePas')).toBe(null);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
describe('loadByUserNamePassword tests', () => {
|
||||||
|
it('should return UserTest (name: WeshWesh, password: MdpDeOuf)', () => {
|
||||||
|
expect(loader.loadByUsernamePassword('WeshWesh', 'MdpDeOuf')).toEqual(tabUS[0]);
|
||||||
|
})
|
||||||
|
it('should return null', () => {
|
||||||
|
expect(loader.loadByUsernamePassword('jExistePas', 'jExistePas')).toBe(null);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
describe('loadUserByMatch tests', () => {
|
||||||
|
it('should return tabUS', () => {
|
||||||
|
expect(loader.loadUserByMatch(match)).toEqual(tabUS);
|
||||||
|
})
|
||||||
|
it('should return null', () => {
|
||||||
|
expect(loader.loadByUsernamePassword('jExistePas', 'jExistePas')).toEqual(null);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
describe('loadUserByConversation tests', () => {
|
||||||
|
it('should return tabUS', () => {
|
||||||
|
expect(loader.loadUserByConversation(convo)).toEqual(tabUS);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
import LoaderUserApi from '../userServices/loaderUserApi';
|
||||||
|
import SaverUserApi from '../userServices/saverUserApi';
|
||||||
|
|
||||||
|
|
||||||
|
// Instances
|
||||||
|
let saver:SaverUserApi = new SaverUserApi();
|
||||||
|
let loader = new LoaderUserApi();
|
||||||
|
|
||||||
|
|
||||||
|
// Tests
|
||||||
|
|
||||||
|
describe('SaverUserApi tests', () => {
|
||||||
|
describe('saverUser tests', () => {
|
||||||
|
})
|
||||||
|
})
|
||||||
|
*/
|
||||||
|
|
||||||
|
it('should return true', () => {
|
||||||
|
expect(1+1).toBe(2);
|
||||||
|
})
|
@ -0,0 +1,78 @@
|
|||||||
|
import StubUser from '../userServices/stub';
|
||||||
|
import { User } from '../../core/User/user';
|
||||||
|
import { Skin } from '../../core/skin';
|
||||||
|
import { GameSolo } from '../../core/gameSolo';
|
||||||
|
import MatchSolo from '../../core/Match/matchSolo';
|
||||||
|
import { Match } from '../../core/Match/match';
|
||||||
|
import { Conversation } from '../../core/conversation';
|
||||||
|
|
||||||
|
// Instances
|
||||||
|
const img = "";
|
||||||
|
let stub:StubUser = new StubUser();
|
||||||
|
let map = new Map<number, number>([
|
||||||
|
[50, 3],
|
||||||
|
[75, 4],
|
||||||
|
[100, 5],
|
||||||
|
[150, 6]
|
||||||
|
]);
|
||||||
|
let tabUS:User[] = [
|
||||||
|
new User(1, "WeshWesh", "MdpDeOuf", "ouioui", "grand", new Date(2022,12,12), 12222, 123324, 12, new Skin(1, "Bob", img, 0), [new Skin(1, "Bob", img, 0)]),
|
||||||
|
new User(2, "leBg", "MdpDeOuf", "ouioui", "grand", new Date(2022,12,12), 12222, 123324, 12, new Skin(1, "Bob", img, 0), [new Skin(1, "Bob", img, 0)]),
|
||||||
|
new User(3, "Alban", "oui", "ouioui", "homme", new Date(2022,12,12), 555, 667, 12, new Skin(1, "Bob", img, 0), [new Skin(1, "Bob", img, 0)],),
|
||||||
|
new User(4, "Fefe63", "jesuishm", "ouioui", "homme", new Date(2022,12,12), 12222, 123324, 12, new Skin(1, "Bob", img, 0), [new Skin(1, "Bob", img, 0)]),
|
||||||
|
];
|
||||||
|
let game:GameSolo = new GameSolo(1, 'SuperJeu', img, 'source', 1, 1, map);
|
||||||
|
let match:Match = new MatchSolo(1, false, tabUS, game);
|
||||||
|
let convo:Conversation = new Conversation(1, tabUS, [], 'superConvo');
|
||||||
|
|
||||||
|
|
||||||
|
// Tests
|
||||||
|
describe('StubUser tests', () => {
|
||||||
|
describe('loadAllUser tests', () => {
|
||||||
|
it('should return tabUS', () => {
|
||||||
|
expect(stub.loadAllUser()).toEqual(tabUS);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
describe('loadById tests', () => {
|
||||||
|
it('should return UserTest (id: 48)', () => {
|
||||||
|
expect(stub.loadByID(48)).toEqual(tabUS[0]);
|
||||||
|
})
|
||||||
|
it('should return null', () => {
|
||||||
|
expect(stub.loadByID(999999999999)).toBe(null);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
describe('loadByUserName tests', () => {
|
||||||
|
it('should return USerTest (name: WeshWesh)', () => {
|
||||||
|
expect(stub.loadByUsername('WeshWesh')).toEqual(tabUS[0]);
|
||||||
|
})
|
||||||
|
it('should return null', () => {
|
||||||
|
expect(stub.loadByUsername('jExistePas')).toBe(null);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
describe('loadByUserNamePassword tests', () => {
|
||||||
|
it('should return UserTest (name: WeshWesh, password: MdpDeOuf)', () => {
|
||||||
|
expect(stub.loadByUsernamePassword('WeshWesh', 'MdpDeOuf')).toEqual(tabUS[0]);
|
||||||
|
})
|
||||||
|
it('should return null', () => {
|
||||||
|
expect(stub.loadByUsernamePassword('jExistePas', 'jExistePas')).toBe(null);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
describe('loadUserByMatch tests', () => {
|
||||||
|
it('should return tabUS', () => {
|
||||||
|
expect(stub.loadUserByMatch(match)).toEqual(tabUS);
|
||||||
|
})
|
||||||
|
it('should return null', () => {
|
||||||
|
expect(stub.loadByUsernamePassword('jExistePas', 'jExistePas')).toEqual(null);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
describe('loadUserByConversation tests', () => {
|
||||||
|
it('should return tabUS', () => {
|
||||||
|
expect(stub.loadUserByConversation(convo)).toEqual(tabUS);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
describe('loadLastId', () => {
|
||||||
|
it('should return U0005', () => {
|
||||||
|
expect(stub.loadLastId()).toBe('U0005');
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
@ -0,0 +1,52 @@
|
|||||||
|
import { Conversation } from "../../core/conversation";
|
||||||
|
import { Match } from "../../core/Match/match";
|
||||||
|
import { User } from "../../core/User/user";
|
||||||
|
|
||||||
|
export default interface ILoaderUser{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* loadAllUser methode that load every user from the data management system
|
||||||
|
* return an array of User
|
||||||
|
*/
|
||||||
|
loadAllUser(): Promise<User[]>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* loadByID methode that load a user from the data management system by his id
|
||||||
|
* id the id we want to search
|
||||||
|
* return a User if found, if not null
|
||||||
|
*/
|
||||||
|
loadByID(id:number): Promise<User | null>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* loadByUsername methode that load a user from the data management system by his username
|
||||||
|
* username the username we want to search
|
||||||
|
* return a User if found, if not null
|
||||||
|
*/
|
||||||
|
loadByUsername(username:string): Promise<User | null>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* loadByUsernamePassword methode that load a user from the data management system by his username and his password
|
||||||
|
* username the username we want to search
|
||||||
|
* password the password we want to search
|
||||||
|
* return a User if found, if not null
|
||||||
|
*/
|
||||||
|
loadByUsernamePassword(username:string, password:string): Promise<User | null>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* loadUserByMatch methode that load every user in a game
|
||||||
|
* return an array of User
|
||||||
|
*/
|
||||||
|
loadUserByMatch(m:Match): Promise<User[]>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* laodUserByConversation methode that load every user in a Conversation
|
||||||
|
* return an array of User
|
||||||
|
*/
|
||||||
|
loadUserByConversation(c:Conversation): Promise<User[]>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* loadLastId methode that load the last id used to create a user
|
||||||
|
* return a String
|
||||||
|
*/
|
||||||
|
loadLastId(): Promise<number>;
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
import { User } from "../../core/User/user";
|
||||||
|
|
||||||
|
export default interface ISaverUser{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* saveUser methode that save a User in the data management system
|
||||||
|
* u the user we want to save
|
||||||
|
*/
|
||||||
|
|
||||||
|
saveUser(username:string, password:string, nationality:string, sexe:string, date:Date): Promise<User | null>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* deleteUser methode that delete a User in the data management system
|
||||||
|
* u the user we want to delete
|
||||||
|
*/
|
||||||
|
deleteUser(u:User | null):Promise<void>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* updateUser methode that update a User in the data management system
|
||||||
|
* u the user we want to update
|
||||||
|
*/
|
||||||
|
updateUser(u:User | null): Promise<void>;
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
import { User } from "../../core/User/user";
|
||||||
|
import ILoaderUser from "./ILoaderUser";
|
||||||
|
import ISaverUser from "./ISaverUser";
|
||||||
|
|
||||||
|
export default class ManagerUser{
|
||||||
|
|
||||||
|
private currentUser: User | null=null;
|
||||||
|
|
||||||
|
private loaderUser: ILoaderUser;
|
||||||
|
|
||||||
|
private saverUser: ISaverUser;
|
||||||
|
|
||||||
|
constructor(loader:ILoaderUser, saver:ISaverUser){
|
||||||
|
this.loaderUser=loader;
|
||||||
|
this.saverUser=saver;
|
||||||
|
}
|
||||||
|
|
||||||
|
getCurrentUser(){
|
||||||
|
return this.currentUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
setCurrentUser(u:User | null){
|
||||||
|
this.currentUser=u;
|
||||||
|
}
|
||||||
|
|
||||||
|
getLoaderUser(){
|
||||||
|
return this.loaderUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
setLoaderUser(l:ILoaderUser){
|
||||||
|
this.loaderUser=l;
|
||||||
|
}
|
||||||
|
|
||||||
|
getsaverUser(){
|
||||||
|
return this.saverUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
setsaverUser(s:ISaverUser){
|
||||||
|
this.saverUser=s;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
import { User } from "../../core/User/user";
|
||||||
|
import ISaverUser from "./ISaverUser";
|
||||||
|
|
||||||
|
|
||||||
|
export default class FakeSaverUser implements ISaverUser{
|
||||||
|
|
||||||
|
async saveUser(username:string, password:string, nationality:string, sexe:string, date:Date): Promise<User | null> {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
async deleteUser(u: User): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
async updateUser(u: User): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,136 @@
|
|||||||
|
import tabSkinApp from "../../constSkin";
|
||||||
|
import { Conversation } from "../../core/conversation";
|
||||||
|
import { Match } from "../../core/Match/match";
|
||||||
|
import { Skin } from "../../core/skin";
|
||||||
|
import { User } from "../../core/User/user";
|
||||||
|
import ILoaderUser from "./ILoaderUser";
|
||||||
|
|
||||||
|
class Test{
|
||||||
|
public completed:boolean;
|
||||||
|
public id: number;
|
||||||
|
public title: String;
|
||||||
|
public userId: number;
|
||||||
|
|
||||||
|
constructor(completed: boolean, id:number, title:String, userId: number){
|
||||||
|
this.completed=completed;
|
||||||
|
this.id=id;
|
||||||
|
this.title=title;
|
||||||
|
this.userId=userId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class LoaderUserApi implements ILoaderUser{
|
||||||
|
|
||||||
|
private axios = require('axios').default;
|
||||||
|
|
||||||
|
async loadAllUser() : Promise<User[]> {
|
||||||
|
let us:User[]=[];
|
||||||
|
let test=new Test(false, 1, "a", 1);
|
||||||
|
await this.axios({
|
||||||
|
method: 'get',
|
||||||
|
url: 'https://jsonplaceholder.typicode.com/todos',
|
||||||
|
params: {
|
||||||
|
name: "getAllUser",
|
||||||
|
//Les params genre nom de la fonction en php
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(function (response: any) {
|
||||||
|
if (response.data != null && response.data != undefined){
|
||||||
|
Object.assign(test, response.data);
|
||||||
|
us.push(new User(1, "Fefe63", "jesuishm", "ouioui", "homme", new Date(2022,12,12), 12222, 123324, 12, tabSkinApp[6], tabSkinApp));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return us;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async loadByID(id: number): Promise<User | null> {
|
||||||
|
let test = new Test(true, 0, "wesh", 0);
|
||||||
|
try{
|
||||||
|
await this.axios({
|
||||||
|
method: 'get',
|
||||||
|
url: 'https://jsonplaceholder.typicode.com/todos/1',
|
||||||
|
params: {
|
||||||
|
name: "getUserById",
|
||||||
|
id: id,
|
||||||
|
//Les params genre nom de la fonction en php
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(function (response: any) {
|
||||||
|
console.log(response.data);
|
||||||
|
Object.assign(test, response.data);
|
||||||
|
console.log(test.id);
|
||||||
|
});
|
||||||
|
}catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
return new User(1, "Bite", "jesuishm", "ouioui", "homme", new Date(2022,12,12), 123, 123324, 12, tabSkinApp[6], tabSkinApp);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async loadByUsername(username: string): Promise<User | null> {
|
||||||
|
let test = new Test(true, 0, "wesh", 0);
|
||||||
|
try{
|
||||||
|
await this.axios({
|
||||||
|
method: 'get',
|
||||||
|
url: 'https://jsonplaceholder.typicode.com/todos/1',
|
||||||
|
params: {
|
||||||
|
name: "getUserByUsername",
|
||||||
|
username: username,
|
||||||
|
//Les params genre nom de la fonction en php
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(function (response: any) {
|
||||||
|
console.log(response.data);
|
||||||
|
Object.assign(test, response.data);
|
||||||
|
console.log(test.id);
|
||||||
|
});
|
||||||
|
}catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
async loadByUsernamePassword(username: string, password: string): Promise<User | null>{
|
||||||
|
let user:User | null=null;
|
||||||
|
await this.axios({
|
||||||
|
method: 'get',
|
||||||
|
url: 'https://jsonplaceholder.typicode.com/todos/1',
|
||||||
|
params: {
|
||||||
|
name: "getAllUser",
|
||||||
|
//Les params genre nom de la fonction en php
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(function (response: any) {
|
||||||
|
const tabTest=[new Skin(1, "Bob","https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/BobsSkins/BobClassic.png", 0),
|
||||||
|
new Skin(2, "Bob Blue","https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/BobsSkins/BobBlue.png", 100)];
|
||||||
|
user=new User(1, username, password, "ouioui", "homme", new Date(2022,12,12), 200, 123324, 12, new Skin(1, "Bob","https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/BobsSkins/BobClassic.png", 0), tabTest);
|
||||||
|
});
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
async loadUserByMatch(m: Match): Promise<User[]> {
|
||||||
|
throw new Error("Method not implemented.");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async loadUserByConversation(c: Conversation): Promise<User[]> {
|
||||||
|
throw new Error("Method not implemented.");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async loadLastId(): Promise<number> {
|
||||||
|
let test = new Test(true, 0, "wesh", 0);
|
||||||
|
try {
|
||||||
|
const response = await this.axios.get('https://jsonplaceholder.typicode.com/todos/1');
|
||||||
|
console.log(response.data);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue