api link to page
This commit is contained in:
@@ -42,33 +42,9 @@ export default function CourseRegistrationModal({ open, onClose, onSave, onDelet
|
||||
|
||||
setIsLoadingInstructors(true);
|
||||
try {
|
||||
const token = localStorage.getItem('token') || document.cookie
|
||||
.split('; ')
|
||||
.find(row => row.startsWith('token='))
|
||||
?.split('=')[1];
|
||||
|
||||
// 외부 API 호출
|
||||
const baseUrl = process.env.NEXT_PUBLIC_API_BASE_URL
|
||||
? `${process.env.NEXT_PUBLIC_API_BASE_URL}/admin/users/compact`
|
||||
: 'https://hrdi.coconutmeet.net/admin/users/compact';
|
||||
|
||||
// 쿼리 파라미터 추가: type=ADMIN
|
||||
const apiUrl = new URL(baseUrl);
|
||||
apiUrl.searchParams.set('type', 'ADMIN');
|
||||
|
||||
const response = await fetch(apiUrl.toString(), {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...(token && { Authorization: `Bearer ${token}` }),
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`강사 목록을 가져오는데 실패했습니다. (${response.status})`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
const response = await apiService.getUsersCompact();
|
||||
const data = response.data;
|
||||
|
||||
// API 응답이 배열이 아닌 경우 처리 (예: { items: [...] } 형태)
|
||||
let usersArray: any[] = [];
|
||||
@@ -293,15 +269,6 @@ export default function CourseRegistrationModal({ open, onClose, onSave, onDelet
|
||||
}
|
||||
}
|
||||
|
||||
const token = localStorage.getItem('token') || document.cookie
|
||||
.split('; ')
|
||||
.find(row => row.startsWith('token='))
|
||||
?.split('=')[1];
|
||||
|
||||
const baseUrl = process.env.NEXT_PUBLIC_API_BASE_URL
|
||||
? process.env.NEXT_PUBLIC_API_BASE_URL
|
||||
: 'https://hrdi.coconutmeet.net';
|
||||
|
||||
const requestBody: {
|
||||
title: string;
|
||||
instructor: string;
|
||||
@@ -354,52 +321,24 @@ export default function CourseRegistrationModal({ open, onClose, onSave, onDelet
|
||||
}
|
||||
} else {
|
||||
// 등록 모드: POST /subjects
|
||||
const response = await fetch(`${baseUrl}/subjects`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...(token && { Authorization: `Bearer ${token}` }),
|
||||
},
|
||||
body: JSON.stringify(requestBody),
|
||||
});
|
||||
try {
|
||||
await apiService.createSubject({
|
||||
courseName: courseName.trim(),
|
||||
instructorName: selectedInstructor.name,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
let errorMessage = `과목 등록 실패 (${response.status})`;
|
||||
try {
|
||||
const errorData = await response.json();
|
||||
if (errorData.error) {
|
||||
errorMessage = errorData.error;
|
||||
} else if (errorData.message) {
|
||||
errorMessage = errorData.message;
|
||||
}
|
||||
} catch (parseError) {
|
||||
// JSON 파싱 실패 시 기본 메시지 사용
|
||||
// 성공 시 onSave 콜백 호출 및 모달 닫기
|
||||
if (onSave && selectedInstructor) {
|
||||
onSave(courseName.trim(), selectedInstructor.name);
|
||||
}
|
||||
onClose(); // 모달 닫기
|
||||
} catch (createError) {
|
||||
const errorMessage = createError instanceof Error ? createError.message : '과목 등록 중 오류가 발생했습니다.';
|
||||
console.error('과목 등록 실패:', errorMessage);
|
||||
setErrors({ submit: errorMessage });
|
||||
setIsSaving(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// 응답에서 id 추출하여 저장
|
||||
try {
|
||||
const responseData = await response.json();
|
||||
|
||||
// 응답에서 id 추출 (다양한 가능한 필드명 확인)
|
||||
const subjectId = responseData.id
|
||||
|| responseData.data?.id
|
||||
|| responseData.subjectId
|
||||
|| responseData.data?.subjectId
|
||||
|| null;
|
||||
} catch (parseError) {
|
||||
// 응답 파싱 실패 시 무시
|
||||
}
|
||||
|
||||
// 성공 시 onSave 콜백 호출 및 모달 닫기
|
||||
if (onSave && selectedInstructor) {
|
||||
onSave(courseName.trim(), selectedInstructor.name);
|
||||
}
|
||||
onClose(); // 모달 닫기
|
||||
}
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : '네트워크 오류가 발생했습니다.';
|
||||
|
||||
Reference in New Issue
Block a user