fix: API URL 하드코딩 문제 해결 및 API 통합 개선

- API URL 생성 로직에서 localhost 환경 감지 개선
- 모든 페이지에서 하드코딩된 API URL 제거
- ManagementAPI, InboxAPI 추가로 API 호출 통합
- ProjectsAPI 사용으로 프로젝트 로드 통일
- permissions.js에서 API URL 동적 생성 적용
This commit is contained in:
hyungi
2025-11-08 15:34:37 +09:00
parent 637b690eda
commit 1299ac261c
6 changed files with 111 additions and 118 deletions

View File

@@ -472,66 +472,41 @@
// 프로젝트 로드
async function loadProjects() {
try {
const apiUrl = window.API_BASE_URL || 'http://localhost:16080/api';
const response = await fetch(`${apiUrl}/projects/`, {
headers: {
'Authorization': `Bearer ${localStorage.getItem('access_token')}`,
'Content-Type': 'application/json'
}
});
if (response.ok) {
projects = await response.json();
updateProjectFilter();
}
// ProjectsAPI 사용 (모든 프로젝트 로드)
projects = await ProjectsAPI.getAll(false);
updateProjectFilter();
} catch (error) {
console.error('프로젝트 로드 실패:', error);
}
}
// 부적합 목록 로드 (관리자는 모든 부적합 조회)
// 부적합 목록 로드 (관리함 API 사용)
async function loadIssues() {
try {
let endpoint = '/api/issues/admin/all';
// ManagementAPI 사용
const managementIssues = await ManagementAPI.getAll();
const response = await fetch(endpoint, {
headers: {
'Authorization': `Bearer ${localStorage.getItem('access_token')}`,
'Content-Type': 'application/json'
// 수신함에서 넘어온 순서대로 No. 재할당 (reviewed_at 기준)
managementIssues.sort((a, b) => new Date(a.reviewed_at) - new Date(b.reviewed_at));
// 프로젝트별로 그룹화하여 No. 재할당
const projectGroups = {};
managementIssues.forEach(issue => {
if (!projectGroups[issue.project_id]) {
projectGroups[issue.project_id] = [];
}
projectGroups[issue.project_id].push(issue);
});
if (response.ok) {
const allIssues = await response.json();
// 관리함에서는 진행 중(in_progress)과 완료됨(completed) 상태만 표시
let filteredIssues = allIssues.filter(issue =>
issue.review_status === 'in_progress' || issue.review_status === 'completed'
);
// 수신함에서 넘어온 순서대로 No. 재할당 (reviewed_at 기준)
filteredIssues.sort((a, b) => new Date(a.reviewed_at) - new Date(b.reviewed_at));
// 프로젝트별로 그룹화하여 No. 재할당
const projectGroups = {};
filteredIssues.forEach(issue => {
if (!projectGroups[issue.project_id]) {
projectGroups[issue.project_id] = [];
}
projectGroups[issue.project_id].push(issue);
// 각 프로젝트별로 순번 재할당
Object.keys(projectGroups).forEach(projectId => {
projectGroups[projectId].forEach((issue, index) => {
issue.project_sequence_no = index + 1;
});
// 각 프로젝트별로 순번 재할당
Object.keys(projectGroups).forEach(projectId => {
projectGroups[projectId].forEach((issue, index) => {
issue.project_sequence_no = index + 1;
});
});
issues = filteredIssues;
filterIssues();
} else {
throw new Error('부적합 목록을 불러올 수 없습니다.');
}
});
issues = managementIssues;
filterIssues();
} catch (error) {
console.error('부적합 로드 실패:', error);
alert('부적합 목록을 불러오는데 실패했습니다.');