fix: channel api int parsing
This commit is contained in:
@@ -7,6 +7,17 @@ module.exports = {
|
||||
res.json(channels);
|
||||
},
|
||||
|
||||
getChannel(req, res) {
|
||||
const { channelId } = req.params;
|
||||
const channelIdInt = parseInt(channelId, 10);
|
||||
const channel = ChannelService.getChannelById(channelIdInt);
|
||||
if (channel) {
|
||||
res.json(channel);
|
||||
} else {
|
||||
res.status(404).json({ error: 'Channel not found' });
|
||||
}
|
||||
},
|
||||
|
||||
getCurrentChannel(req, res) {
|
||||
res.json(ChannelService.getCurrentChannel());
|
||||
},
|
||||
@@ -14,17 +25,19 @@ module.exports = {
|
||||
deleteChannel(req, res) {
|
||||
try {
|
||||
const { channelId } = req.params;
|
||||
ChannelService.deleteChannel(channelId);
|
||||
const channelIdInt = parseInt(channelId, 10);
|
||||
ChannelService.deleteChannel(channelIdInt);
|
||||
res.status(204).send();
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
},
|
||||
|
||||
updateChannel(req, res) {
|
||||
async updateChannel(req, res) {
|
||||
try {
|
||||
const { channelId } = req.params;
|
||||
const updatedChannel = ChannelService.updateChannel(channelId, req.body);
|
||||
const channelIdInt = parseInt(channelId, 10);
|
||||
const updatedChannel = await ChannelService.updateChannel(channelIdInt, req.body);
|
||||
res.json(updatedChannel);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
|
||||
@@ -20,6 +20,7 @@ const apiRouter = express.Router();
|
||||
|
||||
apiRouter.get('/', channelController.getChannels);
|
||||
apiRouter.get('/current', channelController.getCurrentChannel);
|
||||
apiRouter.get('/:channelId', channelController.getChannel);
|
||||
apiRouter.delete('/:channelId', channelController.deleteChannel);
|
||||
apiRouter.put('/:channelId', channelController.updateChannel);
|
||||
apiRouter.post('/', channelController.addChannel);
|
||||
|
||||
@@ -34,6 +34,10 @@ class ChannelService {
|
||||
return this.channels;
|
||||
}
|
||||
|
||||
getChannelById(id) {
|
||||
return this.channels.find(channel => channel.id === id);
|
||||
}
|
||||
|
||||
getFilteredChannels({ playlistName, group }) {
|
||||
let filtered = this.channels;
|
||||
if (playlistName) {
|
||||
@@ -110,6 +114,7 @@ class ChannelService {
|
||||
}
|
||||
|
||||
async updateChannel(id, updatedAttributes) {
|
||||
console.log(id);
|
||||
const channelIndex = this.channels.findIndex(channel => channel.id === id);
|
||||
if (channelIndex === -1) {
|
||||
throw new Error('Channel does not exist');
|
||||
|
||||
@@ -5,6 +5,8 @@ class PlaylistService {
|
||||
|
||||
async addPlaylist(playlistUrl, playlistName, mode, headersJson) {
|
||||
|
||||
console.log('Adding playlist', playlistUrl);
|
||||
|
||||
const response = await fetch(playlistUrl);
|
||||
const content = await response.text();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user