@@ -6,66 +6,5 @@ const router = express.Router();
66
77router . route ( "/" ) . get ( getAllSongs ) ;
88router . route ( "/new" ) . post ( newSong ) ;
9- // /**
10- // * @route GET /songs
11- // * @desc Get all songs
12- // * @access Public
13- // */
14- // router.get("/", async (req, res) => {
15- // try {
16- // const songs = await getAllSongs();
17- // return res.json(songs);
18- // } catch (error) {
19- // console.error("Error fetching songs:", error.message);
20- // res.status(500).json({ error: "Internal Server Error" });
21- // }
22- // });
23-
24- // /**
25- // * @route POST /songs/new
26- // * @desc Create new songs and update associated album
27- // * @access Public
28- // */
29- // router.post("/new", async (req, res) => {
30- // try {
31- // const songsData = req.body;
32- // console.log(songsData);
33-
34- // // Ensure songsData is an array
35- // if (!Array.isArray(songsData)) {
36- // return res
37- // .status(400)
38- // .json({ error: "Invalid request. Expected an array of songs." });
39- // }
40-
41- // const savedSongs = [];
42-
43- // for (const { name, artist, albumId, duration } of songsData) {
44- // // Create a new song
45- // const song = new Song({ name, artist, albumId, duration });
46- // const savedSong = await song.save();
47-
48- // // Update the associated album with the new song's ID
49- // const validAlbum = await getAlbum(albumId);
50-
51- // if (!validAlbum) {
52- // return res.status(404).json({ error: "Album not found" });
53- // }
54-
55- // // Add the new song's ID to the album's tracks array
56- // validAlbum.tracks.push(savedSong._id);
57- // await validAlbum.save();
58-
59- // savedSongs.push(savedSong);
60- // }
61-
62- // res.json(savedSongs);
63- // } catch (error) {
64- // console.error("Error creating songs and updating album:", error.message);
65- // res.status(500).json({ error: "Internal Server Error" });
66- // }
67- // });
68-
69- // module.exports = router;
709
7110module . exports = router ;
0 commit comments