refactor: API 중앙화 마무리 (3/3)

- api/public/ import 경로 ../index로 수정
- schedules.js에 getUpcomingSchedules 함수 추가
- Home.jsx API 모듈 적용
This commit is contained in:
caadiq 2026-01-09 22:02:04 +09:00
parent e994aa08ca
commit 20f496ca24
4 changed files with 14 additions and 10 deletions

View file

@ -1,7 +1,7 @@
/** /**
* 앨범 관련 공개 API * 앨범 관련 공개 API
*/ */
import { fetchApi } from "./index"; import { fetchApi } from "../index";
// 앨범 목록 조회 // 앨범 목록 조회
export async function getAlbums() { export async function getAlbums() {

View file

@ -1,7 +1,7 @@
/** /**
* 멤버 관련 공개 API * 멤버 관련 공개 API
*/ */
import { fetchApi } from "./index"; import { fetchApi } from "../index";
// 멤버 목록 조회 // 멤버 목록 조회
export async function getMembers() { export async function getMembers() {

View file

@ -1,13 +1,20 @@
/** /**
* 일정 관련 공개 API * 일정 관련 공개 API
*/ */
import { fetchApi } from "./index"; import { fetchApi } from "../index";
import { getTodayKST } from "../../utils/date";
// 일정 목록 조회 (월별) // 일정 목록 조회 (월별)
export async function getSchedules(year, month) { export async function getSchedules(year, month) {
return fetchApi(`/api/schedules?year=${year}&month=${month}`); return fetchApi(`/api/schedules?year=${year}&month=${month}`);
} }
// 다가오는 일정 조회 (오늘 이후)
export async function getUpcomingSchedules(limit = 3) {
const todayStr = getTodayKST();
return fetchApi(`/api/schedules?startDate=${todayStr}&limit=${limit}`);
}
// 일정 검색 (Meilisearch) // 일정 검색 (Meilisearch)
export async function searchSchedules(query, { offset = 0, limit = 20 } = {}) { export async function searchSchedules(query, { offset = 0, limit = 20 } = {}) {
return fetchApi( return fetchApi(

View file

@ -3,6 +3,8 @@ import { motion } from 'framer-motion';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import { Calendar, ArrowRight, Clock, Link2, Tag } from 'lucide-react'; import { Calendar, ArrowRight, Clock, Link2, Tag } from 'lucide-react';
import { getTodayKST } from '../../../utils/date'; import { getTodayKST } from '../../../utils/date';
import { getMembers } from '../../../api/public/members';
import { getUpcomingSchedules } from '../../../api/public/schedules';
function Home() { function Home() {
const [members, setMembers] = useState([]); const [members, setMembers] = useState([]);
@ -10,17 +12,12 @@ function Home() {
useEffect(() => { useEffect(() => {
// //
fetch('/api/members') getMembers()
.then(res => res.json())
.then(data => setMembers(data)) .then(data => setMembers(data))
.catch(error => console.error('멤버 데이터 로드 오류:', error)); .catch(error => console.error('멤버 데이터 로드 오류:', error));
// ( 3) // ( 3)
const todayStr = getTodayKST(); getUpcomingSchedules(3)
fetch(`/api/schedules?startDate=${todayStr}&limit=3`)
.then(res => res.json())
.then(data => setUpcomingSchedules(data)) .then(data => setUpcomingSchedules(data))
.catch(error => console.error('일정 데이터 로드 오류:', error)); .catch(error => console.error('일정 데이터 로드 오류:', error));
}, []); }, []);