-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from Read-bird/feature/yj
기능수정 및 api 연결
- Loading branch information
Showing
15 changed files
with
257 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,33 @@ | ||
import axios from 'axios'; | ||
|
||
export const authFetch = axios.create({ | ||
baseURL: `${process.env.REACT_APP_SERVER_PATH}` | ||
baseURL: `${process.env.REACT_APP_SERVER_PATH}`, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Accept: 'application/json' | ||
} | ||
}); | ||
|
||
authFetch.interceptors.request.use( | ||
(config) => { | ||
config.headers['Content-Type'] = 'application/json'; | ||
config.headers['Accept'] = 'application/json'; | ||
config.headers.Authorization = `${localStorage.getItem('rb-access-token')}`; | ||
config.headers.refreshtoken = `${localStorage.getItem('rb-refresh-token')}`; | ||
return config; | ||
}, | ||
(error) => { | ||
return Promise.reject(error); | ||
} | ||
); | ||
|
||
authFetch.interceptors.response.use( | ||
(response) => response, | ||
async (error) => { | ||
const status = error.response.status; | ||
if (status === 412) { | ||
const result = await authFetch.post('/api/user/token'); | ||
localStorage.setItem('rb-access-token', result.headers?.authorization); | ||
} | ||
|
||
return Promise.reject(error); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { authFetch } from '@api/axios'; | ||
import { TPlanData } from '@api/types'; | ||
import { AxiosError } from 'axios'; | ||
|
||
type TResponse<T> = { error: boolean; success: boolean; data: T }; | ||
|
||
// 플랜 조회하기 | ||
export const getPlanList = async (date: string): Promise<TResponse<TPlanData | string>> => { | ||
try { | ||
const result = await authFetch.get('/api/plan', { params: { date } }); | ||
return { error: false, success: true, data: result.data }; | ||
} catch (e) { | ||
if (e instanceof AxiosError) { | ||
return { error: true, success: false, data: e.response?.data.message ?? '' }; | ||
} | ||
|
||
return { error: true, success: false, data: '' }; | ||
} | ||
}; | ||
|
||
// 플랜 삭제하기 | ||
export const deletePlan = async (planId: number, userId: number): Promise<TResponse<string>> => { | ||
try { | ||
const result = await authFetch.delete(`/api/plan/${planId}`, { data: { userId } }); | ||
|
||
return { error: false, success: true, data: result.data }; | ||
} catch (e: any) { | ||
if (e instanceof AxiosError) { | ||
return { error: true, success: false, data: e.response?.data.message ?? '' }; | ||
} | ||
|
||
return { error: true, success: false, data: '' }; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.