From ae938443285babfe451597091ff811b98362fa26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=86=8C=EC=9A=B8=EC=B9=98=ED=82=A8?= <90738604+soulchicken@users.noreply.github.com> Date: Fri, 3 Nov 2023 17:59:51 +0900 Subject: [PATCH] =?UTF-8?q?Refactor:=20=EB=B0=B1=EC=97=94=EB=93=9C=20API?= =?UTF-8?q?=20url=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../community/postDetail/CommentInput.tsx | 4 ++-- src/store/comment.ts | 8 ++++---- src/utils/api/accounts.ts | 4 ++-- src/utils/api/boards.ts | 17 +++++++++++------ src/utils/api/character.ts | 4 ++-- src/utils/axiosInstance/webServerInstance.ts | 2 +- 6 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/components/community/postDetail/CommentInput.tsx b/src/components/community/postDetail/CommentInput.tsx index 63f1878..dda599e 100644 --- a/src/components/community/postDetail/CommentInput.tsx +++ b/src/components/community/postDetail/CommentInput.tsx @@ -20,8 +20,8 @@ const CommentInput : FC = ({ 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(''); } diff --git a/src/store/comment.ts b/src/store/comment.ts index a057b76..020f1f1 100644 --- a/src/store/comment.ts +++ b/src/store/comment.ts @@ -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((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) { diff --git a/src/utils/api/accounts.ts b/src/utils/api/accounts.ts index 5bdab42..67e61b6 100644 --- a/src/utils/api/accounts.ts +++ b/src/utils/api/accounts.ts @@ -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; }; @@ -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; }; diff --git a/src/utils/api/boards.ts b/src/utils/api/boards.ts index 7e3db26..0b61335 100644 --- a/src/utils/api/boards.ts +++ b/src/utils/api/boards.ts @@ -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(`boards/${characterId}/${postId}/comments`); +export const readComment = async (postId: string) => { + const result = await webServerInstance.get(`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; }; diff --git a/src/utils/api/character.ts b/src/utils/api/character.ts index b8ac9c2..839d1e8 100644 --- a/src/utils/api/character.ts +++ b/src/utils/api/character.ts @@ -13,11 +13,11 @@ export const findCharacterById = async (characterId: string) => { }; export const ssrFindAllCharacters = async () => { - const result = await ssrInstance.get('/api/characters'); + const result = await ssrInstance.get('/characters'); return result.data; }; export const ssrFindCharacterById = async (characterId: string) => { - const result = await ssrInstance.get(`/api/characters/${characterId}`); + const result = await ssrInstance.get(`/characters/${characterId}`); return result.data; }; diff --git a/src/utils/axiosInstance/webServerInstance.ts b/src/utils/axiosInstance/webServerInstance.ts index 5ec5fc9..18cd472 100644 --- a/src/utils/axiosInstance/webServerInstance.ts +++ b/src/utils/axiosInstance/webServerInstance.ts @@ -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' }, });