fromis_9/frontend/src/api/public/schedules.js

52 lines
1.4 KiB
JavaScript
Raw Normal View History

/**
* 일정 관련 공개 API
*/
import { fetchApi } from "../index";
import { getTodayKST } from "../../utils/date";
// 일정 목록 조회 (월별)
export async function getSchedules(year, month) {
const data = await fetchApi(`/api/schedules?year=${year}&month=${month}`);
// 날짜별 그룹화된 응답을 플랫 배열로 변환
const schedules = [];
for (const [date, dayData] of Object.entries(data)) {
for (const schedule of dayData.schedules) {
const category = schedule.category || {};
schedules.push({
...schedule,
date,
category_id: category.id,
category_name: category.name,
category_color: category.color,
});
}
}
return schedules;
}
// 다가오는 일정 조회 (오늘 이후)
export async function getUpcomingSchedules(limit = 3) {
const todayStr = getTodayKST();
return fetchApi(`/api/schedules?startDate=${todayStr}&limit=${limit}`);
}
// 일정 검색 (Meilisearch)
export async function searchSchedules(query, { offset = 0, limit = 20 } = {}) {
return fetchApi(
`/api/schedules?search=${encodeURIComponent(
query
)}&offset=${offset}&limit=${limit}`
);
}
// 일정 상세 조회
export async function getSchedule(id) {
return fetchApi(`/api/schedules/${id}`);
}
// X 프로필 정보 조회
export async function getXProfile(username) {
return fetchApi(`/api/schedules/x-profile/${encodeURIComponent(username)}`);
}