Skip to content

Commit

Permalink
fix: createApiClient 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
seung365 committed Aug 7, 2024
1 parent 1faa03b commit d8ba137
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 25 deletions.
20 changes: 11 additions & 9 deletions src/api/hooks/Mail/useGetMailBusiness.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@ import { useQuery } from '@tanstack/react-query';
export const getMailPath = (page: number, size: number) =>
`${BASE_URL}/emails?page=${page}&size=${size}`;

const token = sessionStorage.getItem('accessToken');

const apiClient = axios.create({
baseURL: BASE_URL,
headers: {
Authorization: `Bearer ${token}`,
Job: `business`,
},
});
const createApiClient = () => {
const token = sessionStorage.getItem('accessToken');
return axios.create({
baseURL: BASE_URL,
headers: {
Authorization: `Bearer ${token}`,
Job: 'business',
},
});
};

const getMailBusiness = async (page: number, size: number) => {
try {
const apiClient = createApiClient();
const response = await apiClient.get<MailListResponse>(getMailPath(page, size));
return response.data;
} catch (error) {
Expand Down
20 changes: 11 additions & 9 deletions src/api/hooks/Mail/useGetMailUniv.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@ import { useQuery } from '@tanstack/react-query';
export const getMailPath = (page: number, size: number) =>
`${BASE_URL}/emails?page=${page}&size=${size}`;

const token = sessionStorage.getItem('accessToken');

const apiClient = axios.create({
baseURL: BASE_URL,
headers: {
Authorization: `Bearer ${token}`,
Job: `univ`,
},
});
const createApiClient = () => {
const token = sessionStorage.getItem('accessToken');
return axios.create({
baseURL: BASE_URL,
headers: {
Authorization: `Bearer ${token}`,
Job: 'univ',
},
});
};

const getMailUniv = async (page: number, size: number) => {
try {
const apiClient = createApiClient();
const response = await apiClient.get<MailListResponse>(getMailPath(page, size));
return response.data;
} catch (error) {
Expand Down
18 changes: 11 additions & 7 deletions src/api/hooks/Mail/usePostMail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ import { BASE_URL } from '../..';
import { useMutation } from '@tanstack/react-query';

export const postMailPath = () => `${BASE_URL}/save-email`;
const token = sessionStorage.getItem('accessToken');

const apiClient = axios.create({
baseURL: BASE_URL,
headers: {
Authorization: `Bearer ${token}`,
},
});
const createApiClient = () => {
const token = sessionStorage.getItem('accessToken');

return axios.create({
baseURL: BASE_URL,
headers: {
Authorization: `Bearer ${token}`,
},
});
};

const postMail = async (mailInput: MailPostData) => {
try {
const apiClient = createApiClient();
const response = await apiClient.post<number>(postMailPath(), mailInput);
return response.data;
} catch (error) {
Expand Down

0 comments on commit d8ba137

Please sign in to comment.