Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[혜수] - API 엔드 포인트 상수화 작업 #92

Merged
merged 4 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/apis/axiosInstanceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import axios, { AxiosError, InternalAxiosRequestConfig } from 'axios';
import { getCookie } from 'cookies-next';

export const axiosInstanceClient = axios.create({
baseURL: process.env.NEXT_PUBLIC_TEST_API_END_POINT,
baseURL: process.env.NEXT_PUBLIC_BASE_URL,
timeout: NETWORK.TIMEOUT,
authorization: true,
});
Expand Down
2 changes: 1 addition & 1 deletion src/apis/axiosInstanceServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import axios, { AxiosError, InternalAxiosRequestConfig } from 'axios';
import { cookies } from 'next/headers';

export const axiosInstanceServer = axios.create({
baseURL: process.env.NEXT_PUBLIC_TEST_API_END_POINT,
baseURL: process.env.NEXT_PUBLIC_BASE_URL,
timeout: NETWORK.TIMEOUT,
authorization: true,
});
Expand Down
3 changes: 2 additions & 1 deletion src/apis/client/deletePlan.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { DOMAIN } from '@/constants/api';
import { axiosInstanceClient } from '../axiosInstanceClient';

// 헤더에 date 추가해줘야 함
export const deletePlan = (planId: number) => {
return axiosInstanceClient.delete(`/plans/${planId}`);
return axiosInstanceClient.delete(DOMAIN.DELETE_PLANS(planId));
};
3 changes: 2 additions & 1 deletion src/apis/client/editPlan.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { DOMAIN } from '@/constants/api';
import { axiosInstanceClient } from '../axiosInstanceClient';

// 헤더에 date 추가해줘야 함
export const editPlan = (planId: number) => {
return axiosInstanceClient.put(`/plans/${planId}`);
return axiosInstanceClient.put(DOMAIN.PUT_PLANS(planId));
};
3 changes: 2 additions & 1 deletion src/apis/client/getAllPlans.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { DOMAIN } from '@/constants/api';
import { GetAllPlansResponse } from '@/types/apis/plan/GetAllPlans';
import { axiosInstanceClient } from '../axiosInstanceClient';

export const getAllPlans = async () => {
const { data } = await axiosInstanceClient.get<GetAllPlansResponse>(
'/plans',
DOMAIN.GET_PLANS_ALL,
{
authorization: false,
},
Expand Down
3 changes: 2 additions & 1 deletion src/apis/client/getRemindAfterSeason.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DOMAIN } from '@/constants/api';
import { axiosInstanceClient } from '../axiosInstanceClient';

export const getRemindAfterSeason = (planId: number) => {
return axiosInstanceClient.get(`/reminds/${planId}`);
return axiosInstanceClient.get(DOMAIN.GET_REMINDS(planId));
};
3 changes: 2 additions & 1 deletion src/apis/client/getRemindSeason.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DOMAIN } from '@/constants/api';
import { axiosInstanceClient } from '../axiosInstanceClient';

export const getRemindSeason = (planId: number) => {
return axiosInstanceClient.get(`/reminds/modify/${planId}`);
return axiosInstanceClient.get(DOMAIN.GET_REMINDS_MODIFY(planId));
};
5 changes: 4 additions & 1 deletion src/apis/client/postNewPlan.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DOMAIN } from '@/constants/api';
import { axiosInstanceClient } from '../axiosInstanceClient';

interface PostNewPlanRequestBody {
Expand All @@ -14,6 +15,8 @@ interface PostNewPlanRequestBody {
}

export const postNewPlan = async (body: PostNewPlanRequestBody) => {
const { data } = await axiosInstanceClient.post('/plans', { data: body });
const { data } = await axiosInstanceClient.post(DOMAIN.POST_PLANS, {
data: body,
});
return data;
};
3 changes: 2 additions & 1 deletion src/apis/client/toggleAjajaNotification.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DOMAIN } from '@/constants/api';
import { axiosInstanceClient } from '../axiosInstanceClient';

export const toggleAjajaNotification = (planId: number) => {
return axiosInstanceClient.put(`/plans/${planId}/ajaja`);
return axiosInstanceClient.put(DOMAIN.PUT_PLANS_SWITCH_AJAJA(planId));
};
3 changes: 2 additions & 1 deletion src/apis/client/toggleIsPublic.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DOMAIN } from '@/constants/api';
import { axiosInstanceClient } from '../axiosInstanceClient';

export const toggleIsPublic = (planId: number) => {
return axiosInstanceClient.put(`/plans/${planId}/public`);
return axiosInstanceClient.put(DOMAIN.PUT_PLANS_SWITCH_PUBLIC(planId));
};
3 changes: 2 additions & 1 deletion src/apis/client/toggleIsRemindable.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DOMAIN } from '@/constants/api';
import { axiosInstanceClient } from '../axiosInstanceClient';

export const toggleIsRemindable = (planId: number) => {
return axiosInstanceClient.put(`/plans/${planId}/remindable`);
return axiosInstanceClient.put(DOMAIN.PUT_PLANS_SWITCH_REMINDABLE(planId));
};
15 changes: 6 additions & 9 deletions src/apis/server/getMyPlans.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { DOMAIN } from '@/constants/api';
import { GetMyPlansResponse } from '@/types/apis/plan/GetMyPlans';
import { axiosInstanceServer } from '@apis/axiosInstanceServer';

