사고쳤어요
[Node.js] 유튜브 서비스 - 채널 삭제, 채널 수정(DELETE, PUT) 본문
채널 수정
.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: "요청이 올바르지 않습니다.",
});
}
});


'웹 풀스택' 카테고리의 다른 글
| [Node.js] 유튜브 서비스 - router 사용하여 하나의 파일에서 모든 요청 연결하기 (0) | 2025.02.21 |
|---|---|
| [Node.js] 유튜브 서비스 - 채널 전체 조회(GET) (0) | 2025.02.20 |
| [Node.js] 유튜브 서비스 - 채널 생성, 채널 조회(POST, GET) (0) | 2025.02.20 |
| [Node.js] 유튜브 서비스 - app.route() (0) | 2025.02.20 |
| [Node.js] 유튜브 서비스 - 로그인(POST) (0) | 2025.02.20 |