forked from antebrl/IPTV-Restream
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChannelController.js
More file actions
61 lines (53 loc) · 1.81 KB
/
ChannelController.js
File metadata and controls
61 lines (53 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const ChannelService = require('../services/ChannelService');
module.exports = {
getChannels(req, res) {
const channels = ChannelService.getFilteredChannels(req.query);
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());
},
deleteChannel(req, res) {
try {
const { channelId } = req.params;
const channelIdInt = parseInt(channelId, 10);
ChannelService.deleteChannel(channelIdInt);
res.status(204).send();
} catch (error) {
res.status(500).json({ error: error.message });
}
},
async updateChannel(req, res) {
try {
const { channelId } = req.params;
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 });
}
},
addChannel(req, res) {
try {
//const { name, url, avatar, mode, headersJson, group, playlist } = req.body;
const newChannel = ChannelService.addChannel(req.body);
res.status(201).json(newChannel);
} catch (error) {
res.status(500).json({ error: error.message });
}
},
clearChannels(req, res) {
ChannelService.clearChannels();
res.status(204).send();
}
};