Skip to content

Commit

Permalink
Refactor: 백엔드 API url 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
soulchicken committed Nov 3, 2023
1 parent 879bb6d commit ae93844
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/components/community/postDetail/CommentInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const CommentInput : FC<postProps> = ({ characterId, postId }) => {
const handleSubmit = async (e: FormEvent) => {
e.preventDefault();
if (message && characterId && postId) {
createComment(characterId, postId, message).then(() => {
fetchComments(characterId, postId);
createComment(postId, message).then(() => {
fetchComments(postId);
});
setMessage('');
}
Expand Down
8 changes: 4 additions & 4 deletions src/store/comment.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { CommentData } from '@/types/post';
import { findCommentsByPostAndCharacterId } from '@/utils/api/boards';
import { readComment } from '@/utils/api/boards';
import { create } from 'zustand';

interface CommentState {
comments: CommentData[],
loading: boolean,
fetchComments: (characterId: string, postId: string) => void;
fetchComments: (postId: string) => void;
}

const useCommentStore = create<CommentState>((set) => ({
comments: [],
loading: true,
fetchComments: async (characterId, postId) => {
fetchComments: async (postId) => {
set({ loading: false });
try {
const response = await findCommentsByPostAndCharacterId(characterId, postId);
const response = await readComment(postId);
console.log(response);
set({ comments: response, loading: true });
} catch (error) {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/api/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface SocialLoginForm {
}

export const credentialsLoginAPI = async (credentials : Credentials) => {
const result = await ssrInstance.post('members/login', JSON.stringify(credentials));
const result = await ssrInstance.post('members/login', credentials);
return result.data;
};

Expand Down Expand Up @@ -63,7 +63,7 @@ export const credentialsSignupAPI = async ({
};

export const refreshAccessToken = async (refreshToken: string) => {
const result = await ssrInstance.post('members/refreshToken', { refreshToken });
const result = await ssrInstance.post('members/refreshtoken', { refreshToken });
return result.data;
};

Expand Down
17 changes: 11 additions & 6 deletions src/utils/api/boards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,23 @@ export const createPost = async (characterId: string, title: string, content: st
return result;
};

export const findCommentsByPostAndCharacterId = async (characterId: string, postId: string) => {
const result = await webServerInstance.get<CommentData[]>(`boards/${characterId}/${postId}/comments`);
export const readComment = async (postId: string) => {
const result = await webServerInstance.get<CommentData[]>(`comments/${postId}`);
return result.data;
};

export const createComment = async (characterId: string, postId: string, comment: string) => {
const result = await webServerInstance.post(`boards/${characterId}/${postId}/comments`, { comment });
export const createComment = async (postId: string, comment: string) => {
const result = await webServerInstance.post(`comments/${postId}`, { comment });
return result.data;
};

export const deleteComment = async (commentId: string) => {
const result = await webServerInstance.put(`comments/${commentId}`);
export const deleteComment = async (postId: string, commentId: string) => {
const result = await webServerInstance.delete(`comments/${postId}/${commentId}`);
return result.data;
};

export const updateComment = async (postId: string, commentId: string) => {
const result = await webServerInstance.put(`comments/${postId}/${commentId}`);
return result.data;
};

Expand Down
4 changes: 2 additions & 2 deletions src/utils/api/character.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ export const findCharacterById = async (characterId: string) => {
};

export const ssrFindAllCharacters = async () => {
const result = await ssrInstance.get<CharacterInfo[]>('/api/characters');
const result = await ssrInstance.get<CharacterInfo[]>('/characters');
return result.data;
};

export const ssrFindCharacterById = async (characterId: string) => {
const result = await ssrInstance.get<CharacterInfo>(`/api/characters/${characterId}`);
const result = await ssrInstance.get<CharacterInfo>(`/characters/${characterId}`);
return result.data;
};
2 changes: 1 addition & 1 deletion src/utils/axiosInstance/webServerInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios, { AxiosError } from 'axios';
import { getSession } from 'next-auth/react';

const webServerInstance = axios.create({
baseURL: `${process.env.NEXT_PUBLIC_SERVER_URL || 'http://localhost:8080/'}api/`,
baseURL: `${process.env.NEXT_PUBLIC_SERVER_URL || 'http://localhost:8080/'}/`,
// headers: { 'Content-Type': 'application/json' },
});

Expand Down

0 comments on commit ae93844

Please sign in to comment.