Skip to content

Commit

Permalink
refactor: (#205) 댓글을 제외한 나머지 api에 BASE_URL 코드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Gilpop8663 committed Aug 2, 2023
1 parent a7586ad commit 4d4708d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
1 change: 1 addition & 0 deletions frontend/src/api/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const transformCommentListResponse = (commentList: CommentResponse[]): Co
isEdit: comment.createdAt !== comment.updatedAt,
}));
};

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

Expand Down
12 changes: 6 additions & 6 deletions frontend/src/api/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
const BASE_URL = process.env.VOTOGETHER_BASE_URL;

export const votePost = async (postId: number, optionId: number) => {
return await postFetch(`/posts/${postId}/options/${optionId}`, '');
return await postFetch(`${BASE_URL}/posts/${postId}/options/${optionId}`, '');
};

interface OptionData {
Expand All @@ -22,26 +22,26 @@ interface OptionData {

export const changeVotedOption = async (postId: number, optionData: OptionData) => {
return await patchFetch(
`/posts/${postId}/options?source=${optionData.originOptionId}&target=${optionData.newOptionId}`
`${BASE_URL}/posts/${postId}/options?source=${optionData.originOptionId}&target=${optionData.newOptionId}`
);
};

export const getPost = async (postId: number): Promise<PostInfo> => {
return await getFetch<PostInfo>(`/posts/${postId}`);
return await getFetch<PostInfo>(`${BASE_URL}/posts/${postId}`);
};

export const createPost = async (newPost: FormData) => {
return await multiPostFetch(`${BASE_URL}/posts`, newPost);
};

export const editPost = async (postId: number, updatedPost: FormData) => {
return await multiPutFetch(`http://3.35.232.54/api/posts/${postId}`, updatedPost);
return await multiPutFetch(`${BASE_URL}/posts/${postId}`, updatedPost);
};

export const removePost = async (postId: number) => {
return await deleteFetch(`/posts/${postId}`);
return await deleteFetch(`${BASE_URL}/posts/${postId}`);
};

export const setEarlyClosePost = async (postId: number) => {
return await patchFetch(`/posts/${postId}/close`);
return await patchFetch(`${BASE_URL}/posts/${postId}/close`);
};
2 changes: 1 addition & 1 deletion frontend/src/api/postList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {

import { getFetch } from '@utils/fetch';

const BASE_URL = process.env.VOTOGETHER_MOCKING_URL;
const BASE_URL = process.env.VOTOGETHER_BASE_URL;

export const makePostListUrl = (
requiredOption: PostListByRequiredOption,
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/api/voteResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { VoteResult } from '@components/VoteStatistics/type';

import { getFetch } from '@utils/fetch';

const BASE_URL = process.env.VOTOGETHER_BASE_URL;

export const getPostStatistics = async (postId: number): Promise<VoteResult> => {
return await getFetch<VoteResult>(`/posts/${postId}/options`);
return await getFetch<VoteResult>(`${BASE_URL}/posts/${postId}/options`);
};

export const getOptionStatistics = async ({
Expand All @@ -13,5 +15,5 @@ export const getOptionStatistics = async ({
postId: number;
optionId: number;
}): Promise<VoteResult> => {
return await getFetch<VoteResult>(`/posts/${postId}/options/${optionId}`);
return await getFetch<VoteResult>(`${BASE_URL}/posts/${postId}/options/${optionId}`);
};

0 comments on commit 4d4708d

Please sign in to comment.