Merge branch 'master' into hugo
This commit is contained in:
@@ -200,8 +200,10 @@ export class GameService {
|
||||
|
||||
async declineInvitation(user : User, token : string, @Res() res : Response)
|
||||
{
|
||||
if (user.status !== STATUS.CONNECTED)
|
||||
return res.status(HttpStatus.FORBIDDEN).json({message : "You must not be in game to decline an invitation"});
|
||||
/* Luke: le check de user.status n'est pas fonctionnel avec l'implémentation des invitations dans le front.
|
||||
Ça me semble dispensable, je désactive donc pour le moment plutôt que de refaire l'implémentation front. */
|
||||
// if (user.status !== STATUS.CONNECTED)
|
||||
// return res.status(HttpStatus.FORBIDDEN).json({message : "You must not be in game to decline an invitation"});
|
||||
console.log("On décline l'invitation")
|
||||
const tokenGame = await this.tokenGameRepository.createQueryBuilder('tokengame')
|
||||
.andWhere('tokengame.playerTwoUsername = :playerTwoUsername', {playerTwoUsername : user.username})
|
||||
@@ -236,8 +238,10 @@ export class GameService {
|
||||
|
||||
async acceptInvitation(user : User, token : string, @Res() res : Response)
|
||||
{
|
||||
if (user.status !== STATUS.CONNECTED)
|
||||
return res.status(HttpStatus.FORBIDDEN).send("")
|
||||
/* Luke: le check de user.status n'est pas fonctionnel avec l'implémentation des invitations dans le front.
|
||||
Ça me semble dispensable, je désactive donc pour le moment plutôt que de refaire l'implémentation front. */
|
||||
// if (user.status !== STATUS.CONNECTED)
|
||||
// return res.status(HttpStatus.FORBIDDEN).send("")
|
||||
const tokenGame = await this.tokenGameRepository.createQueryBuilder('tokenGame')
|
||||
.andWhere('tokenGame.playerTwoUsername = :playerTwoUsername', {playerTwoUsername : user.username})
|
||||
.andWhere('tokenGame.token = :token', {token : token})
|
||||
|
||||
BIN
srcs/requirements/svelte/api_front/public/img/default.png
Normal file
BIN
srcs/requirements/svelte/api_front/public/img/default.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 69 KiB |
@@ -4,11 +4,13 @@
|
||||
import { fade, fly } from 'svelte/transition';
|
||||
|
||||
import Header from '../../pieces/Header.svelte';
|
||||
import { fetchAvatar } from "../../pieces/utils";
|
||||
import { fetchUser, fetchAllUsers, fetchAvatar } from "../../pieces/utils";
|
||||
|
||||
import * as pong from "./client/pong";
|
||||
import { gameState } from "./client/ws";
|
||||
|
||||
import { invited_username } from '../../pieces/store_invitation';
|
||||
|
||||
//user's stuff
|
||||
let user;
|
||||
let allUsers;
|
||||
@@ -36,11 +38,21 @@
|
||||
const watchMatchStartIntervalRate = 111;
|
||||
|
||||
onMount( async() => {
|
||||
user = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/user`)
|
||||
.then( x => x.json() );
|
||||
allUsers = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/user/all`)
|
||||
.then( x => x.json() );
|
||||
user = await fetchUser();
|
||||
allUsers = await fetchAllUsers();
|
||||
|
||||
if (!user) {
|
||||
showError = true;
|
||||
errorMessage = "User load failed";
|
||||
return;
|
||||
}
|
||||
|
||||
options.playerOneUsername = user.username;
|
||||
if ($invited_username) {
|
||||
options.isSomeoneIsInvited = true;
|
||||
options.playerTwoUsername = $invited_username;
|
||||
invited_username.set("");
|
||||
}
|
||||
})
|
||||
|
||||
onDestroy( async() => {
|
||||
@@ -298,8 +310,8 @@
|
||||
|
||||
{#if options.isSomeoneIsInvited}
|
||||
<select bind:value={options.playerTwoUsername}>
|
||||
{#each allUsers as user }
|
||||
<option value={user.username}>{user.username}</option>
|
||||
{#each allUsers as invitedUser }
|
||||
<option value={invitedUser.username}>{invitedUser.username}</option>
|
||||
{/each}
|
||||
</select>
|
||||
{/if}
|
||||
|
||||
@@ -6,15 +6,11 @@
|
||||
import Header from '../../pieces/Header.svelte';
|
||||
import MatchListElem from "../../pieces/MatchListElem.svelte";
|
||||
import type { Match } from "../../pieces/Match";
|
||||
import { fetchAvatar } from "../../pieces/utils";
|
||||
import { fetchUser, fetchAllUsers, fetchAvatar } from "../../pieces/utils";
|
||||
|
||||
import * as pongSpectator from "./client/pongSpectator";
|
||||
import { gameState } from "./client/ws";
|
||||
|
||||
//user's stuff
|
||||
let user;
|
||||
let allUsers;
|
||||
|
||||
let playerOneAvatar;
|
||||
let playerTwoAvatar;
|
||||
|
||||
@@ -30,13 +26,7 @@
|
||||
const watchGameStateIntervalRate = 142;
|
||||
|
||||
onMount( async() => {
|
||||
user = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/user`)
|
||||
.then( x => x.json() );
|
||||
allUsers = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/user/all`)
|
||||
.then( x => x.json() );
|
||||
const responseForMatchList = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/game/match/all`)
|
||||
const jsonForMatchList = await responseForMatchList.json();
|
||||
matchList = jsonForMatchList;
|
||||
matchList = await fetchMatchList();
|
||||
})
|
||||
|
||||
onDestroy( async() => {
|
||||
@@ -82,12 +72,25 @@
|
||||
async function resetPage() {
|
||||
hiddenGame = true;
|
||||
pongSpectator.destroy();
|
||||
fetchMatchList();
|
||||
matchList = await fetchMatchList();
|
||||
};
|
||||
|
||||
async function fetchMatchList() {
|
||||
matchList = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/game/match/all`)
|
||||
.then( x => x.json() );
|
||||
async function fetchMatchList()
|
||||
{
|
||||
return fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/game/match/all`)
|
||||
.then((response) => {
|
||||
if (!response.ok) {
|
||||
throw new Error("All matchs not retrieved");
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then((body) => {
|
||||
return body;
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("catch fetchMatchList: ", error);
|
||||
return [];
|
||||
});
|
||||
};
|
||||
|
||||
</script>
|
||||
|
||||
@@ -8,6 +8,15 @@
|
||||
let mute = "mute";
|
||||
let block = "block";
|
||||
|
||||
import { push } from "svelte-spa-router";
|
||||
import { invited_username } from '../store_invitation';
|
||||
function game_invitation()
|
||||
{
|
||||
const usernamePLACEHOLDER = "hulamy";
|
||||
invited_username.set(usernamePLACEHOLDER);
|
||||
push("/game");
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<div class="grid_box">
|
||||
@@ -40,7 +49,7 @@
|
||||
<Button>
|
||||
view profile
|
||||
</Button>
|
||||
<Button>
|
||||
<Button on_click={() => game_invitation()}>
|
||||
game invitation
|
||||
</Button>
|
||||
<Button>
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
export const invited_username = writable("");
|
||||
@@ -13,5 +13,42 @@ export async function fetchAvatar(username: string)
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("catch fetchAvatar: ", error);
|
||||
return `http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/img/default.png`;
|
||||
});
|
||||
}
|
||||
|
||||
export async function fetchUser()
|
||||
{
|
||||
return fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/user`)
|
||||
.then((response) => {
|
||||
if (!response.ok) {
|
||||
throw new Error("User not retrieved");
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then((body) => {
|
||||
return body;
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("catch fetchUser: ", error);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
export async function fetchAllUsers()
|
||||
{
|
||||
return fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/user/all`)
|
||||
.then((response) => {
|
||||
if (!response.ok) {
|
||||
throw new Error("All Users not retrieved");
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then((body) => {
|
||||
return body;
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("catch fetchAllUsers: ", error);
|
||||
return [];
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user