-
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.
- services api 추가 - constants 추가 (env 2개 추가) - axios 기본 형태 추가. 추가 설정 필요 - request, response 기본 type 추가 close #21
- Loading branch information
Showing
11 changed files
with
97 additions
and
63 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import axios from '~/shared/axios'; | ||
import { Response } from '~/shared/types'; | ||
import { MainContents } from './services.model'; | ||
|
||
export async function getMainContents(params: { keyword: string }) { | ||
const { data } = await axios.get<Response<MainContents[]>>( | ||
'/services/main_contents', | ||
{ | ||
params, | ||
}, | ||
); | ||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { useQuery, UseQueryOptions } from 'react-query'; | ||
import { AxiosError } from 'axios'; | ||
import { Response } from '~/shared/types'; | ||
import { MainContents } from './services.model'; | ||
import { getMainContents } from './services.api'; | ||
|
||
export function useMainContents( | ||
params: { | ||
keyword: string; | ||
}, | ||
/** | ||
* @see https://github.com/tannerlinsley/react-query/discussions/1195 | ||
* query variables가 필요할 때 | ||
*/ | ||
/** | ||
* @see https://github.com/tannerlinsley/react-query/discussions/1477 | ||
* TQueryFnData : Query 함수의 반환 데이터 | ||
* TError: Query 함수의 에러 반환값 | ||
* TData: Query 함수의 최종 데이터 | ||
*/ | ||
options: | ||
| UseQueryOptions< | ||
Response<MainContents[]>, | ||
AxiosError<unknown>, | ||
Response<MainContents[]> | ||
> | ||
| undefined = {}, | ||
) { | ||
return useQuery<Response<MainContents[]>, AxiosError>( | ||
['/services/main_contents', params], | ||
() => getMainContents(params), | ||
{ | ||
retry: 2, | ||
...options, | ||
}, | ||
); | ||
} |
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,15 @@ | ||
export interface MainContents { | ||
contents_id: number; | ||
title: string; | ||
thumbnail: string; | ||
introduction: string; | ||
writer: Writer; | ||
language: string; | ||
is_translate: boolean; | ||
original_id: number; | ||
} | ||
|
||
export interface Writer { | ||
writer_name: string; | ||
writer_id: string; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import axios from 'axios'; | ||
import { API_URL } from '~/shared/constants/environments'; | ||
|
||
const axiosInstance = axios.create({ baseURL: API_URL }); | ||
|
||
export default axiosInstance; |
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 @@ | ||
export { default } from './axios.factory'; |
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,2 @@ | ||
export const API_URL = process.env.NEXT_PUBLIC_API_URL; | ||
export const APP_STAGE = process.env.NEXT_PUBLIC_APP_STAGE; |
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,2 @@ | ||
export * from './request'; | ||
export * from './response'; |
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,10 @@ | ||
export interface WritingContentsRequest { | ||
title: string; | ||
thumbnail: string; | ||
introduction: string; | ||
contents: string; | ||
writer_id: string; | ||
language: string; | ||
is_translate: boolean; | ||
original_id: number; | ||
} |
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,5 @@ | ||
export interface Response<T> { | ||
status_code: number; | ||
msg: string; | ||
data: T; | ||
} |