29 lines
841 B
TypeScript
29 lines
841 B
TypeScript
import express from 'express';
|
|
import { Playlist } from '../models/Playlist.js';
|
|
|
|
const router = express.Router();
|
|
|
|
// Get all playlists
|
|
router.get('/', async (req, res) => {
|
|
try {
|
|
const playlists = await Playlist.find();
|
|
res.json(playlists);
|
|
} catch (error) {
|
|
console.error('Error fetching playlists:', error);
|
|
res.status(500).json({ error: 'Failed to fetch playlists' });
|
|
}
|
|
});
|
|
|
|
// Save playlists in batch (replacing all existing ones)
|
|
router.post('/batch', async (req, res) => {
|
|
try {
|
|
await Playlist.deleteMany({}); // Clear existing playlists
|
|
const playlists = await Playlist.create(req.body);
|
|
res.json(playlists);
|
|
} catch (error) {
|
|
console.error('Error saving playlists:', error);
|
|
res.status(500).json({ error: 'Failed to save playlists' });
|
|
}
|
|
});
|
|
|
|
export const playlistsRouter = router;
|