diff --git a/srcs/requirements/nestjs/api_back/src/game/game.controller.ts b/srcs/requirements/nestjs/api_back/src/game/game.controller.ts index ab5f787e..bd7636e3 100644 --- a/srcs/requirements/nestjs/api_back/src/game/game.controller.ts +++ b/srcs/requirements/nestjs/api_back/src/game/game.controller.ts @@ -1,4 +1,4 @@ -import { Body, Controller, Get, HttpException, HttpStatus, Param, Post, Req, Res, UseGuards } from '@nestjs/common'; +import { Body, Controller, Get, HttpException, HttpStatus, Param, Post, Query, Req, Res, UseGuards } from '@nestjs/common'; import { AuthenticateGuard, TwoFactorGuard } from 'src/auth/42/guards/42guards'; import { User } from 'src/users/entities/user.entity'; import { Response } from 'express'; @@ -21,11 +21,13 @@ export class GameController { return this.gameService.getMatchesForSpectator(); } - @Get('match/history/:username') + @Get('match/history') @UseGuards(AuthenticateGuard) @UseGuards(TwoFactorGuard) - async getMatchHistory(@Req() req, @Param('username') username: string, @Res() res) + async getMatchHistory(@Req() req, @Query('username') username: string, @Res() res) { + console.log("DANS MATCH HISTORY") + console.log("usrrnmae" + username) return this.gameService.getMatchHistory(username, res); } diff --git a/srcs/requirements/nestjs/api_back/src/game/game.service.ts b/srcs/requirements/nestjs/api_back/src/game/game.service.ts index 00ac5e78..0ef558a1 100644 --- a/srcs/requirements/nestjs/api_back/src/game/game.service.ts +++ b/srcs/requirements/nestjs/api_back/src/game/game.service.ts @@ -49,22 +49,30 @@ export class GameService { async getMatchHistory(username : string, @Res() res : Response) { - const user = await this.userService.findOne(username); + const user = await this.userRepository.createQueryBuilder("user") + .where('user.username = :username', {username: username}) + .getOne(); if (!user) return res.status(HttpStatus.NOT_FOUND).json({message : "History for " + username + " not found"}); - const gameHistory = await this.matchHistory - .createQueryBuilder('history') + console.log(user.username + 'OK USERNAME') + const gameHistory = await this.matchHistory. + createQueryBuilder('history') .leftJoinAndSelect('history.playerOne', 'playerOne') .leftJoinAndSelect('history.playerTwo', 'playerTwo') - .where('playerOne.id = :playerOneId', { playerOneId: user.id }) - .orWhere('playerTwo.id = :playerTwoId', { playerTwoId: user.id }) - .getMany(); + .where('history.playerOne.id = :userOne', {userOne : user.id}) + .orWhere('history.playerTwo.id = :userTwo', {userTwo: user.id}) + .getMany() + console.log("gZZZZZZZZZZZZamehistory") + console.log(...gameHistory) let sendableHistory : SendableMatchHistory[] = [] for (const history of gameHistory) { + console.log(history.playerOne.username + 'ssssssssss') sendableHistory.push(new SendableMatchHistory(history)) } - return sendableHistory; + console.log("sendable history") + console.log(sendableHistory); + return res.status(HttpStatus.OK).json(sendableHistory); } async getRankingForAllUsers(currentUser : User) { @@ -323,6 +331,7 @@ export class GameService { matchHistory.playerOneResult = game.playerOneUsernameResult; matchHistory.playerTwoResult = game.playerTwoUsernameResult; const savedHistory = await this.matchHistory.save(matchHistory); + console.log("MATCH HISTORYsssssssssss") console.log(savedHistory); return HttpStatus.OK } diff --git a/srcs/requirements/nestjs/api_back/src/users/class/matchHistory.class.ts b/srcs/requirements/nestjs/api_back/src/users/class/matchHistory.class.ts index a0bc4a4e..90cafc65 100644 --- a/srcs/requirements/nestjs/api_back/src/users/class/matchHistory.class.ts +++ b/srcs/requirements/nestjs/api_back/src/users/class/matchHistory.class.ts @@ -16,6 +16,6 @@ export class SendableMatchHistory { this.playerOneUsername = matchHistory.playerOne.username; this.playerTwoUsername = matchHistory.playerTwo.username; this.playerOneResult = matchHistory.playerOneResult; - this.playerTwoResult = matchHistory.playerTwoResult; + this.playerTwoResult = matchHistory.playerTwoResult; }; } \ No newline at end of file diff --git a/srcs/requirements/svelte/api_front/src/pieces/MatchHistory.svelte b/srcs/requirements/svelte/api_front/src/pieces/MatchHistory.svelte index ba32cf9e..e157c0da 100644 --- a/srcs/requirements/svelte/api_front/src/pieces/MatchHistory.svelte +++ b/srcs/requirements/svelte/api_front/src/pieces/MatchHistory.svelte @@ -5,9 +5,9 @@ import type { MatchHistory } from "./Match"; export let user; - let matchList: MatchHistory[] = []; - + let matchList = []; onMount( async() => { + console.log(user.username + 'jjjjjjjjjjjjj') matchList = await fetchMatchList(user.username); console.log(matchList); // matchList = await mockMatchList(user.username); @@ -15,8 +15,8 @@ async function fetchMatchList(username: string) { - let url = `http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/game/match/history/${username}`; - + let url = `http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/game/match/history?username=${username}`; + console.log(url + 'ffffffff') return fetch(url) .then((response) => { if (!response.ok) {