From 6e5841601428b5a7d16df78eb065dd7333734961 Mon Sep 17 00:00:00 2001 From: sayyyho <323psh@naver.com> Date: Thu, 14 Nov 2024 11:33:47 +0900 Subject: [PATCH 1/8] =?UTF-8?q?[Test]=20#41=20-=20=EB=88=84=EA=B5=AC?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=83=9D=EC=84=B1=20=EC=9C=A0?= =?UTF-8?q?=EB=AC=B4=20API=20=EC=97=B0=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/nuguTest/NuguTest.jsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pages/nuguTest/NuguTest.jsx b/src/pages/nuguTest/NuguTest.jsx index cc06656..f842c52 100644 --- a/src/pages/nuguTest/NuguTest.jsx +++ b/src/pages/nuguTest/NuguTest.jsx @@ -24,6 +24,7 @@ export const NuguTestPage = () => { try { const hasTest = await getNuguTestStatus(); //누구 테스트 사용자-get + console.log("hasTest :", hasTest); setIsMakeTest(hasTest); } catch (error) { console.error("실패", error); From acf230f947b60e9a91027472e32f583b4346fa0e Mon Sep 17 00:00:00 2001 From: sayyyho <323psh@naver.com> Date: Thu, 14 Nov 2024 11:39:22 +0900 Subject: [PATCH 2/8] =?UTF-8?q?[Fix]=20#41=20-=20=ED=97=A4=EB=8D=94?= =?UTF-8?q?=EC=97=90=20=EC=BF=A0=ED=82=A4=20=EC=A7=81=EC=A0=91=20=EC=82=BD?= =?UTF-8?q?=EC=9E=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/nuguTest.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/apis/nuguTest.js b/src/apis/nuguTest.js index 3ab36b7..9781961 100644 --- a/src/apis/nuguTest.js +++ b/src/apis/nuguTest.js @@ -1,15 +1,25 @@ import { instance } from "./instance"; +import Cookies from "js-cookie"; export const getNuguTestStatus = async () => { try { - const response = await instance.get("/tests/status"); - console.log(response); - if (response.data.hasTest) { - // TODO 수행한 인원 및 기타 작업 + const accessToken = Cookies.get("access_token"); + + if (!accessToken) { + console.error("토큰이 없습니다. 인증이 필요합니다."); + } + + const response = await instance.get("/tests/status", { + headers: { Authorization: `Bearer ${accessToken}` }, + }); + + if (response) { + console.log("테스트 상태 확인:", response); return true; } return false; } catch (err) { + console.error("테스트 상태 확인 중 오류가 발생했습니다:", err); throw err; } }; From 187b14be52764fb3224473852c744c7d5203fadc Mon Sep 17 00:00:00 2001 From: sayyyho <323psh@naver.com> Date: Thu, 14 Nov 2024 11:40:35 +0900 Subject: [PATCH 3/8] =?UTF-8?q?[Test]=20#41=20-=20=EC=9D=B8=ED=84=B0?= =?UTF-8?q?=EC=85=89=ED=84=B0=20=EC=9E=84=EC=8B=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/instance.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/apis/instance.js b/src/apis/instance.js index f15358f..bc9e637 100644 --- a/src/apis/instance.js +++ b/src/apis/instance.js @@ -9,16 +9,16 @@ export const instance = axios.create({ }, }); -instance.interceptors.request.use( - (config) => { - // config 매개변수를 받아옵니다. - const accessToken = Cookies.get("access_token"); - if (accessToken) { - config.headers["Authorization"] = `Bearer ${accessToken}`; - } - return config; - }, - () => { - console.log("토큰 없음"); - } -); +// instance.interceptors.request.use( +// (config) => { +// // config 매개변수를 받아옵니다. +// const accessToken = Cookies.get("access_token"); +// if (accessToken) { +// config.headers["Authorization"] = `Bearer ${accessToken}`; +// } +// return config; +// }, +// () => { +// console.log("토큰 없음"); +// } +// ); From 3568f786d0b420de21e46410254d9fb4e0046cf4 Mon Sep 17 00:00:00 2001 From: sayyyho <323psh@naver.com> Date: Thu, 14 Nov 2024 11:46:17 +0900 Subject: [PATCH 4/8] =?UTF-8?q?[Test]=20#41=20-=20=EB=88=84=EA=B5=AC?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20API=20=EC=97=B0=EB=8F=99=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/atoms/nuguTestState.js | 2 +- src/pages/nuguTest/NuguTest.jsx | 46 ++++++++++----------------------- 2 files changed, 14 insertions(+), 34 deletions(-) diff --git a/src/atoms/nuguTestState.js b/src/atoms/nuguTestState.js index 181305a..2366d12 100644 --- a/src/atoms/nuguTestState.js +++ b/src/atoms/nuguTestState.js @@ -2,5 +2,5 @@ import { atom } from "recoil"; export const isMakeTestOwner = atom({ key: "isMakeTestOwner", - default: "", + default: false, }); diff --git a/src/pages/nuguTest/NuguTest.jsx b/src/pages/nuguTest/NuguTest.jsx index f842c52..e6413cd 100644 --- a/src/pages/nuguTest/NuguTest.jsx +++ b/src/pages/nuguTest/NuguTest.jsx @@ -1,4 +1,3 @@ -//소유자뷰- 누구테스트 홈 import * as S from "./styled"; import { useEffect } from "react"; import { useNavigate } from "react-router-dom"; @@ -10,69 +9,50 @@ import { Button } from "@components/common/button/Button"; import { NuguTestTrue } from "@components/nuguTest/NuguTestTrue"; import { isMakeTestOwner } from "@atoms/nuguTestState"; import { useRecoilState } from "recoil"; - import { getNuguTestStatus } from "@apis/nuguTest"; import Cookies from "js-cookie"; -//토큰 여부로 워딩 다르게 표현 export const NuguTestPage = () => { const [isMakeTest, setIsMakeTest] = useRecoilState(isMakeTestOwner); const navigate = useNavigate(); - //test + + const sampleArray = []; // TODO - API 연동 후 + useEffect(() => { const fetchTestStatus = async () => { try { const hasTest = await getNuguTestStatus(); - //누구 테스트 사용자-get console.log("hasTest :", hasTest); - setIsMakeTest(hasTest); + // setIsMakeTest(hasTest); } catch (error) { console.error("실패", error); } - - fetchTestStatus(); }; - }, []); + + fetchTestStatus(); + }, [navigate]); const moveOnTest = () => { navigate("/test/make"); }; - const array = [ - // { - // nickname: "응시자3", - // correctAnswers: 9, - // rank: 1, - // totalParticipants: 3, - // }, - // { - // nickname: "응시자1", - // correctAnswers: 7, - // rank: 2, - // totalParticipants: 3, - // }, - // { - // nickname: "응시자2", - // correctAnswers: 7, - // rank: 2, - // totalParticipants: 3, - // }, - ]; - return ( {isMakeTest ? ( - array.length === 0 ? ( + sampleArray.length === 0 ? ( ) : ( - + ) ) : ( <> - From 4b2ec0be76ee624f0f60519d925ec102eaa68eeb Mon Sep 17 00:00:00 2001 From: sayyyho <323psh@naver.com> Date: Thu, 14 Nov 2024 12:01:28 +0900 Subject: [PATCH 5/8] =?UTF-8?q?[Test]=20#41=20-=20=EB=88=84=EA=B5=AC?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20API=20=EC=97=B0=EB=8F=99=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/nuguTest.js | 9 ++------- src/pages/nuguTest/NuguTest.jsx | 23 ++++++++++++++++------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/apis/nuguTest.js b/src/apis/nuguTest.js index 9781961..94b41f5 100644 --- a/src/apis/nuguTest.js +++ b/src/apis/nuguTest.js @@ -6,18 +6,13 @@ export const getNuguTestStatus = async () => { const accessToken = Cookies.get("access_token"); if (!accessToken) { - console.error("토큰이 없습니다. 인증이 필요합니다."); + console.log("세션 만료"); } const response = await instance.get("/tests/status", { headers: { Authorization: `Bearer ${accessToken}` }, }); - - if (response) { - console.log("테스트 상태 확인:", response); - return true; - } - return false; + return response.data; } catch (err) { console.error("테스트 상태 확인 중 오류가 발생했습니다:", err); throw err; diff --git a/src/pages/nuguTest/NuguTest.jsx b/src/pages/nuguTest/NuguTest.jsx index e6413cd..fb71dab 100644 --- a/src/pages/nuguTest/NuguTest.jsx +++ b/src/pages/nuguTest/NuguTest.jsx @@ -1,5 +1,5 @@ import * as S from "./styled"; -import { useEffect } from "react"; +import { useEffect, useState } from "react"; import { useNavigate } from "react-router-dom"; import { Layout } from "@components/common/layout/Layout"; import { NavigateBar } from "@components/common/navigateBar/NavigateBar"; @@ -14,16 +14,25 @@ import Cookies from "js-cookie"; export const NuguTestPage = () => { const [isMakeTest, setIsMakeTest] = useRecoilState(isMakeTestOwner); + const [participants, setParticipants] = useState(0); const navigate = useNavigate(); - const sampleArray = []; // TODO - API 연동 후 + const sampleArray = [ + { + nickname: "응시자1", + correctAnswers: 7, + rank: 1, + totalParticipants: 1, + }, + ]; useEffect(() => { const fetchTestStatus = async () => { try { - const hasTest = await getNuguTestStatus(); + const data = await getNuguTestStatus(); + setIsMakeTest(data.hasTest); + setParticipants(Number(data.totalParticipants)); console.log("hasTest :", hasTest); - // setIsMakeTest(hasTest); } catch (error) { console.error("실패", error); } @@ -41,12 +50,12 @@ export const NuguTestPage = () => { {isMakeTest ? ( - sampleArray.length === 0 ? ( + participants ? ( ) : ( ) ) : ( From f14233d5c720b776a5597c13af118d840de6aea9 Mon Sep 17 00:00:00 2001 From: sayyyho <323psh@naver.com> Date: Thu, 14 Nov 2024 12:06:06 +0900 Subject: [PATCH 6/8] =?UTF-8?q?[Fix]=20#41=20-=20=EB=A0=88=ED=8D=BC?= =?UTF-8?q?=EB=9F=B0=EC=8A=A4=20=EC=97=90=EB=9F=AC=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/nuguTest/NuguTest.jsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/nuguTest/NuguTest.jsx b/src/pages/nuguTest/NuguTest.jsx index fb71dab..b6b2e91 100644 --- a/src/pages/nuguTest/NuguTest.jsx +++ b/src/pages/nuguTest/NuguTest.jsx @@ -32,7 +32,6 @@ export const NuguTestPage = () => { const data = await getNuguTestStatus(); setIsMakeTest(data.hasTest); setParticipants(Number(data.totalParticipants)); - console.log("hasTest :", hasTest); } catch (error) { console.error("실패", error); } From 627a98640b31079412f8894d219734d5fd4e1aec Mon Sep 17 00:00:00 2001 From: sayyyho <323psh@naver.com> Date: Thu, 14 Nov 2024 12:10:33 +0900 Subject: [PATCH 7/8] =?UTF-8?q?[Test]=20#41=20-=20=EB=88=84=EA=B5=AC?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20API=20=EC=97=B0=EB=8F=99=20?= =?UTF-8?q?=ED=9B=84=20=EB=A0=8C=EB=8D=94=EB=A7=81=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/nuguTest/NuguTest.jsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pages/nuguTest/NuguTest.jsx b/src/pages/nuguTest/NuguTest.jsx index b6b2e91..5ad6ac7 100644 --- a/src/pages/nuguTest/NuguTest.jsx +++ b/src/pages/nuguTest/NuguTest.jsx @@ -38,7 +38,7 @@ export const NuguTestPage = () => { }; fetchTestStatus(); - }, [navigate]); + }, []); const moveOnTest = () => { navigate("/test/make"); @@ -49,12 +49,12 @@ export const NuguTestPage = () => { {isMakeTest ? ( - participants ? ( + participants === 0 ? ( ) : ( ) ) : ( From e6c9c2c804ce5c01e8644bff9ae5d11bee0306ba Mon Sep 17 00:00:00 2001 From: sayyyho <323psh@naver.com> Date: Thu, 14 Nov 2024 12:21:53 +0900 Subject: [PATCH 8/8] =?UTF-8?q?[Test]=20#41=20-=20=EB=88=84=EA=B5=AC?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EB=9E=AD=ED=82=B9=20API=20?= =?UTF-8?q?=EC=97=B0=EB=8F=99=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/instance.js | 26 ++++++++++++------------ src/apis/nuguTest.js | 20 +++++++++--------- src/components/nuguTest/NuguTestTrue.jsx | 20 +++++++++++++++++- src/pages/nuguTest/NuguTest.jsx | 14 +------------ 4 files changed, 43 insertions(+), 37 deletions(-) diff --git a/src/apis/instance.js b/src/apis/instance.js index bc9e637..f15358f 100644 --- a/src/apis/instance.js +++ b/src/apis/instance.js @@ -9,16 +9,16 @@ export const instance = axios.create({ }, }); -// instance.interceptors.request.use( -// (config) => { -// // config 매개변수를 받아옵니다. -// const accessToken = Cookies.get("access_token"); -// if (accessToken) { -// config.headers["Authorization"] = `Bearer ${accessToken}`; -// } -// return config; -// }, -// () => { -// console.log("토큰 없음"); -// } -// ); +instance.interceptors.request.use( + (config) => { + // config 매개변수를 받아옵니다. + const accessToken = Cookies.get("access_token"); + if (accessToken) { + config.headers["Authorization"] = `Bearer ${accessToken}`; + } + return config; + }, + () => { + console.log("토큰 없음"); + } +); diff --git a/src/apis/nuguTest.js b/src/apis/nuguTest.js index 94b41f5..18adca0 100644 --- a/src/apis/nuguTest.js +++ b/src/apis/nuguTest.js @@ -1,20 +1,20 @@ import { instance } from "./instance"; -import Cookies from "js-cookie"; export const getNuguTestStatus = async () => { try { - const accessToken = Cookies.get("access_token"); - - if (!accessToken) { - console.log("세션 만료"); - } - - const response = await instance.get("/tests/status", { - headers: { Authorization: `Bearer ${accessToken}` }, - }); + const response = await instance.get("/tests/status"); return response.data; } catch (err) { console.error("테스트 상태 확인 중 오류가 발생했습니다:", err); throw err; } }; + +export const getNuguTestRanking = async () => { + try { + const response = await instance.get("/test-results/rankings"); + return response.data; + } catch (err) { + console.log(err); + } +}; diff --git a/src/components/nuguTest/NuguTestTrue.jsx b/src/components/nuguTest/NuguTestTrue.jsx index 55c36f0..73cd20d 100644 --- a/src/components/nuguTest/NuguTestTrue.jsx +++ b/src/components/nuguTest/NuguTestTrue.jsx @@ -1,7 +1,25 @@ //소유자가 테스트를 만듦 & 테스트를 진행한 사람이 존재 import * as S from "./styled"; + +import { useEffect, useState } from "react"; + import { NuguTestRanking } from "@components/nuguTestRanking/NuguTestRanking"; -export const NuguTestTrue = ({ username, ranking }) => { + +import { getNuguTestRanking } from "@apis/nuguTest"; + +export const NuguTestTrue = ({ username }) => { + const [ranking, setRanking] = useState([]); + useEffect(() => { + const fetchRanking = async () => { + try { + const data = await getNuguTestRanking(); + setRanking(data); + } catch (err) { + console.log(err); + } + }; + fetchRanking(); + }, []); return ( diff --git a/src/pages/nuguTest/NuguTest.jsx b/src/pages/nuguTest/NuguTest.jsx index 5ad6ac7..0eb415d 100644 --- a/src/pages/nuguTest/NuguTest.jsx +++ b/src/pages/nuguTest/NuguTest.jsx @@ -17,15 +17,6 @@ export const NuguTestPage = () => { const [participants, setParticipants] = useState(0); const navigate = useNavigate(); - const sampleArray = [ - { - nickname: "응시자1", - correctAnswers: 7, - rank: 1, - totalParticipants: 1, - }, - ]; - useEffect(() => { const fetchTestStatus = async () => { try { @@ -52,10 +43,7 @@ export const NuguTestPage = () => { participants === 0 ? ( ) : ( - + ) ) : ( <>