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);
}
};
잘 불러오는 모습을 볼 수 있다. 읽기를 구현해보자.
댓글 인풋에 이어 댓글 리스트 아이템을 먼저 만들어 보자.
'웹' 카테고리의 다른 글
댓글 작성자에게만 버튼을 노출하기 (0) | 2020.11.24 |
---|---|
삭제 기능 (0) | 2020.11.24 |
리덕스로 댓글 쓰기 요청 보내기 (0) | 2020.11.18 |
생성, 조회, 삭제, 수정 API 생성하기 (0) | 2020.11.16 |