-
Notifications
You must be signed in to change notification settings - Fork 20
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
refactor: 맵 상세 페이지를 새로운 API 명세에 맞게 마이그레이션 #980
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7df6fb7
refactor: axios api v2 작성
suyoungj db37a80
refactor: api request 및 query v2 작성
suyoungj eb58d78
refactor: useManagerMap 사용처 v2 마이그레이션
suyoungj 5ecec49
refactor: 불필요한 Vertical Bar 제거
suyoungj e42e16e
refactor: MapItemResponse type에 slackUrl 프로퍼티 추가
suyoungj 34c17fc
Merge branch 'campus-dev' into refactor/977/map-detail-page
2yunseong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import axios, { AxiosError } from 'axios'; | ||
import { history } from 'App'; | ||
import PATH from 'constants/path'; | ||
import { LOCAL_STORAGE_KEY } from 'constants/storage'; | ||
import { ErrorResponse } from 'types/response'; | ||
import { getLocalStorageItem, removeLocalStorageItem } from 'utils/localStorage'; | ||
|
||
const apiV2 = axios.create({ | ||
baseURL: 'http://localhost:7742', | ||
headers: { | ||
'Content-type': 'application/json', | ||
}, | ||
}); | ||
|
||
apiV2.interceptors.request.use( | ||
(config) => { | ||
const token = getLocalStorageItem({ | ||
key: LOCAL_STORAGE_KEY.ACCESS_TOKEN, | ||
defaultValue: '', | ||
}); | ||
|
||
if (typeof token !== 'string' || !token) return config; | ||
|
||
config.headers = { | ||
'Content-type': 'application/json', | ||
Authorization: `Bearer ${token}`, | ||
}; | ||
|
||
return config; | ||
}, | ||
|
||
(error) => { | ||
return Promise.reject(error); | ||
} | ||
); | ||
|
||
apiV2.interceptors.response.use( | ||
(response) => { | ||
return response; | ||
}, | ||
|
||
(error: AxiosError<ErrorResponse>) => { | ||
if (error?.response?.status === 401) { | ||
removeLocalStorageItem({ key: LOCAL_STORAGE_KEY.ACCESS_TOKEN }); | ||
|
||
history.push(PATH.LOGIN); | ||
} | ||
|
||
return Promise.reject(error); | ||
} | ||
); | ||
|
||
export default apiV2; |
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,18 @@ | ||
import { AxiosResponse } from 'axios'; | ||
import { QueryFunction, QueryKey } from 'react-query'; | ||
import { QueryManagerMapSuccessV2 } from 'types/response-v2'; | ||
import apiV2 from './apiv2'; | ||
|
||
export interface QueryManagerMapParamsV2 { | ||
mapId: number; | ||
} | ||
|
||
export const queryManagerMapV2: QueryFunction< | ||
AxiosResponse<QueryManagerMapSuccessV2>, | ||
[QueryKey, QueryManagerMapParamsV2] | ||
> = ({ queryKey }) => { | ||
const [, data] = queryKey; | ||
const { mapId } = data; | ||
|
||
return apiV2.get(`/api/maps/${mapId}`); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { AxiosError, AxiosResponse } from 'axios'; | ||
import { QueryKey, useQuery, UseQueryOptions, UseQueryResult } from 'react-query'; | ||
import { QueryManagerMapParamsV2, queryManagerMapV2 } from 'api-v2/managerMap'; | ||
import { QueryManagerMapParams } from 'api/managerMap'; | ||
import { ErrorResponse } from 'types/response'; | ||
import { QueryManagerMapSuccessV2 } from 'types/response-v2'; | ||
|
||
const useManagerMapV2 = <TData = AxiosResponse<QueryManagerMapSuccessV2>>( | ||
{ mapId }: QueryManagerMapParams, | ||
options?: UseQueryOptions< | ||
AxiosResponse<QueryManagerMapSuccessV2>, | ||
AxiosError<ErrorResponse>, | ||
TData, | ||
[QueryKey, QueryManagerMapParamsV2] | ||
> | ||
): UseQueryResult<TData, AxiosError<ErrorResponse>> => | ||
useQuery(['getManagerMapV2', { mapId }], queryManagerMapV2, options); | ||
|
||
export default useManagerMapV2; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { MapItem } from './common'; | ||
|
||
export interface MapItemResponseV2 | ||
extends Omit<MapItem, 'mapDrawing' | 'sharingMapId' | 'notice' | 'managerEmail'> { | ||
mapDrawing: string; | ||
} | ||
|
||
export interface QueryManagerMapsSuccessV2 { | ||
maps: MapItemResponseV2[]; | ||
organization: string; | ||
} | ||
|
||
export type QueryManagerMapSuccessV2 = MapItemResponseV2; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
명세보면, slackUrl이 포함되어있어서 해당 부분 추가해줘야 될 것 같습니다!
일단은 저도 MapItemResponseV2에 slackUrl 프로퍼티를 추가했는데, 생각해보면 MapItem에 넣어야 겠더라구요.
위 부분은 Map관련 API 전부 이전한 이후 변경해도 좋다 생각합니다.
따라서 merge할 때 유념하면 될 것 같아요!