From bb1170db2f143309948e5c318ef5162e6d494136 Mon Sep 17 00:00:00 2001 From: NamKyeongMin Date: Fri, 23 May 2025 15:09:57 +0900 Subject: [PATCH] =?UTF-8?q?[fix]:=20=EC=88=98=EA=B0=95=EC=83=9D=20?= =?UTF-8?q?=EB=94=94=ED=85=8C=EC=9D=BC=20=ED=8E=98=EC=9D=B4=EC=A7=80=20->?= =?UTF-8?q?=20=EA=B3=BC=EC=A0=9C=ED=99=95=EC=9D=B8=20=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=20api=20=EB=84=98=EA=B9=80=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pages/admin/AdminStudentAssignment.jsx | 57 ++++++++++++------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/frontend/src/pages/admin/AdminStudentAssignment.jsx b/frontend/src/pages/admin/AdminStudentAssignment.jsx index 9424ca7..edc9d88 100644 --- a/frontend/src/pages/admin/AdminStudentAssignment.jsx +++ b/frontend/src/pages/admin/AdminStudentAssignment.jsx @@ -5,7 +5,10 @@ import WeeklyOpenBlock from "../../components/WeeklyOpenBlock"; import AssignmentInfoBlock from "../../components/AssignmentInfoBlock"; import api from "../../api/api"; import styles from "./AdminStudentAssignment.module.css"; -import { submitAssignmentStatus, updateAssignmentStatus } from "../../api/assignment"; +import { + submitAssignmentStatus, + updateAssignmentStatus, +} from "../../api/assignment"; const AdminStudentAssignment = () => { const { studentId, week } = useParams(); @@ -15,7 +18,8 @@ const AdminStudentAssignment = () => { const [selectedWeekLabel, setSelectedWeekLabel] = useState(null); useEffect(() => { - api.get(`/admin/users/${userId}`).then((res) => { + // 기존 (오류 발생) api.get(`/admin/users/${userId}`).then((res) => { + api.get(`/admin/users/${studentId}`).then((res) => { setStudentInfo(res.data.data); }); @@ -63,7 +67,7 @@ const AdminStudentAssignment = () => { task.modified = true; setWeeks(updated); }; -/* + /* const handleSave = async (taskId, status) => { await api.put("/admin/assignment/status", { assignmentId: taskId, @@ -71,30 +75,32 @@ const AdminStudentAssignment = () => { }); }; */ -const handleSave = async (taskId, status) => { - const userId = parseInt(studentId); // 문자열일 수 있으니 숫자로 변환 + const handleSave = async (taskId, status) => { + const userId = parseInt(studentId); // 문자열일 수 있으니 숫자로 변환 - try { - // PUT 요청 시도 (기존 과제 수정) - await updateAssignmentStatus(userId, taskId, status); - alert("과제 상태가 수정되었습니다."); - } catch (err) { - console.warn("PUT 실패, POST 시도"); try { - // 없으면 POST 요청 (새 과제 등록) - await submitAssignmentStatus(userId, taskId, status); - alert("과제 상태가 등록되었습니다."); + // PUT 요청 시도 (기존 과제 수정) + await updateAssignmentStatus(userId, taskId, status); + alert("과제 상태가 수정되었습니다."); } catch (err) { - alert("상태 저장 실패"); - console.error(err); + console.warn("PUT 실패, POST 시도"); + try { + // 없으면 POST 요청 (새 과제 등록) + await submitAssignmentStatus(userId, taskId, status); + alert("과제 상태가 등록되었습니다."); + } catch (err) { + alert("상태 저장 실패"); + console.error(err); + } } - } -}; + }; return (
window.history.back()} /> @@ -110,14 +116,23 @@ const handleSave = async (taskId, status) => {

{weekItem.label}

{weekItem.days.map((dayItem, dayIdx) => (
-

{dayItem.day}   {dayItem.subject}

+

+ {dayItem.day}   {dayItem.subject} +

{dayItem.tasks.map((task, taskIdx) => (
{task.label}