Skip to content

Commit

Permalink
feat: (#157) 댓글 관련 API fetch 함수 및 타입 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
inyeong-kang committed Jul 28, 2023
1 parent 02a0f03 commit e993416
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
23 changes: 23 additions & 0 deletions frontend/src/api/comment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { CommentRequest, CommentResponse } from '@type/comment';

import { getFetch, postFetch, putFetch, deleteFetch } from '@utils/fetch';

export const getComment = async (postId: number): Promise<CommentResponse> => {
return await getFetch<CommentResponse>(`/posts/${postId}/comments`);
};

export const createComment = async (postId: number, newComment: CommentRequest) => {
return await postFetch(`/posts/${postId}/comments`, newComment);
};

export const editComment = async (
postId: number,
commentId: number,
updatedComment: CommentRequest
) => {
return await putFetch(`/posts/${postId}/comments/${commentId}`, updatedComment);
};

export const deleteComment = async (postId: number, commentId: number) => {
return await deleteFetch(`/posts/${postId}/comments/${commentId}`);
};
25 changes: 25 additions & 0 deletions frontend/src/types/comment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export interface Comment {
id: number;
member: {
id: number;
nickname: string;
};
content: string;
createdAt: string;
isEdit: boolean;
}

export interface CommentResponse {
id: number;
member: {
id: number;
nickname: string;
};
content: string;
createdAt: string;
updatedAt: string;
}

export interface CommentRequest {
content: string;
}

0 comments on commit e993416

Please sign in to comment.