export const getMyPlans = async (userId: string) => {
try {
const { data } = await axiosInstanceServer.get<GetMyPlansResponse>(
`/plans/main/${userId}`,
);
return data;
} catch (error) {
console.log('Error:', error);
}
export const getMyPlans = async (userId: number) => {
const { data } = await axiosInstanceServer.get<GetMyPlansResponse>(
DOMAIN.GET_PLANS_MAIN(userId),
);
return data;
};
9 changes: 3 additions & 6 deletions src/app/(headerless)/oauth/hooks/useOauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@ export default function useOauth() {
useEffect(() => {
const code = new URL(window.location.href).searchParams.get('code');
(async () => {
await fetch(
`${process.env.NEXT_PUBLIC_TEST_API_END_POINT}/login?code=${code}`,
{
method: 'POST',
},
)
await fetch(`${process.env.NEXT_PUBLIC_BASE_URL}/login?code=${code}`, {
method: 'POST',
})
.then((res) => res.json())
.then((data) => {
const auth: auth = {
Expand Down
64 changes: 64 additions & 0 deletions src/constants/api.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,67 @@
export const NETWORK = {
TIMEOUT: 10000,
} as const;

export const DOMAIN = {
PUT_USERS_RECEIVE: '/users/receive',
POST_USERS_VERIFY: '/mock/users/verify-email',
POST_USERS_SEND_VERIFICATION: '/mock/users/send-verification',
POST_USERS_REFRESH: '/mock/users/refresh',
POST_USERS_LOGOUT: '/mock/users/logout',
DELETE_USERS: '/mock/users',

POST_FEEDBACKS: (feedbackId: number) => `/mock/feedbacks/${feedbackId}`,
GET_FEEDBACKS: (userId: number) => `/feedbacks/${userId}`,
GET_FEEDBACKS_EACH: (planId: number) => `/mock/${planId}/feedbacks`,

POST_REISSUE: '/mock/reissue',
POST_LOGIN: '/mock/login',

GET_PLANS_REMINDS: (planId: number) => `/mock/plans/${planId}/reminds`,
PUT_PLANS_REMINDS: (planId: number) => `/mock/plans/${planId}/reminds`,
POST_PLANS_REMINDS: (planId: number) => `/mock/plans/${planId}/reminds`,
GET_PLANS_REMINDS_MESSAGES: (userId: number) =>
`/mock/plans/${userId}/reminds/messages`,
GET_PLANS: (planId: number) => `/mock/plans/${planId}`,
PUT_PLANS: (planId: number) => `/mock/plans/${planId}`,
DELETE_PLANS: (planId: number) => `/mock/plans/${planId}`,
PUT_PLANS_SWITCH_REMINDABLE: (planId: number) =>
`/mock/plans/${planId}/remindable`,
PUT_PLANS_SWITCH_PUBLIC: (planId: number) => `/mock/plans/${planId}/public`,
PUT_PLANS_SWITCH_AJAJA: (planId: number) => `/mock/plans/${planId}/ajaja`,
GET_PLANS_ALL: '/mock/plans',
POST_PLANS: '/mock/plans',
GET_PLANS_FEEDBAKS: (planId: number) => `/plans/${planId}/feedbacks`,
GET_PLANS_MAIN: (userId: number) => `/mock/plans/main/${userId}`,

GET_REMINDS: (planId: number) => `/reminds/${planId}`,
GET_REMINDS_MODIFY: (planId: number) => `/reminds/modify/${planId}`,
};

//실제 API -> swagger 순서입니다.
// PUT_USERS_RECEIVE: '/users/receive',
// POST_USERS_VERIFY: '/users/verify',
// POST_USERS_SEND_VERIFICATION: '/users/send-verification',
// POST_USERS_REFRESH: '/users/refresh',
// POST_USERS_LOGOUT: '/users/logout',
// DELETE_USERS: '/users',

// POST_FEEDBACKS: (feedbackId: number) => `/feedbacks/${feedbackId}`,
// GET_FEEDBACKS: (userId: number) => `/feedbacks/${userId}`,

// POST_REISSUE: '/reissue',
// POST_LOGIN: '/login',

// GET_PLANS: (planId: number) => `/plans/${planId}`,
// PUT_PLANS: (planId: number) => `/plans/${planId}`,
// DELETE_PLANS: (planId: number) => `/plans/${planId}`,
// PUT_PLANS_SWITCH_REMINDABLE: (planId: number) => `/plans/${planId}/remindable`,
// PUT_PLANS_SWITCH_PUBLIC: (planId: number) => `/plans/${planId}/public`,
// PUT_PLANS_SWITCH_AJAJA: (planId: number) => `/plans/${planId}/ajaja`,
// GET_PLANS_ALL: '/plans',
// POST_PLANS: '/plans',
// GET_PLANS_FEEDBAKS: (planId: number) => `/plans/${planId}/feedbacks`,
// GET_PLANS_MAIN: (userId: number) => `/plans/main/${userId}`,

// GET_REMINDS : (planId: number) => `/reminds/${planId}`,
// GET_REMINDS_MODIFY : (planId: number) => `/reminds/modify/${planId}`,