Notice
Recent Posts
Recent Comments
Link
«   2026/02   »
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
Archives
Today
Total
관리 메뉴

사고쳤어요

[Node.js] 유튜브 서비스 - 채널 삭제, 채널 수정(DELETE, PUT) 본문

웹 풀스택

[Node.js] 유튜브 서비스 - 채널 삭제, 채널 수정(DELETE, PUT)

kevinmj12 2025. 2. 20. 17:33

채널 수정

.put((req, res) => {
    let { id } = req.params;
    id = parseInt(id);
    let newChannelTitle = req.body.channelTitle;

    let channel = channelDb.get(id);
    let oldChannelTitle = channel.channelTitle;

    if (channel) {
      channel.channelTitle = newChannelTitle;
      channelDb.set(id, channel);

      res.json({
        message: `${oldChannelTitle} 채널이 ${newChannelTitle} 채널로 수정되었습니다.`,
      });
    } else {
      res.status(404).json({
        message: "요청이 올바르지 않습니다.",
      });
    }
  })

채널 삭제

.delete((req, res) => {
    let { id } = req.params;
    id = parseInt(id);

    let channel = channelDb.get(id);
    if (channel) {
      channelDb.delete(id);
      res.json({
        message: `${channel.channelTitle} 채널이 삭제되었습니다.`,
      });
    } else {
      res.status(404).json({
        message: "요청이 올바르지 않습니다.",
      });
    }
  });