fromis_9/backend/routes/members.js

35 lines
1 KiB
JavaScript

import express from "express";
import pool from "../lib/db.js";
const router = express.Router();
// 전체 멤버 조회
router.get("/", async (req, res) => {
try {
const [rows] = await pool.query(
"SELECT id, name, birth_date, position, image_url, instagram, is_former FROM members ORDER BY is_former, birth_date"
);
res.json(rows);
} catch (error) {
console.error("멤버 조회 오류:", error);
res.status(500).json({ error: "멤버 정보를 가져오는데 실패했습니다." });
}
});
// 특정 멤버 조회
router.get("/:id", async (req, res) => {
try {
const [rows] = await pool.query("SELECT * FROM members WHERE id = ?", [
req.params.id,
]);
if (rows.length === 0) {
return res.status(404).json({ error: "멤버를 찾을 수 없습니다." });
}
res.json(rows[0]);
} catch (error) {
console.error("멤버 조회 오류:", error);
res.status(500).json({ error: "멤버 정보를 가져오는데 실패했습니다." });
}
});
export default router;