refactor(frontend-temp): 스케줄 API도 새 형식에 맞게 업데이트
- flattenScheduleResponse → transformSchedule 함수로 변경 - 새 API 형식(schedules 배열, datetime, category 객체) 지원 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
3922d5c6f7
commit
b64710c8fd
1 changed files with 36 additions and 19 deletions
|
|
@ -5,24 +5,37 @@ import { fetchApi, fetchAuthApi, fetchFormData } from './client';
|
||||||
import { getTodayKST } from '@/utils';
|
import { getTodayKST } from '@/utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API 응답을 플랫 배열로 변환
|
* API 응답을 프론트엔드 형식으로 변환
|
||||||
* 백엔드가 날짜별 그룹화된 객체를 반환하므로 변환 필요
|
* - datetime → date, time 분리
|
||||||
|
* - category 객체 → category_id, category_name, category_color 플랫화
|
||||||
|
* - members 배열 → member_names 문자열
|
||||||
*/
|
*/
|
||||||
function flattenScheduleResponse(data) {
|
function transformSchedule(schedule) {
|
||||||
const schedules = [];
|
|
||||||
for (const [date, dayData] of Object.entries(data)) {
|
|
||||||
for (const schedule of dayData.schedules || []) {
|
|
||||||
const category = schedule.category || {};
|
const category = schedule.category || {};
|
||||||
schedules.push({
|
|
||||||
|
// datetime에서 date와 time 분리
|
||||||
|
let date = '';
|
||||||
|
let time = null;
|
||||||
|
if (schedule.datetime) {
|
||||||
|
const parts = schedule.datetime.split('T');
|
||||||
|
date = parts[0];
|
||||||
|
time = parts[1] || null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// members 배열을 문자열로 (기존 코드 호환성)
|
||||||
|
const memberNames = Array.isArray(schedule.members)
|
||||||
|
? schedule.members.join(',')
|
||||||
|
: '';
|
||||||
|
|
||||||
|
return {
|
||||||
...schedule,
|
...schedule,
|
||||||
date,
|
date,
|
||||||
|
time,
|
||||||
category_id: category.id,
|
category_id: category.id,
|
||||||
category_name: category.name,
|
category_name: category.name,
|
||||||
category_color: category.color,
|
category_color: category.color,
|
||||||
});
|
member_names: memberNames,
|
||||||
}
|
};
|
||||||
}
|
|
||||||
return schedules;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==================== 공개 API ====================
|
// ==================== 공개 API ====================
|
||||||
|
|
@ -32,7 +45,7 @@ function flattenScheduleResponse(data) {
|
||||||
*/
|
*/
|
||||||
export async function getSchedules(year, month) {
|
export async function getSchedules(year, month) {
|
||||||
const data = await fetchApi(`/schedules?year=${year}&month=${month}`);
|
const data = await fetchApi(`/schedules?year=${year}&month=${month}`);
|
||||||
return flattenScheduleResponse(data);
|
return (data.schedules || []).map(transformSchedule);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -41,16 +54,20 @@ export async function getSchedules(year, month) {
|
||||||
export async function getUpcomingSchedules(limit = 3) {
|
export async function getUpcomingSchedules(limit = 3) {
|
||||||
const today = getTodayKST();
|
const today = getTodayKST();
|
||||||
const data = await fetchApi(`/schedules?startDate=${today}&limit=${limit}`);
|
const data = await fetchApi(`/schedules?startDate=${today}&limit=${limit}`);
|
||||||
return flattenScheduleResponse(data);
|
return (data.schedules || []).map(transformSchedule);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 스케줄 검색 (Meilisearch)
|
* 스케줄 검색 (Meilisearch)
|
||||||
*/
|
*/
|
||||||
export async function searchSchedules(query, { offset = 0, limit = 20 } = {}) {
|
export async function searchSchedules(query, { offset = 0, limit = 20 } = {}) {
|
||||||
return fetchApi(
|
const data = await fetchApi(
|
||||||
`/schedules?search=${encodeURIComponent(query)}&offset=${offset}&limit=${limit}`
|
`/schedules?search=${encodeURIComponent(query)}&offset=${offset}&limit=${limit}`
|
||||||
);
|
);
|
||||||
|
return {
|
||||||
|
...data,
|
||||||
|
schedules: (data.schedules || []).map(transformSchedule),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue