From 450ece53937c84f44a3b8f9f9ed9c2a351c04b41 Mon Sep 17 00:00:00 2001 From: kinou-p Date: Wed, 7 Jun 2023 17:58:27 +0200 Subject: [PATCH] add social friend with redirection to personnal profile page and show personnal match log --- containers/api/src/app.controller.ts | 9 +++++---- containers/api/src/users/users.service.ts | 2 +- containers/react/src/components/Profile/Win_Loss.jsx | 11 ++++++++--- containers/react/src/pages/Home.jsx | 4 +++- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/containers/api/src/app.controller.ts b/containers/api/src/app.controller.ts index 4778785d..8edc5334 100644 --- a/containers/api/src/app.controller.ts +++ b/containers/api/src/app.controller.ts @@ -45,8 +45,9 @@ export class AppController { } @UseGuards(JwtAuthGuard) - @Get('/user') + @Post('/user') async getUser( @Body() data: any) { + console.log(`usernamewwww= ${data.username}`) return await this.userService.findOne(data.username); } @@ -125,12 +126,12 @@ export class AppController { } @UseGuards(JwtAuthGuard) - @Get('/history') - async getHistory(@Request() req) + @Post('/history') + async getHistory(@Body() data: any) { // const user = await this.userService.findOne(req.user.username); // return user.rank; - return await this.userService.getHistory(req.user.username); + return await this.userService.getHistory(data.username); // if (user) { // const children = user.children; diff --git a/containers/api/src/users/users.service.ts b/containers/api/src/users/users.service.ts index 45e945dc..43b5cb41 100644 --- a/containers/api/src/users/users.service.ts +++ b/containers/api/src/users/users.service.ts @@ -43,7 +43,7 @@ export class UsersService { const user = await this.findOne(username) let friendsTab = user.friends console.log(friendsTab) - friendsTab = ['apommier'] + friendsTab = ['apommier', 'syd'] const friends = await this.userRepository.query("SELECT * FROM \"User\" WHERE username = ANY ($1);", [friendsTab]); console.log(friends) return (friends) diff --git a/containers/react/src/components/Profile/Win_Loss.jsx b/containers/react/src/components/Profile/Win_Loss.jsx index 936beb2f..a59de74c 100644 --- a/containers/react/src/components/Profile/Win_Loss.jsx +++ b/containers/react/src/components/Profile/Win_Loss.jsx @@ -45,19 +45,24 @@ import '../../styles/Win_Loss.css' // ` import React, { useState, useEffect, useRef } from "react"; +import { useParams } from 'react-router-dom'; import api from '../../script/axiosApi'; -function WinLoss() { +function WinLoss() { + const [user, setUser] = useState(null); const [history, setHistory] = useState([]); const [isLoading, setIsLoading] = useState(true); + + const { username } = useParams(); useEffect(()=> { const getUser = async ()=>{ try{ - const tmpUser = await api.get("/profile") - const tmpHistory = await api.get("/history") + // const tmpUser = await api.get("/profile") + const tmpUser = await api.post("/user", {username: username}) + const tmpHistory = await api.post("/history", {username: username}) setHistory(tmpHistory.data); setUser(tmpUser.data); setIsLoading(false) diff --git a/containers/react/src/pages/Home.jsx b/containers/react/src/pages/Home.jsx index 25fefb6f..1da40cd4 100644 --- a/containers/react/src/pages/Home.jsx +++ b/containers/react/src/pages/Home.jsx @@ -41,9 +41,11 @@ function Profile () { useEffect(()=> { const getUser = async ()=>{ + console.log(`username= ${username}`) try{ - const tmpUser = await api.get("/user", {username: username}) + const tmpUser = await api.post("/user", {username: username}) setUser(tmpUser.data); + console.log(`user= ${tmpUser.data.username}`) setIsLoading(false) } catch(err){