Skip to content

Commit

Permalink
refactor: (#168) post detail에 대한 query key 추가, 실서버 주소로 API 주소 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
inyeong-kang committed Aug 3, 2023
1 parent d756058 commit d26f363
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
10 changes: 6 additions & 4 deletions frontend/src/api/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Comment, CommentRequest, CommentResponse } from '@type/comment';

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

const BASE_URL = process.env.VOTOGETHER_BASE_URL;

export const transformCommentListResponse = (commentList: CommentResponse[]): Comment[] => {
return commentList.map(comment => ({
id: comment.id,
Expand All @@ -13,23 +15,23 @@ export const transformCommentListResponse = (commentList: CommentResponse[]): Co
};

export const getCommentList = async (postId: number): Promise<Comment[]> => {
const commentList = await getFetch<CommentResponse[]>(`/posts/${postId}/comments`);
const commentList = await getFetch<CommentResponse[]>(`${BASE_URL}/posts/${postId}/comments`);

return transformCommentListResponse(commentList);
};

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

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

export const deleteComment = async (postId: number, commentId: number) => {
return await deleteFetch(`/posts/${postId}/comments/${commentId}`);
return await deleteFetch(`${BASE_URL}/posts/${postId}/comments/${commentId}`);
};
1 change: 1 addition & 0 deletions frontend/src/constants/queryKey.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export const QUERY_KEY = {
POSTS: 'posts',
POST_DETAIL: 'postDetail',
COMMENTS: 'comments',
CATEGORIES: 'categories',
USER_INFO: 'user_info',
Expand Down

0 comments on commit d26f363

Please sign in to comment.