웹
댓글 읽기 요청 보내기
Time Saver
2020. 11. 18. 10:55
bang-gui/blog
나의 리액트 페이지. Contribute to bang-gui/blog development by creating an account on GitHub.
github.com
//api/comments.js
import client from './client';
export const writeComment = ({ id, body }) =>
client.post(`/api/posts/${id}/comments`, { body });
export const listComments = ({ id }) =>
client.post(`/api/posts/${id}/comments`);
//comments.ctrl.js
//...생략...
export const list = async ctx => {
try {
const comments = await Comment.find({post: ctx.params.id}).sort({createdAt:-1}).lean().exec();
ctx.body = comments;
} catch (e) {
ctx.throw(500, e);
}
};
잘 불러오는 모습을 볼 수 있다. 읽기를 구현해보자.
댓글 인풋에 이어 댓글 리스트 아이템을 먼저 만들어 보자.