Skip to content

Commit 62eda52

Browse files
authored
Merge pull request #350 from KW-ClassLog/Feat/#348/lecture-question-list
✨ Feat/#348 강의 상제 페이지 질문 목록 API 연동
2 parents dba1fb1 + 77c9505 commit 62eda52

File tree

5 files changed

+63
-6
lines changed

5 files changed

+63
-6
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { axiosInstance } from "@/api/axiosInstance";
2+
import axios from "axios";
3+
import { ENDPOINTS } from "@/constants/endpoints";
4+
import { ApiResponse } from "@/types/apiResponseTypes";
5+
import { FetchQuestionsResult } from "@/types/lectures/fetchQuestionsTypes";
6+
7+
export async function fetchQuestions(lectureId: string) {
8+
try {
9+
const response = await axiosInstance.get<
10+
ApiResponse<FetchQuestionsResult>
11+
>(ENDPOINTS.LECTURES.GET_CHAT(lectureId));
12+
return response.data;
13+
} catch (error: unknown) {
14+
if (axios.isAxiosError(error) && error.response) {
15+
return error.response.data as ApiResponse<FetchQuestionsResult>;
16+
}
17+
throw error;
18+
}
19+
}

frontend/app/teacher/lecture-detail/[lectureId]/_components/QuestionList/QuestionList.module.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
display: flex;
3333
justify-content: space-between;
3434
align-items: center;
35-
margin-bottom: $spacing-xs;
3635
}
3736

3837
.userInfo {

frontend/app/teacher/lecture-detail/[lectureId]/_components/QuestionList/QuestionList.tsx

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { useEffect, useState } from "react";
55
import Image from "next/image";
66
import { IMAGES } from "@/constants/images";
77
import { useLectureDetail } from "../LectureDetailContext";
8+
import { FetchQuestionsResult } from "@/types/lectures/fetchQuestionsTypes";
9+
import { fetchQuestions } from "@/api/lectures/fetchQuestions";
810

911
export interface Question {
1012
sender: string;
@@ -19,11 +21,41 @@ export default function QuestionList() {
1921
const [loading, setLoading] = useState(true);
2022

2123
useEffect(() => {
22-
// TODO: API 호출로 변경
23-
setQuestions([]);
24-
setLoading(false);
24+
let alive = true;
25+
26+
const load = async () => {
27+
setLoading(true);
28+
29+
try {
30+
const res = await fetchQuestions(lectureId);
31+
if (!alive) return;
32+
33+
const list = (res.result ?? []) as FetchQuestionsResult[];
34+
35+
const mapped: Question[] = list.map((q) => ({
36+
sender: q.studentName,
37+
message: q.content,
38+
timestamp: q.timestamp,
39+
profileUrl: q.studentProfile ?? "",
40+
}))
41+
.sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime());
42+
43+
setQuestions(mapped);
44+
} catch {
45+
if (!alive) return;
46+
setQuestions([]);
47+
} finally {
48+
if (alive) setLoading(false);
49+
}
50+
};
51+
52+
load();
53+
return () => {
54+
alive = false;
55+
};
2556
}, [lectureId]);
2657

58+
2759
const formatTimestamp = (timestamp: string) => {
2860
try {
2961
const date = new Date(timestamp);

frontend/constants/endpoints.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@ export const ENDPOINTS = {
9595
`${BASE_API}/lectures/${lectureId}/recordings`,
9696
GET_RECORDING: (lectureId: string) =>
9797
`${BASE_API}/lectures/${lectureId}/recordings`,
98-
98+
9999
// 채팅 관련
100100
SAVE_CHAT: (lectureId: string) =>
101101
`${BASE_API}/lectures/chatting/after/${lectureId}`,
102102
GET_CHAT: (lectureId: string) =>
103-
`${BASE_API}/lectures/${lectureId}/chatting`,
103+
`${BASE_API}/lectures/${lectureId}/questions`,
104104
},
105105

106106
// 퀴즈 관련
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export interface FetchQuestionsResult {
2+
studentId: string;
3+
studentName: string;
4+
studentProfile: string | null;
5+
timestamp: string;
6+
content: string;
7+
}

0 commit comments

Comments
 (0)