diff --git a/client/src/service/base/api.ts b/client/src/service/base/api.ts index 5a3ce8fa..7d8aa70b 100644 --- a/client/src/service/base/api.ts +++ b/client/src/service/base/api.ts @@ -1,3 +1,4 @@ +import { IResponseRawData } from '@/types'; import axios from 'axios'; export const BASE_URL = process.env.NEXT_PUBLIC_API_URL; @@ -26,7 +27,7 @@ export async function axios_get({ params = {}, }: Omit, 'data'>) { try { - const response = await axios.get(suburl, { + const response = await axios.get>(suburl, { headers, params, paramsSerializer, @@ -34,7 +35,7 @@ export async function axios_get({ //TODO: data: response.data.data로 바꾸기 (백엔드 변경 이후) return { isOkay: true, - data: response.data, + data: response.data.data, }; } catch (error) { if (axios.isAxiosError(error)) { @@ -56,12 +57,16 @@ export async function axios_post({ headers = {}, }: AxiosProps) { try { - const response = await axios.post(suburl, data, { - headers, - }); + const response = await axios.post>( + suburl, + data, + { + headers, + } + ); return { isOkay: true, - data: response.data, + data: response.data.data, }; } catch (error) { if (axios.isAxiosError(error)) { @@ -83,12 +88,12 @@ export async function axios_put({ headers = {}, }: AxiosProps) { try { - const response = await axios.put(suburl, data, { + const response = await axios.put>(suburl, data, { headers, }); return { isOkay: true, - data: response.data, + data: response.data.data, }; } catch (error) { if (axios.isAxiosError(error)) { @@ -109,12 +114,12 @@ export async function axios_delete({ headers = {}, }: Omit, 'data'>) { try { - const response = await axios.delete(suburl, { + const response = await axios.delete>(suburl, { headers, }); return { isOkay: true, - data: response.data, + data: response.data.data, }; } catch (error) { if (axios.isAxiosError(error)) { diff --git a/client/src/service/comment/getComments.ts b/client/src/service/comment/getComments.ts index 6a1e298c..9f15feee 100644 --- a/client/src/service/comment/getComments.ts +++ b/client/src/service/comment/getComments.ts @@ -1,6 +1,6 @@ import { axios_get } from '../base/api'; -import { IComment, IResponseRawData } from '@/types'; +import { IComment } from '@/types'; export default async function getComments({ postOriginId, @@ -9,13 +9,11 @@ export default async function getComments({ }) { const suburl = `/post/${postOriginId}/comments`; - const result = await axios_get({ suburl }); + const result = await axios_get({ suburl }); if (!result.isOkay) { throw result.error; } - const rawData = result.data as IResponseRawData; - - return rawData.data; + return result.data; } diff --git a/client/src/service/follow/checkFollowStatus.ts b/client/src/service/follow/checkFollowStatus.ts index cb256bf3..f1b9676c 100644 --- a/client/src/service/follow/checkFollowStatus.ts +++ b/client/src/service/follow/checkFollowStatus.ts @@ -2,12 +2,6 @@ import { axios_get } from '../base/api'; import { IFollowStatus } from '@/types'; -interface IRawData { - data: IFollowStatus; - status: string; - message: string; -} - export default async function checkFollowStatus({ userId, }: { @@ -15,13 +9,11 @@ export default async function checkFollowStatus({ }) { const suburl = `/follow/status/${userId}`; - const result = await axios_get({ suburl }); + const result = await axios_get({ suburl }); if (!result.isOkay) { throw result.error; } - const rawData = result.data as IRawData; - - return rawData.data; + return result.data; } diff --git a/client/src/service/follow/getFollower.ts b/client/src/service/follow/getFollower.ts index 131bfd2a..5ce61ff8 100644 --- a/client/src/service/follow/getFollower.ts +++ b/client/src/service/follow/getFollower.ts @@ -6,22 +6,14 @@ interface IFollowUser extends Pick { profileImg: string; } -interface IRawData { - data: IFollowUser[]; - status: string; - message: string; -} - export default async function getFollower({ userId }: { userId: string }) { const suburl = `/follow/followers/${userId}`; - const result = await axios_get({ suburl }); + const result = await axios_get({ suburl }); if (!result.isOkay) { throw new Error(result.error); } - const rawData = result.data as IRawData; - - return rawData.data; + return result.data; } diff --git a/client/src/service/follow/getFollowing.ts b/client/src/service/follow/getFollowing.ts index f4847709..8b31c833 100644 --- a/client/src/service/follow/getFollowing.ts +++ b/client/src/service/follow/getFollowing.ts @@ -8,22 +8,14 @@ interface IFollowUser extends Pick { profileImg: string; } -interface IRawData { - data: IFollowUser[]; - status: string; - message: string; -} - export default async function getFollowing({ userId }: { userId: string }) { const suburl = `/follow/followings/${userId}`; - const result = await axios_get({ suburl }); + const result = await axios_get({ suburl }); if (!result.isOkay) { throw new Error(result.error); } - const rawData = result.data as IRawData; - - return rawData.data; + return result.data; } diff --git a/client/src/service/like/getIsLikePost.ts b/client/src/service/like/getIsLikePost.ts index a9a08c31..6ad21045 100644 --- a/client/src/service/like/getIsLikePost.ts +++ b/client/src/service/like/getIsLikePost.ts @@ -1,7 +1,5 @@ import { axios_get } from '../base/api'; -import { IResponseRawData } from '@/types'; - export default async function getIsLikePost({ postOriginId, }: { @@ -9,13 +7,11 @@ export default async function getIsLikePost({ }) { const suburl = `like/posts/${postOriginId}/status`; - const result = await axios_get({ suburl }); + const result = await axios_get({ suburl }); - if (!result.isOkay) { + if (!result.isOkay || result.data === undefined) { throw result.error; } - const rawData = result.data as IResponseRawData; - - return rawData.data; + return result.data; } diff --git a/client/src/service/scrap/getIsScrapPost.ts b/client/src/service/scrap/getIsScrapPost.ts index 1316e873..4ece7685 100644 --- a/client/src/service/scrap/getIsScrapPost.ts +++ b/client/src/service/scrap/getIsScrapPost.ts @@ -1,7 +1,5 @@ import { axios_get } from '../base/api'; -import { IResponseRawData } from '@/types'; - export default async function getIsScrapPost({ postOriginId, }: { @@ -9,13 +7,11 @@ export default async function getIsScrapPost({ }) { const suburl = `scrap/posts/${postOriginId}/status`; - const result = await axios_get({ suburl }); + const result = await axios_get({ suburl }); - if (!result.isOkay) { + if (!result.isOkay || result.data === undefined) { throw result.error; } - const rawData = result.data as IResponseRawData; - - return rawData.data; + return result.data; } diff --git a/client/src/service/scrap/getScrapPosts.ts b/client/src/service/scrap/getScrapPosts.ts index ef9772be..e9312292 100644 --- a/client/src/service/scrap/getScrapPosts.ts +++ b/client/src/service/scrap/getScrapPosts.ts @@ -1,19 +1,17 @@ import { axios_get } from '../base/api'; -import { IResponseRawData, IPostInformation } from '@/types'; +import { IPostInformation } from '@/types'; export default async function getScrapPosts() { const suburl = '/scrap/posts'; - const result = await axios_get({ suburl }); + const result = await axios_get< + Omit + >({ suburl }); if (!result.isOkay) { return result.error; } - const rawData = result.data as IResponseRawData< - Omit - >; - - return rawData.data; + return result.data; }