-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: 맵 편집/생성 페이지를 API 명세에 맞게 마이그레이션 (#979)
* refactor: api v2 추상화로직 작성 - mockoon의 port를 7742로 설정해야함. * refactor: 맵 단건조회 API 사용부분 V2로 변경 * refactor: 맵 생성 API V2로 마이그레이션 * refactor: 맵 수정 API V2로 마이그레이션 * refactor: query key 변경
- Loading branch information
Showing
4 changed files
with
83 additions
and
11 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,14 +1,60 @@ | ||
import { AxiosResponse } from 'axios'; | ||
import { QueryFunction } from 'react-query'; | ||
import { QueryManagerMapsSuccessV2 } from 'types/response-v2'; | ||
import { QueryFunction, QueryKey } from 'react-query'; | ||
import { QueryManagerMapSuccessV2 } from 'types/response-v2'; | ||
import apiV2 from './apiv2'; | ||
|
||
export interface QueryManagerMapParamsV2 { | ||
mapId: number; | ||
} | ||
|
||
interface PostMapParamsV2 { | ||
mapName: string; | ||
mapDrawing: string; | ||
thumbnail: string; | ||
slackUrl: string; | ||
} | ||
|
||
interface PutMapParamsV2 { | ||
mapId: number; | ||
mapName: string; | ||
mapDrawing: string; | ||
thumbnail: string; | ||
slackUrl: string; | ||
} | ||
|
||
interface DeleteMapParamsV2 { | ||
mapId: number; | ||
} | ||
|
||
export const queryManagerMapV2: QueryFunction< | ||
AxiosResponse<QueryManagerMapSuccessV2>, | ||
[QueryKey, QueryManagerMapParamsV2] | ||
> = ({ queryKey }) => { | ||
const [, data] = queryKey; | ||
const { mapId } = data; | ||
|
||
return apiV2.get(`/api/maps/${mapId}`); | ||
}; | ||
|
||
export const queryManagerMapsV2: QueryFunction<AxiosResponse<QueryManagerMapsSuccessV2>> = () => | ||
apiV2.get('/api/maps'); | ||
|
||
export const postMapV2 = ({ | ||
mapName, | ||
mapDrawing, | ||
thumbnail, | ||
slackUrl, | ||
}: PostMapParamsV2): Promise<AxiosResponse<never>> => | ||
apiV2.post('/api/maps', { mapName, mapDrawing, thumbnail, slackUrl }); | ||
|
||
export const putMapV2 = ({ | ||
mapId, | ||
mapName, | ||
mapDrawing, | ||
thumbnail, | ||
slackUrl, | ||
}: PutMapParamsV2): Promise<AxiosResponse<never>> => | ||
apiV2.put(`/api/maps/${mapId}`, { mapName, mapDrawing, thumbnail, slackUrl }); | ||
|
||
export const deleteMapV2 = ({ mapId }: DeleteMapParamsV2): Promise<AxiosResponse<never>> => | ||
apiV2.delete(`/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { AxiosError, AxiosResponse } from 'axios'; | ||
import { QueryKey, useQuery, UseQueryOptions, UseQueryResult } from 'react-query'; | ||
import { QueryManagerMapParamsV2, queryManagerMapV2 } from 'api-v2/managerMap'; | ||
import { ErrorResponse } from 'types/response'; | ||
import { QueryManagerMapSuccessV2 } from 'types/response-v2'; | ||
|
||
const useManagerMapV2 = <TData = AxiosResponse<QueryManagerMapSuccessV2>>( | ||
{ mapId }: QueryManagerMapParamsV2, | ||
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