-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
9 changed files
with
100 additions
and
26 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
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,3 @@ | ||
export * from './types'; | ||
export * from './useGetTopViews'; | ||
export * from './useGetStocksByPrice'; |
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,12 @@ | ||
export interface GetStockListRequest { | ||
limit: number; | ||
} | ||
|
||
export interface GetStockListResponse { | ||
id: string; | ||
name: string; | ||
currentPrice: number; | ||
changeRate: number; | ||
volume: number; | ||
marketCap: string; | ||
} |
29 changes: 29 additions & 0 deletions
29
packages/frontend/src/apis/queries/stocks/useGetStocksByPrice.ts
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,29 @@ | ||
import type { GetStockListRequest, GetStockListResponse } from './types'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { instance } from '@/apis/config'; | ||
|
||
const getTopGainers = async ({ | ||
limit, | ||
}: GetStockListRequest): Promise<GetStockListResponse[]> => { | ||
const { data } = await instance.get(`/api/stock/topGainers?limit=${limit}`); | ||
return data; | ||
}; | ||
|
||
const getTopLosers = async ({ | ||
limit, | ||
}: GetStockListRequest): Promise<GetStockListResponse[]> => { | ||
const { data } = await instance.get(`/api/stock/topLosers?limit=${limit}`); | ||
return data; | ||
}; | ||
|
||
export const useGetStocksByPrice = ({ | ||
limit, | ||
isGaining, | ||
}: GetStockListRequest & { isGaining: boolean }) => { | ||
return useQuery<GetStockListResponse[], Error>({ | ||
queryKey: ['stocks', isGaining], | ||
queryFn: isGaining | ||
? () => getTopGainers({ limit }) | ||
: () => getTopLosers({ limit }), | ||
}); | ||
}; |
17 changes: 17 additions & 0 deletions
17
packages/frontend/src/apis/queries/stocks/useGetTopViews.ts
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,17 @@ | ||
import type { GetStockListRequest, GetStockListResponse } from './types'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { instance } from '@/apis/config'; | ||
|
||
const getTopViews = async ({ | ||
limit, | ||
}: GetStockListRequest): Promise<GetStockListResponse[]> => { | ||
const { data } = await instance.get(`/api/stock/topViews?limit=${limit}`); | ||
return data; | ||
}; | ||
|
||
export const useGetTopViews = ({ limit }: GetStockListRequest) => { | ||
return useQuery<GetStockListResponse[], Error>({ | ||
queryKey: ['stocks', 'topViews'], | ||
queryFn: () => getTopViews({ limit }), | ||
}); | ||
}; |
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
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