fromis_9/backend/routes/schedules.js
caadiq 52332babea 일정 관리 기능 개선: 봇 스케줄러 리팩토링, 멤버 표시, UI 개선
- 봇 스케줄러: 서버 시작 시 자동 초기화, 10초 간격 상태 동기화
- DB 리팩토링: bots 테이블에서 YouTube 컬럼 분리, bot_youtube_config 활용
- 봇별 커스텀 설정: BOT_CUSTOM_CONFIG 상수로 코드 내 관리
- 공개/관리자 일정 목록에 멤버 태그 표시 (5명 이상이면 '프로미스나인')
- 일정 목록 글씨 크기 증가 및 UI 개선
- source_name 관리자 일정에 뱃지로 표시
- 봇 시작/정지 토스트에 봇 이름 포함
2026-01-06 00:27:35 +09:00

83 lines
2.1 KiB
JavaScript

import express from "express";
import pool from "../lib/db.js";
const router = express.Router();
// 공개 일정 목록 조회
router.get("/", async (req, res) => {
try {
const [schedules] = await pool.query(`
SELECT
s.id,
s.title,
s.description,
s.date,
s.time,
s.category_id,
s.source_url,
s.source_name,
s.location_name,
c.name as category_name,
c.color as category_color,
GROUP_CONCAT(m.name ORDER BY m.id SEPARATOR ',') as member_names
FROM schedules s
LEFT JOIN schedule_categories c ON s.category_id = c.id
LEFT JOIN schedule_members sm ON s.id = sm.schedule_id
LEFT JOIN members m ON sm.member_id = m.id
GROUP BY s.id
ORDER BY s.date DESC, s.time DESC
`);
res.json(schedules);
} catch (error) {
console.error("일정 목록 조회 오류:", error);
res.status(500).json({ error: "일정 목록 조회 중 오류가 발생했습니다." });
}
});
// 카테고리 목록 조회
router.get("/categories", async (req, res) => {
try {
const [categories] = await pool.query(`
SELECT id, name, color, sort_order
FROM schedule_categories
ORDER BY sort_order ASC
`);
res.json(categories);
} catch (error) {
console.error("카테고리 조회 오류:", error);
res.status(500).json({ error: "카테고리 조회 중 오류가 발생했습니다." });
}
});
// 개별 일정 조회
router.get("/:id", async (req, res) => {
try {
const { id } = req.params;
const [schedules] = await pool.query(
`
SELECT
s.*,
c.name as category_name,
c.color as category_color
FROM schedules s
LEFT JOIN schedule_categories c ON s.category_id = c.id
WHERE s.id = ?
`,
[id]
);
if (schedules.length === 0) {
return res.status(404).json({ error: "일정을 찾을 수 없습니다." });
}
res.json(schedules[0]);
} catch (error) {
console.error("일정 조회 오류:", error);
res.status(500).json({ error: "일정 조회 중 오류가 발생했습니다." });
}
});
export default router;