백엔드: 트랙 상세 API 라우트 순서 수정
This commit is contained in:
parent
b18183a9f9
commit
4e52f79cd5
1 changed files with 42 additions and 42 deletions
|
|
@ -81,48 +81,7 @@ router.get("/", async (req, res) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 앨범 folder_name 또는 title로 조회
|
// 앨범명과 트랙명으로 트랙 상세 조회 (더 구체적인 경로이므로 /by-name/:name보다 앞에 배치)
|
||||||
router.get("/by-name/:name", async (req, res) => {
|
|
||||||
try {
|
|
||||||
const name = decodeURIComponent(req.params.name);
|
|
||||||
// folder_name 또는 title로 검색 (PC는 title, 모바일은 folder_name 사용)
|
|
||||||
const [albums] = await pool.query(
|
|
||||||
"SELECT * FROM albums WHERE folder_name = ? OR title = ?",
|
|
||||||
[name, name]
|
|
||||||
);
|
|
||||||
|
|
||||||
if (albums.length === 0) {
|
|
||||||
return res.status(404).json({ error: "앨범을 찾을 수 없습니다." });
|
|
||||||
}
|
|
||||||
|
|
||||||
const album = await getAlbumDetails(albums[0]);
|
|
||||||
res.json(album);
|
|
||||||
} catch (error) {
|
|
||||||
console.error("앨범 조회 오류:", error);
|
|
||||||
res.status(500).json({ error: "앨범 정보를 가져오는데 실패했습니다." });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// ID로 앨범 조회
|
|
||||||
router.get("/:id", async (req, res) => {
|
|
||||||
try {
|
|
||||||
const [albums] = await pool.query("SELECT * FROM albums WHERE id = ?", [
|
|
||||||
req.params.id,
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (albums.length === 0) {
|
|
||||||
return res.status(404).json({ error: "앨범을 찾을 수 없습니다." });
|
|
||||||
}
|
|
||||||
|
|
||||||
const album = await getAlbumDetails(albums[0]);
|
|
||||||
res.json(album);
|
|
||||||
} catch (error) {
|
|
||||||
console.error("앨범 조회 오류:", error);
|
|
||||||
res.status(500).json({ error: "앨범 정보를 가져오는데 실패했습니다." });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 앨범명과 트랙명으로 트랙 상세 조회
|
|
||||||
router.get("/by-name/:albumName/track/:trackTitle", async (req, res) => {
|
router.get("/by-name/:albumName/track/:trackTitle", async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const albumName = decodeURIComponent(req.params.albumName);
|
const albumName = decodeURIComponent(req.params.albumName);
|
||||||
|
|
@ -177,4 +136,45 @@ router.get("/by-name/:albumName/track/:trackTitle", async (req, res) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 앨범 folder_name 또는 title로 조회
|
||||||
|
router.get("/by-name/:name", async (req, res) => {
|
||||||
|
try {
|
||||||
|
const name = decodeURIComponent(req.params.name);
|
||||||
|
// folder_name 또는 title로 검색 (PC는 title, 모바일은 folder_name 사용)
|
||||||
|
const [albums] = await pool.query(
|
||||||
|
"SELECT * FROM albums WHERE folder_name = ? OR title = ?",
|
||||||
|
[name, name]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (albums.length === 0) {
|
||||||
|
return res.status(404).json({ error: "앨범을 찾을 수 없습니다." });
|
||||||
|
}
|
||||||
|
|
||||||
|
const album = await getAlbumDetails(albums[0]);
|
||||||
|
res.json(album);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("앨범 조회 오류:", error);
|
||||||
|
res.status(500).json({ error: "앨범 정보를 가져오는데 실패했습니다." });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// ID로 앨범 조회
|
||||||
|
router.get("/:id", async (req, res) => {
|
||||||
|
try {
|
||||||
|
const [albums] = await pool.query("SELECT * FROM albums WHERE id = ?", [
|
||||||
|
req.params.id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (albums.length === 0) {
|
||||||
|
return res.status(404).json({ error: "앨범을 찾을 수 없습니다." });
|
||||||
|
}
|
||||||
|
|
||||||
|
const album = await getAlbumDetails(albums[0]);
|
||||||
|
res.json(album);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("앨범 조회 오류:", error);
|
||||||
|
res.status(500).json({ error: "앨범 정보를 가져오는데 실패했습니다." });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue