Skip to content

Commit eb24a00

Browse files
committed
refactor: 그래프 관련 API 및 훅 추가, 기존 API 수정 및 불필요한 파일 삭제
1 parent 3bc75ce commit eb24a00

13 files changed

Lines changed: 133 additions & 35 deletions

src/entities/auth/apis/refresh-token.api.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export const refreshTokenApi = async ({
2525
method: 'POST',
2626
headers: {
2727
'Content-Type': 'application/json',
28-
refreshToken: refreshToken,
2928
},
3029
body: JSON.stringify({ refreshToken }),
3130
});
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { fetchInstance } from '@/shared';
2+
3+
import type { Period } from '../types';
4+
5+
export const GRAPH_GU_API_PATH = (gu: string) => `/api/graph/gu/${gu}`;
6+
7+
export interface GraphGuApiResponse extends Period {
8+
gu: string;
9+
dongs: {
10+
month: string;
11+
regionGu: string;
12+
regionDong: string;
13+
riskScoreAvg: number;
14+
riskEnum: string;
15+
divergencePct: number;
16+
}[];
17+
selectedDong: string;
18+
series: {
19+
month: {
20+
year: number;
21+
month: string;
22+
monthValue: number;
23+
leapYear: boolean;
24+
};
25+
transAmt: number;
26+
depositAmt: number;
27+
ratioPctileAvg: number;
28+
divergence: number;
29+
riskEnum: string;
30+
}[];
31+
}
32+
33+
export interface GraphGuAPIParams extends Period {
34+
gu: string;
35+
dong: string;
36+
from: string;
37+
to: string;
38+
}
39+
40+
export const graphGuApi = async ({
41+
gu,
42+
dong,
43+
from,
44+
to,
45+
}: GraphGuAPIParams): Promise<GraphGuApiResponse> => {
46+
const response = await fetchInstance.get<GraphGuApiResponse>(GRAPH_GU_API_PATH(gu), {
47+
params: { gu, dong, from, to },
48+
});
49+
return response.data;
50+
};

src/entities/chart/apis/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './substitute-compensations.api';
22
export * from './size-price.api';
3-
export * from './top-gu-districts.api';
3+
export * from './top-gus.api';
4+
export * from './graph-gu.api';
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { fetchInstance } from '@/shared';
22

3+
import type { Period } from '../types';
4+
35
export const SIZE_PRICE_API_PATH = '/api/graph/sizePriceIndex';
46

57
interface SizePriceApiResponse {
@@ -9,7 +11,13 @@ interface SizePriceApiResponse {
911
changerate: number;
1012
}
1113

12-
export const sizePriceApi = async (): Promise<SizePriceApiResponse[]> => {
13-
const response = await fetchInstance.get<SizePriceApiResponse[]>(SIZE_PRICE_API_PATH);
14+
export interface SizePriceAPIParams extends Period {}
15+
16+
export const sizePriceApi = async ({
17+
month = '2024-08',
18+
}: SizePriceAPIParams): Promise<SizePriceApiResponse[]> => {
19+
const response = await fetchInstance.get<SizePriceApiResponse[]>(SIZE_PRICE_API_PATH, {
20+
params: { month },
21+
});
1422
return response.data;
1523
};

src/entities/chart/apis/substitute-compensations.api.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,20 @@ interface SubstituteCompensationsApiResponse {
88
momchange: number;
99
}
1010

11-
export const substituteCompensationsApi = async (): Promise<
12-
SubstituteCompensationsApiResponse[]
13-
> => {
11+
export interface SubstituteCompensationsAPIParams {
12+
from: string;
13+
to: string;
14+
}
15+
16+
export const substituteCompensationsApi = async ({
17+
from,
18+
to,
19+
}: SubstituteCompensationsAPIParams): Promise<SubstituteCompensationsApiResponse[]> => {
1420
const response = await fetchInstance.get<SubstituteCompensationsApiResponse[]>(
1521
SUBSTITUTE_COMPENSATIONS_API_PATH,
22+
{
23+
params: { from, to },
24+
},
1625
);
1726

1827
return response.data;

src/entities/chart/apis/top-gu-districts.api.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { fetchInstance } from '@/shared';
2+
3+
import type { Period } from '../types';
4+
5+
export const TOP_GUS_API_PATH = '/api/graph/risk/top-gus';
6+
7+
export interface TopGusApiResponse {
8+
month: {
9+
year: number;
10+
month: string;
11+
monthValue: number;
12+
leapYear: boolean;
13+
};
14+
regionGu: string;
15+
riskScoreAvg: number;
16+
riskLevel: string;
17+
divergencePct: number;
18+
transSum: number;
19+
depositSum: number;
20+
}
21+
22+
export interface TopGusAPIParams extends Period {
23+
limit: number;
24+
}
25+
26+
export const topGusApi = async ({
27+
month = '2024-08',
28+
limit = 5,
29+
}: TopGusAPIParams): Promise<TopGusApiResponse[]> => {
30+
const response = await fetchInstance.get<TopGusApiResponse[]>(TOP_GUS_API_PATH, {
31+
params: { month, limit },
32+
});
33+
return response.data;
34+
};

src/entities/chart/hooks/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './useGetSubstituteCompensations';
22
export * from './useGetSizePrice';
33
export * from './useGetTopGuDistricts';
4+
export * from './useGetGraphGu';
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { useQuery } from '@tanstack/react-query';
2+
3+
import { GRAPH_GU_API_PATH, type GraphGuAPIParams, graphGuApi } from '../apis';
4+
5+
export const GraphGuQueryKey = [GRAPH_GU_API_PATH];
6+
7+
export const useGetGraphGu = ({ gu, dong, from, to, month }: GraphGuAPIParams) => {
8+
return useQuery({
9+
queryKey: GraphGuQueryKey,
10+
queryFn: () => graphGuApi({ gu, dong, from, to, month }),
11+
});
12+
};
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { useQuery } from '@tanstack/react-query';
22

3-
import { SIZE_PRICE_API_PATH, sizePriceApi } from '../apis';
3+
import { SIZE_PRICE_API_PATH, type SizePriceAPIParams, sizePriceApi } from '../apis';
44

55
export const SizePriceQueryKey = [SIZE_PRICE_API_PATH];
66

7-
export const useGetSizePrice = () => {
7+
export const useGetSizePrice = ({ month }: SizePriceAPIParams) => {
88
return useQuery({
99
queryKey: SizePriceQueryKey,
10-
queryFn: sizePriceApi,
10+
queryFn: () => sizePriceApi({ month }),
1111
});
1212
};

0 commit comments

Comments
 (0)