Skip to content

Commit 59584ef

Browse files
Merge pull request #456 from FunD-StockProject/feat/stock-zipyo-real-api
feat: Replace mock data with real API calls in StockZipyoPanel
2 parents 7bae7de + 670af67 commit 59584ef

4 files changed

Lines changed: 82 additions & 20 deletions

File tree

src/components/Page/Stock/Tab/Zipyo/Zipyo.tsx

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { STOCK_SECTOR_MAP, StockSectorKey } from '@ts/StockSector';
21
import { getDiffText } from '@utils/Number';
32
import { deltaToCaret } from '@utils/ScoreConvert';
43
import useAboutHumanZipyo from '@components/Modal/CenterTutorial/AboutHumanZipyo/useAboutHumanZipyo';
54
import GuageChart from '@components/Search/GuageChart/GuageChart';
6-
import { useScoreQuery } from '@controllers/stocks/query';
5+
import { useScoreQuery, useStockZipyoDataQuery } from '@controllers/stocks/query';
76
import { StockDetailInfo } from '@controllers/stocks/types';
87
import { StockItemContainer } from '../../Common.Style';
98
import StockItemTitle from '../../ItemTitle';
@@ -17,25 +16,12 @@ import {
1716

1817
const StockZipyoPanel = ({ stockInfo: { stockId, country, symbolName } }: { stockInfo: StockDetailInfo }) => {
1918
const { data: stockScore } = useScoreQuery(stockId, country);
19+
const { data: zipyoData } = useStockZipyoDataQuery(stockId, country);
2020
const { Modal: AboutHumanZipyoModal, openModal: openAboutHumanZipyoModal } = useAboutHumanZipyo();
2121

22-
if (!stockScore) return null;
22+
if (!stockScore || !zipyoData) return null;
2323

24-
// 목업 데이터 (실제로는 API에서 가져와야 함)
25-
const mock: {
26-
industryType: StockSectorKey;
27-
industryAverage: number;
28-
stockRanking: number;
29-
monthlyAverage: number;
30-
} = {
31-
industryType: 'IT_SERVICE',
32-
industryAverage: 45,
33-
stockRanking: 68,
34-
monthlyAverage: 51,
35-
};
36-
37-
const { industryType, industryAverage, stockRanking, monthlyAverage } = mock;
38-
const industryName = STOCK_SECTOR_MAP[industryType].text;
24+
const { industryName, industryAverage, stockRanking, monthlyAverage } = zipyoData;
3925
const monthlyAverageDiff = stockScore.score - monthlyAverage;
4026
const monthlyAverageDiffText = getDiffText({ valueDiff: monthlyAverageDiff });
4127
const sentiment = !monthlyAverageDiff ? '유지되고' : monthlyAverageDiff > 0 ? '개선되고' : '약화되고';

src/controllers/stocks/api.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ import {
1111
fetchSearchSymbolNameMock,
1212
fetchSearchWordCloudMock,
1313
} from './mock';
14-
import { PERIOD_CODE, PopularStocks, StockDetailInfo } from './types';
14+
import {
15+
MonthlyAverageResponse,
16+
PERIOD_CODE,
17+
PopularStocks,
18+
SectorAverageResponse,
19+
SectorPercentileResponse,
20+
StockDetailInfo,
21+
} from './types';
1522

1623
export const fetchScore = async (id: number, country: string) => {
1724
if (enableMock) return fetchScoreMock;
@@ -87,3 +94,16 @@ export const fetchPopularKeywords = (country: string): Promise<string[]> => {
8794
if (enableMock) return Promise.resolve(fetchKeywordsMock);
8895
return fetchData(`/keyword/popular/${country}`);
8996
};
97+
98+
export const fetchSectorAverage = (country: string, sector: string): Promise<SectorAverageResponse> => {
99+
return fetchData(`/stock/sector/average/${country}/${sector}`);
100+
};
101+
102+
export const fetchSectorPercentile = (stockId: number): Promise<SectorPercentileResponse> => {
103+
return fetchData(`/stock/${stockId}/sector/percentile`);
104+
};
105+
106+
export const fetchMonthlyAverage = (stockId: number, yearMonth?: string): Promise<MonthlyAverageResponse> => {
107+
const queryParam = yearMonth ? `?yearMonth=${yearMonth}` : '';
108+
return fetchData(`/stock/${stockId}/average/month${queryParam}`);
109+
};

src/controllers/stocks/query.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,23 @@ import { STOCK_FETCH_FUNCTIONS, queryOptions } from '../common/query';
88
import {
99
fetchAutoComplete,
1010
fetchKeywordRankings,
11+
fetchMonthlyAverage,
1112
fetchPopularKeywords,
1213
fetchPopularStocks,
1314
fetchRelevant,
1415
fetchScore,
1516
fetchSearchKeyword,
1617
fetchSearchSymbolName,
1718
fetchSearchWordCloud,
19+
fetchSectorAverage,
20+
fetchSectorPercentile,
1821
fetchStockChart,
1922
fetchStockInfo,
2023
fetchStockSummary,
2124
fetchStockTable,
2225
} from './api';
23-
import { AutoCompleteItem, PERIOD_CODE, PopularItems, StockDetailInfo, StockInfo, StockTableInfo } from './types';
26+
import type { AutoCompleteItem, PopularItems, StockDetailInfo, StockInfo, StockTableInfo } from './types';
27+
import { PERIOD_CODE } from './types';
2428

2529
export const useSymbolNameSearchQuery = (name: string, country: StockCountryKey) => {
2630
return useQuery<StockDetailInfo>(['symbolNameSearch', name, country], () => fetchSearchSymbolName(name, country), {
@@ -291,3 +295,29 @@ export const useKeywordRankingsQuery = () => {
291295
placeholderData: [],
292296
});
293297
};
298+
299+
export const useStockZipyoDataQuery = (stockId: number, country: StockCountryKey) => {
300+
return useQuery(
301+
['stockZipyoData', stockId, country],
302+
async () => {
303+
const [sectorPercentile, monthlyAverage] = await Promise.all([
304+
fetchSectorPercentile(stockId),
305+
fetchMonthlyAverage(stockId),
306+
]);
307+
308+
const sectorAverage = await fetchSectorAverage(country, sectorPercentile.sector);
309+
310+
return {
311+
industryType: sectorPercentile.sector,
312+
industryName: sectorPercentile.sectorName,
313+
industryAverage: sectorAverage.averageScore,
314+
stockRanking: sectorPercentile.topPercent,
315+
monthlyAverage: monthlyAverage.averageScore,
316+
};
317+
},
318+
{
319+
...queryOptions,
320+
enabled: !!stockId && !!country,
321+
},
322+
);
323+
};

src/controllers/stocks/types.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,29 @@ export interface StockPreferenceStatus {
105105
isBookmarked: boolean;
106106
isNotificationOn: boolean;
107107
}
108+
109+
export interface SectorAverageResponse {
110+
sector: string;
111+
sectorName: string;
112+
averageScore: number;
113+
count: number;
114+
}
115+
116+
export interface SectorPercentileResponse {
117+
stockId: number;
118+
sector: string;
119+
sectorName: string;
120+
score: number;
121+
rank: number;
122+
total: number;
123+
topPercent: number;
124+
}
125+
126+
export interface MonthlyAverageResponse {
127+
stockId: number;
128+
symbolName: string;
129+
country: StockCountryKey;
130+
yearMonth: string;
131+
dataCount: number;
132+
averageScore: number;
133+
}

0 commit comments

Comments
 (0)