From 361e6f701dc472907be4156bf69305b176f9a1f6 Mon Sep 17 00:00:00 2001 From: Haemin Kim Date: Sat, 11 Oct 2025 17:44:03 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9C=A8=20(#348)=20=EA=B0=95=EC=9D=98=20?= =?UTF-8?q?=EC=83=81=EC=84=B8=20=EC=A7=88=EB=AC=B8=20=EB=AA=A9=EB=A1=9D=20?= =?UTF-8?q?API=20=EC=97=B0=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/api/lectures/fetchQuestions.ts | 19 ++++++++++ .../_components/QuestionList/QuestionList.tsx | 38 +++++++++++++++++-- frontend/constants/endpoints.ts | 4 +- .../types/lectures/fetchQuestionsTypes.ts | 7 ++++ 4 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 frontend/api/lectures/fetchQuestions.ts create mode 100644 frontend/types/lectures/fetchQuestionsTypes.ts diff --git a/frontend/api/lectures/fetchQuestions.ts b/frontend/api/lectures/fetchQuestions.ts new file mode 100644 index 00000000..1fad3096 --- /dev/null +++ b/frontend/api/lectures/fetchQuestions.ts @@ -0,0 +1,19 @@ +import { axiosInstance } from "@/api/axiosInstance"; +import axios from "axios"; +import { ENDPOINTS } from "@/constants/endpoints"; +import { ApiResponse } from "@/types/apiResponseTypes"; +import { FetchQuestionsResult } from "@/types/lectures/fetchQuestionsTypes"; + +export async function fetchQuestions(lectureId: string) { + try { + const response = await axiosInstance.get< + ApiResponse + >(ENDPOINTS.LECTURES.GET_CHAT(lectureId)); + return response.data; + } catch (error: unknown) { + if (axios.isAxiosError(error) && error.response) { + return error.response.data as ApiResponse; + } + throw error; + } +} diff --git a/frontend/app/teacher/lecture-detail/[lectureId]/_components/QuestionList/QuestionList.tsx b/frontend/app/teacher/lecture-detail/[lectureId]/_components/QuestionList/QuestionList.tsx index 8dc06ff5..ec4b9a6f 100644 --- a/frontend/app/teacher/lecture-detail/[lectureId]/_components/QuestionList/QuestionList.tsx +++ b/frontend/app/teacher/lecture-detail/[lectureId]/_components/QuestionList/QuestionList.tsx @@ -5,6 +5,8 @@ import { useEffect, useState } from "react"; import Image from "next/image"; import { IMAGES } from "@/constants/images"; import { useLectureDetail } from "../LectureDetailContext"; +import { FetchQuestionsResult } from "@/types/lectures/fetchQuestionsTypes"; +import { fetchQuestions } from "@/api/lectures/fetchQuestions"; export interface Question { sender: string; @@ -19,11 +21,41 @@ export default function QuestionList() { const [loading, setLoading] = useState(true); useEffect(() => { - // TODO: API 호출로 변경 - setQuestions([]); - setLoading(false); + let alive = true; + + const load = async () => { + setLoading(true); + + try { + const res = await fetchQuestions(lectureId); + if (!alive) return; + + const list = (res.result ?? []) as FetchQuestionsResult[]; + + const mapped: Question[] = list.map((q) => ({ + sender: q.studentName, + message: q.content, + timestamp: q.timestamp, + profileUrl: q.studentProfile ?? "", + })) + .sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime()); + + setQuestions(mapped); + } catch (e) { + if (!alive) return; + setQuestions([]); + } finally { + if (alive) setLoading(false); + } + }; + + load(); + return () => { + alive = false; + }; }, [lectureId]); + const formatTimestamp = (timestamp: string) => { try { const date = new Date(timestamp); diff --git a/frontend/constants/endpoints.ts b/frontend/constants/endpoints.ts index a21129e7..6cbd4f92 100644 --- a/frontend/constants/endpoints.ts +++ b/frontend/constants/endpoints.ts @@ -99,9 +99,9 @@ export const ENDPOINTS = { SAVE_CHAT: (lectureId: string) => `${BASE_API}/lectures/${lectureId}/chating`, GET_CHAT: (lectureId: string) => - `${BASE_API}/lectures/${lectureId}/chating`, + `${BASE_API}/lectures/${lectureId}/questions`, }, - + // 퀴즈 관련 QUIZZES: { CREATE: (lectureId: string) => `${BASE_API}/quizzes/${lectureId}/create`, diff --git a/frontend/types/lectures/fetchQuestionsTypes.ts b/frontend/types/lectures/fetchQuestionsTypes.ts new file mode 100644 index 00000000..594fd55c --- /dev/null +++ b/frontend/types/lectures/fetchQuestionsTypes.ts @@ -0,0 +1,7 @@ +export interface FetchQuestionsResult { + studentId: string; + studentName: string; + studentProfile: string | null; + timestamp: string; + content: string; +} From 347d6c627f7d9367ce87d29b5b340617df2f7f80 Mon Sep 17 00:00:00 2001 From: Haemin Kim Date: Sat, 11 Oct 2025 17:46:26 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=92=84=20(#348)=20questionHeader=20?= =?UTF-8?q?=ED=95=98=EB=8B=A8=20=EB=A7=88=EC=A7=84=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../_components/QuestionList/QuestionList.module.scss | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/app/teacher/lecture-detail/[lectureId]/_components/QuestionList/QuestionList.module.scss b/frontend/app/teacher/lecture-detail/[lectureId]/_components/QuestionList/QuestionList.module.scss index 2a78c240..8fe868b5 100644 --- a/frontend/app/teacher/lecture-detail/[lectureId]/_components/QuestionList/QuestionList.module.scss +++ b/frontend/app/teacher/lecture-detail/[lectureId]/_components/QuestionList/QuestionList.module.scss @@ -32,7 +32,6 @@ display: flex; justify-content: space-between; align-items: center; - margin-bottom: $spacing-xs; } .userInfo { From 815fda39bfb3d566c7adeb4891ce42b500bae840 Mon Sep 17 00:00:00 2001 From: Haemin Kim Date: Sat, 11 Oct 2025 17:57:31 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=94=A5=20(#348)=20=EC=95=88=20?= =?UTF-8?q?=EC=93=B0=EB=8A=94=20e=20=EB=B3=80=EC=88=98=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../[lectureId]/_components/QuestionList/QuestionList.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/app/teacher/lecture-detail/[lectureId]/_components/QuestionList/QuestionList.tsx b/frontend/app/teacher/lecture-detail/[lectureId]/_components/QuestionList/QuestionList.tsx index ec4b9a6f..4c0bc03d 100644 --- a/frontend/app/teacher/lecture-detail/[lectureId]/_components/QuestionList/QuestionList.tsx +++ b/frontend/app/teacher/lecture-detail/[lectureId]/_components/QuestionList/QuestionList.tsx @@ -41,7 +41,7 @@ export default function QuestionList() { .sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime()); setQuestions(mapped); - } catch (e) { + } catch { if (!alive) return; setQuestions([]); } finally {