diff --git a/backend/routes/schedules.js b/backend/routes/schedules.js index 170758b..f3e4ba9 100644 --- a/backend/routes/schedules.js +++ b/backend/routes/schedules.js @@ -7,7 +7,7 @@ const router = express.Router(); // 공개 일정 목록 조회 (검색 포함) router.get("/", async (req, res) => { try { - const { search, startDate, endDate, limit } = req.query; + const { search, startDate, endDate, limit, year, month } = req.query; // 검색어가 있으면 Meilisearch 사용 if (search && search.trim()) { @@ -30,6 +30,15 @@ router.get("/", async (req, res) => { let whereClause = "WHERE 1=1"; const params = []; + // 년/월 필터링 (월별 데이터 로딩용) + if (year && month) { + whereClause += " AND YEAR(s.date) = ? AND MONTH(s.date) = ?"; + params.push(parseInt(year), parseInt(month)); + } else if (year) { + whereClause += " AND YEAR(s.date) = ?"; + params.push(parseInt(year)); + } + if (startDate) { whereClause += " AND s.date >= ?"; params.push(startDate); diff --git a/frontend/src/pages/pc/Schedule.jsx b/frontend/src/pages/pc/Schedule.jsx index 94894a3..9a66a65 100644 --- a/frontend/src/pages/pc/Schedule.jsx +++ b/frontend/src/pages/pc/Schedule.jsx @@ -82,14 +82,22 @@ function Schedule() { }, [inView, hasNextPage, isFetchingNextPage, fetchNextPage, isSearchMode, searchTerm]); // 데이터 로드 + // 초기 데이터 로드 (카테고리만) useEffect(() => { - fetchSchedules(); fetchCategories(); }, []); + + // 월 변경 시 일정 로드 + useEffect(() => { + const year = currentDate.getFullYear(); + const month = currentDate.getMonth(); + fetchSchedules(year, month + 1); + }, [currentDate]); - const fetchSchedules = async () => { + const fetchSchedules = async (year, month) => { + setLoading(true); try { - const response = await fetch('/api/schedules'); + const response = await fetch(`/api/schedules?year=${year}&month=${month}`); if (response.ok) { const data = await response.json(); setSchedules(data);