DELETE: touts les fichiers de classes obsolètes
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
ADD: Les classses pour l'apitemp
parent
b7aa8d1974
commit
9c06bc1bac
@ -1,20 +1,83 @@
|
|||||||
import React from 'react'
|
import LoaderUserApi from './src/services/userServices/loaderUserApi'
|
||||||
import { GameMulti } from './src/core/gameMulti'
|
import ManagerUser from './src/services/userServices/ManagerUser'
|
||||||
import { GameSolo } from './src/core/gameSolo'
|
import FakeSaverUser from './src/services/userServices/fakeSaverUser'
|
||||||
import { Match } from './src/core/match'
|
import { View, Text, Button } from 'react-native';
|
||||||
import { MatchMulti } from './src/core/matchMulti'
|
import React, { useCallback } from 'react';
|
||||||
import MainTabNavigator from './src/navigation/AppNavigator'
|
import { useUserStore } from './userContext';
|
||||||
import FakeSaverUser from './src/screens/services/userServices/fakeSaverUser'
|
import stylesScreen from './src/screens/style/screens.style'
|
||||||
import ManagerUser from './src/screens/services/userServices/ManagerUser'
|
import { User } from './src/core/User/user';
|
||||||
import StubUser from './src/screens/services/userServices/stub'
|
import tabSkinApp from './src/constSkin';
|
||||||
|
import { stat } from 'fs';
|
||||||
|
import StubUser from './src/services/userServices/stub';
|
||||||
export default function App() {
|
|
||||||
let m=new ManagerUser(new StubUser, new FakeSaverUser);
|
|
||||||
let tabU=m.getLoaderUser().loadAllUser();
|
|
||||||
m.setCurrentUser(tabU[0]);
|
export const MANAGER_USER = new ManagerUser(new StubUser, new FakeSaverUser);
|
||||||
|
|
||||||
let match= new MatchMulti("00001", [...tabU], new GameMulti("1", "SNAKE", require('./assets/Icons/UnSelected/Gamepad.png'),"ouin", 1, 1, new Map<number,number>));
|
|
||||||
console.log(m.getLoaderUser().loadUserByMatch(match));
|
export default function App() {
|
||||||
//return <MainTabNavigator/>
|
const setUser = useUserStore((state) => state.setUser);
|
||||||
}
|
const resetUser = useUserStore((state) => state.resetUser);
|
||||||
|
|
||||||
|
const handleUserConnect = useCallback(async () => {
|
||||||
|
/*
|
||||||
|
fetch(GET_USER_URL)
|
||||||
|
.then((res) => {
|
||||||
|
if (res.status === 200) {
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
throw new Error("Bad User");
|
||||||
|
})
|
||||||
|
.then((user) => {
|
||||||
|
setUser(user);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
await MANAGER_USER.getLoaderUser().loadByID("14").then((res) => {
|
||||||
|
MANAGER_USER.setCurrentUser(res);
|
||||||
|
console.log(res);
|
||||||
|
});
|
||||||
|
setUser(MANAGER_USER.getCurrentUser());
|
||||||
|
|
||||||
|
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleUserLogout = useCallback(async () => {
|
||||||
|
// TODO: Call logout API
|
||||||
|
MANAGER_USER.setCurrentUser(null);
|
||||||
|
resetUser();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleUserChange = useCallback(async () => {
|
||||||
|
MANAGER_USER.getCurrentUser()?.setCurrentCoins(MANAGER_USER.getCurrentUser()?.getCurrentCoins()+100);
|
||||||
|
setUser(MANAGER_USER.getCurrentUser());
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={stylesScreen.bodyCenter}>
|
||||||
|
<AUser />
|
||||||
|
<Button onPress={handleUserConnect} title="Connect"></Button>
|
||||||
|
<Button onPress={handleUserLogout} title="Logout"></Button>
|
||||||
|
<Button onPress={handleUserChange} title="testChangement"></Button>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const AUser = () => {
|
||||||
|
const userName = useUserStore((state) => state.user?.getUsername());
|
||||||
|
const test = useUserStore((state) => state.user?.getCurrentCoins());
|
||||||
|
return userName === undefined ? (
|
||||||
|
<Text>Not Connected</Text>
|
||||||
|
) : (
|
||||||
|
<View>
|
||||||
|
<Text>Hello {userName}</Text>
|
||||||
|
<Text>Money {test}</Text>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,19 +0,0 @@
|
|||||||
import { User } from "./user";
|
|
||||||
|
|
||||||
export class ManagerCoinsUser{
|
|
||||||
addCoins(u:User, coins:number){
|
|
||||||
u.setCurrentCoins(u.getCurrentCoins()+coins);
|
|
||||||
u.setTotalCoins(u.getTotalCoins()+coins);
|
|
||||||
//modif dans la bdd
|
|
||||||
}
|
|
||||||
|
|
||||||
removeCoins(u:User, coins:number){
|
|
||||||
u.setCurrentCoins(u.getCurrentCoins()-coins);
|
|
||||||
//modif dans la bdd
|
|
||||||
}
|
|
||||||
|
|
||||||
changeCurrentCoins(u:User, coins:number){
|
|
||||||
u.setCurrentCoins(coins);
|
|
||||||
//modif dans la bdd
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,23 @@
|
|||||||
|
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){
|
||||||
|
u.setCurrentCoins(u.getCurrentCoins()-coins);
|
||||||
|
await MANAGER_USER.getsaverUser().updateUser(u);
|
||||||
|
}
|
||||||
|
|
||||||
|
async changeCurrentCoins(u:User, coins:number){
|
||||||
|
u.setCurrentCoins(coins);
|
||||||
|
await MANAGER_USER.getsaverUser().updateUser(u);
|
||||||
|
}
|
||||||
|
}
|
@ -1,12 +1,29 @@
|
|||||||
import { User } from "./user";
|
import { User } from "./user";
|
||||||
import tabSkinApp from "../../constSkin";
|
import tabSkinApp from "../../constSkin";
|
||||||
import { Conversation } from "../conversation";
|
import { Conversation } from "../conversation";
|
||||||
|
import ManagerUser from "../../services/userServices/ManagerUser";
|
||||||
|
import { MANAGER_USER } from "../../../App";
|
||||||
|
|
||||||
export class UserCreator{
|
export class UserCreator{
|
||||||
createUser(username:string, password:string, nationality:string, sexe:string, date:Date){
|
|
||||||
|
async createUser(username:string, password:string, nationality:string, sexe:string, date:Date){
|
||||||
//Récup l'ID d'après dans la bdd
|
//Récup l'ID d'après dans la bdd
|
||||||
const u = new User('0000', username, password, nationality, sexe, date, 0, 0, 0, tabSkinApp[0], [tabSkinApp[0]]);
|
let u:User;
|
||||||
//Ajout du joueur dans la bdd
|
let newId:string="";
|
||||||
|
|
||||||
|
let oldId = await MANAGER_USER.getLoaderUser().loadLastId();
|
||||||
|
oldId=oldId.slice(1);
|
||||||
|
let leInt=parseInt(oldId);
|
||||||
|
newId+="U";
|
||||||
|
for (let i = 0; i < 4-leInt.toString().length; i++) {
|
||||||
|
newId = newId + "0";
|
||||||
|
}
|
||||||
|
leInt+=1;
|
||||||
|
newId=newId+leInt;
|
||||||
|
console.log(newId);
|
||||||
|
u = new User(newId, username, password, nationality, sexe, date, 0, 0, 0, tabSkinApp[0], [tabSkinApp[0]]);
|
||||||
|
await MANAGER_USER.getsaverUser().saveUser(u);
|
||||||
|
MANAGER_USER.setCurrentUser(u);
|
||||||
return u;
|
return u;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,24 +1,25 @@
|
|||||||
|
import { MANAGER_USER } from "../../../App";
|
||||||
import { User } from "./user";
|
import { User } from "./user";
|
||||||
|
|
||||||
|
|
||||||
export default class UserModificationManager{
|
export default class UserModificationManager{
|
||||||
changePassword(user:User, password:string){
|
async changePassword(user:User, password:string){
|
||||||
user.setPassword(password);
|
user.setPassword(password);
|
||||||
//modif dans la bdd
|
await MANAGER_USER.getsaverUser().updateUser(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
changeUsername(user:User, username:string){
|
async changeUsername(user:User, username:string){
|
||||||
user.setPassword(username);
|
user.setPassword(username);
|
||||||
//modif dans la bdd
|
await MANAGER_USER.getsaverUser().updateUser(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
changeNationality(user:User, nationality:string){
|
async changeNationality(user:User, nationality:string){
|
||||||
user.setNationality(nationality);
|
user.setNationality(nationality);
|
||||||
//modif dans la bdd
|
await MANAGER_USER.getsaverUser().updateUser(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
changeSexe(user:User, sexe:string){
|
async changeSexe(user:User, sexe:string){
|
||||||
user.setSexe(sexe);
|
user.setSexe(sexe);
|
||||||
//modif dans la bdd
|
await MANAGER_USER.getsaverUser().updateUser(user);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,13 +1,16 @@
|
|||||||
|
import { MANAGER_USER } from '../../../App';
|
||||||
import { Skin } from '../Skin'
|
import { Skin } from '../Skin'
|
||||||
import { User } from './user'
|
import { User } from './user'
|
||||||
|
|
||||||
|
|
||||||
export default class UserSkinModifier{
|
export default class UserSkinModifier{
|
||||||
addSkin(user:User, skin:Skin){
|
async addSkin(user:User, skin:Skin){
|
||||||
user.addSkin(skin);
|
user.addSkin(skin);
|
||||||
|
await MANAGER_USER.getsaverUser().updateUser(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
changeCurrentSkin(user:User, skin:Skin){
|
async changeCurrentSkin(user:User, skin:Skin){
|
||||||
user.setCurrentSkin(skin);
|
user.setCurrentSkin(skin);
|
||||||
|
await MANAGER_USER.getsaverUser().updateUser(user);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,29 +0,0 @@
|
|||||||
import { Conversation } from "../../../core/conversation";
|
|
||||||
import { Match } from "../../../core/match";
|
|
||||||
import { User } from "../../../core/User/user";
|
|
||||||
import ILoaderUser from "./ILoaderUser";
|
|
||||||
|
|
||||||
export default class LoaderUserApi implements ILoaderUser{
|
|
||||||
|
|
||||||
async loadAllUser(): Promise<User[]> {
|
|
||||||
throw new Error("Method not implemented.");
|
|
||||||
}
|
|
||||||
async loadByID(id: string): Promise<User | null> {
|
|
||||||
throw new Error("Method not implemented.");
|
|
||||||
}
|
|
||||||
async loadByUsername(username: string): Promise<User | null> {
|
|
||||||
throw new Error("Method not implemented.");
|
|
||||||
}
|
|
||||||
async loadByUsernamePassword(username: string, password: string): Promise<User | null> {
|
|
||||||
throw new Error("Method not implemented.");
|
|
||||||
}
|
|
||||||
async loadUserByMatch(m: Match): Promise<User[]> {
|
|
||||||
throw new Error("Method not implemented.");
|
|
||||||
}
|
|
||||||
async loadUserByConversation(c: Conversation): Promise<User[]> {
|
|
||||||
throw new Error("Method not implemented.");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,5 +1,5 @@
|
|||||||
import { Conversation } from "../../../core/conversation";
|
import { Conversation } from "../../core/conversation";
|
||||||
import { User } from "../../../core/User/user";
|
import { User } from "../../core/User/user";
|
||||||
|
|
||||||
export default interface ILoaderConversation{
|
export default interface ILoaderConversation{
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
import { Conversation } from "../../../core/conversation";
|
import { Conversation } from "../../core/conversation";
|
||||||
|
|
||||||
export default interface ISaverConversation{
|
export default interface ISaverConversation{
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
import { Match } from "../../../core/match";
|
import { Match } from "../../core/match";
|
||||||
|
|
||||||
export default interface ILoaderMatch{
|
export default interface ILoaderMatch{
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
import { Match } from "../../../core/match";
|
import { Match } from "../../core/match";
|
||||||
|
|
||||||
export default interface ISaverMatch{
|
export default interface ISaverMatch{
|
||||||
|
|
@ -1,5 +1,5 @@
|
|||||||
import { Conversation } from "../../../core/conversation";
|
import { Conversation } from "../../core/conversation";
|
||||||
import { Message } from "../../../core/message";
|
import { Message } from "../../core/message";
|
||||||
|
|
||||||
export default interface ILoaderMessage{
|
export default interface ILoaderMessage{
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
import { Message } from "../../../core/message";
|
import { Message } from "../../core/message";
|
||||||
|
|
||||||
export default interface ISaverMessage{
|
export default interface ISaverMessage{
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
import { User } from "../../../core/User/user";
|
import { User } from "../../core/User/user";
|
||||||
|
|
||||||
export default interface ISaverUser{
|
export default interface ISaverUser{
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
import { User } from "../../../core/User/user";
|
import { User } from "../../core/User/user";
|
||||||
import ISaverUser from "./ISaverUser";
|
import ISaverUser from "./ISaverUser";
|
||||||
|
|
||||||
|
|
@ -0,0 +1,140 @@
|
|||||||
|
import { Conversation } from "../../core/conversation";
|
||||||
|
import { Match } from "../../core/match";
|
||||||
|
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 test = new Test(true, 0, "wesh", 0);
|
||||||
|
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) {
|
||||||
|
console.log(response.data);
|
||||||
|
Object.assign(test, response.data);
|
||||||
|
console.log(test.id);
|
||||||
|
});
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async loadByID(id: 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: "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 null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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 test = new Test(true, 0, "wesh", 0);
|
||||||
|
try{
|
||||||
|
await this.axios({
|
||||||
|
method: 'get',
|
||||||
|
url: 'https://jsonplaceholder.typicode.com/todos/1',
|
||||||
|
params: {
|
||||||
|
name: "getUserForConnection",
|
||||||
|
username: username,
|
||||||
|
password: password,
|
||||||
|
//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 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<string> {
|
||||||
|
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 "U0001";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -1,11 +1,21 @@
|
|||||||
import { User } from "../../../core/User/user";
|
import { User } from "../../core/User/user";
|
||||||
import ISaverUser from "./ISaverUser";
|
import ISaverUser from "./ISaverUser";
|
||||||
|
|
||||||
|
|
||||||
export default class SaverUserApi implements ISaverUser{
|
export default class SaverUserApi implements ISaverUser{
|
||||||
|
|
||||||
|
private axios = require('axios').default;
|
||||||
|
|
||||||
async saveUser(u: User): Promise<void> {
|
async saveUser(u: User): Promise<void> {
|
||||||
throw new Error("Method not implemented.");
|
this.axios({
|
||||||
|
method: 'post',
|
||||||
|
url: '/user/12345',
|
||||||
|
data: {
|
||||||
|
firstName: 'Fred',
|
||||||
|
lastName: 'Flintstone'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
async deleteUser(u: User): Promise<void> {
|
async deleteUser(u: User): Promise<void> {
|
||||||
throw new Error("Method not implemented.");
|
throw new Error("Method not implemented.");
|
@ -0,0 +1,18 @@
|
|||||||
|
import React from "react";
|
||||||
|
import create from "zustand";
|
||||||
|
import { User } from "./src/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: undefined })),
|
||||||
|
}));
|
Loading…
Reference in new issue