-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
103 changed files
with
2,811 additions
and
230 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,24 @@ | ||
import axios, { AxiosError } from 'axios'; | ||
|
||
export const instance = axios.create({ | ||
baseURL: import.meta.env.VITE_BASE_URL, | ||
timeout: 1000, | ||
withCredentials: true, | ||
}); | ||
|
||
instance.interceptors.response.use( | ||
(response) => response, | ||
async (error: AxiosError) => { | ||
const status = error.response?.status; | ||
|
||
if (status === 400) { | ||
alert('잘못된 요청입니다.'); | ||
} | ||
|
||
if (status === 403) { | ||
alert('로그인이 필요합니다.'); | ||
location.href = '/login'; | ||
} | ||
return Promise.reject(error); | ||
}, | ||
); |
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 * from './useGetLoginStatus'; |
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,55 @@ | ||
import { z } from 'zod'; | ||
|
||
export const GetLoginStatusSchema = z.object({ | ||
message: z.enum(['Authenticated', 'Not Authenticated']), | ||
nickname: z.string().nullish(), | ||
}); | ||
|
||
export type GetLoginStatus = z.infer<typeof GetLoginStatusSchema>; | ||
|
||
export const GetTestLoginSchema = z.object({ | ||
password: z.string(), | ||
username: z.string(), | ||
}); | ||
|
||
export type GetTestLogin = z.infer<typeof GetTestLoginSchema>; | ||
|
||
export const GetUserInfoSchema = z.object({ | ||
nickname: z.string(), | ||
subName: z.string(), | ||
createdAt: z.string().datetime(), | ||
email: z.string(), | ||
type: z.string(), | ||
}); | ||
|
||
export type GetUserInfo = z.infer<typeof GetUserInfoSchema>; | ||
|
||
export const PostUserNicknameSchema = z.object({ | ||
message: z.string(), | ||
date: z.string().datetime(), | ||
}); | ||
|
||
export type PostUserNickname = z.infer<typeof PostUserNicknameSchema>; | ||
|
||
export const PostLogoutSchema = z.object({ | ||
message: z.string(), | ||
}); | ||
|
||
export type PostLogout = z.infer<typeof PostLogoutSchema>; | ||
|
||
export const GetUserStockSchema = z.object({ | ||
id: z.number(), | ||
stockId: z.string(), | ||
name: z.string(), | ||
isTrading: z.boolean(), | ||
groupCode: z.string(), | ||
createdAt: z.string().datetime(), | ||
}); | ||
|
||
export type GetUserStock = z.infer<typeof GetUserStockSchema>; | ||
|
||
export const GetUserStockResponseSchema = z.object({ | ||
userStocks: z.array(GetUserStockSchema), | ||
}); | ||
|
||
export type GetUserStockResponse = z.infer<typeof GetUserStockResponseSchema>; |
16 changes: 16 additions & 0 deletions
16
packages/frontend/src/apis/queries/auth/useGetLoginStatus.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,16 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { GetLoginStatusSchema, type GetLoginStatus } from './schema'; | ||
import { get } from '@/apis/utils/get'; | ||
|
||
const getLoginStatus = () => | ||
get<GetLoginStatus>({ | ||
schema: GetLoginStatusSchema, | ||
url: '/api/auth/status', | ||
}); | ||
|
||
export const useGetLoginStatus = () => { | ||
return useQuery({ | ||
queryKey: ['loginStatus'], | ||
queryFn: getLoginStatus, | ||
}); | ||
}; |
21 changes: 21 additions & 0 deletions
21
packages/frontend/src/apis/queries/auth/useGetTestLogin.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,21 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { GetTestLoginSchema, type GetTestLogin } from './schema'; | ||
import { get } from '@/apis/utils/get'; | ||
|
||
const getTestLogin = ({ password, username }: GetTestLogin) => | ||
get({ | ||
schema: GetTestLoginSchema, | ||
url: '/api/auth/tester/login', | ||
params: { | ||
password, | ||
username, | ||
}, | ||
}); | ||
|
||
export const useGetTestLogin = ({ password, username }: GetTestLogin) => { | ||
return useQuery({ | ||
queryKey: ['testLogin', password, username], | ||
queryFn: () => getTestLogin({ password, username }), | ||
enabled: false, | ||
}); | ||
}; |
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,16 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { GetUserInfoSchema, type GetUserInfo } from './schema'; | ||
import { get } from '@/apis/utils/get'; | ||
|
||
const getUserInfo = () => | ||
get<GetUserInfo>({ | ||
schema: GetUserInfoSchema, | ||
url: '/api/user/info', | ||
}); | ||
|
||
export const useGetUserInfo = () => { | ||
return useQuery({ | ||
queryKey: ['userInfo'], | ||
queryFn: getUserInfo, | ||
}); | ||
}; |
19 changes: 19 additions & 0 deletions
19
packages/frontend/src/apis/queries/auth/useGetUserStock.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,19 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { | ||
GetUserStockResponseSchema, | ||
type GetUserStockResponse, | ||
} from './schema'; | ||
import { get } from '@/apis/utils/get'; | ||
|
||
const getUserStock = () => | ||
get<GetUserStockResponse>({ | ||
schema: GetUserStockResponseSchema, | ||
url: '/api/stock/user', | ||
}); | ||
|
||
export const useGetUserStock = () => { | ||
return useQuery({ | ||
queryKey: ['userStock'], | ||
queryFn: getUserStock, | ||
}); | ||
}; |
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,16 @@ | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { PostLogout, PostLogoutSchema } from './schema'; | ||
import { post } from '@/apis/utils/post'; | ||
|
||
const postLogout = () => | ||
post<PostLogout>({ | ||
schema: PostLogoutSchema, | ||
url: '/api/auth/logout', | ||
}); | ||
|
||
export const usePostLogout = () => { | ||
return useMutation({ | ||
mutationKey: ['logout'], | ||
mutationFn: postLogout, | ||
}); | ||
}; |
22 changes: 22 additions & 0 deletions
22
packages/frontend/src/apis/queries/auth/usePostUserNickname.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,22 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
import { PostUserNickname, PostUserNicknameSchema } from './schema'; | ||
import { post } from '@/apis/utils/post'; | ||
|
||
const postUserNickname = ({ nickname }: { nickname: string }) => | ||
post<PostUserNickname>({ | ||
params: { nickname }, | ||
schema: PostUserNicknameSchema, | ||
url: '/api/user/info', | ||
}); | ||
|
||
export const usePostUserNickname = ({ nickname }: { nickname: string }) => { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationKey: ['userNickname'], | ||
mutationFn: () => postUserNickname({ nickname }), | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ queryKey: ['userInfo'] }); | ||
}, | ||
}); | ||
}; |
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 './schema'; | ||
export * from './usePostChatLike'; |
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 { z } from 'zod'; | ||
|
||
export const GetChatLikeRequestSchema = z.object({ | ||
chatId: z.number(), | ||
}); | ||
|
||
export type GetChatLikeRequest = z.infer<typeof GetChatLikeRequestSchema>; | ||
|
||
export const GetChatLikeResponseSchema = z.object({ | ||
chatId: z.number(), | ||
stockId: z.string(), | ||
likeCount: z.number(), | ||
message: z.string(), | ||
date: z.string().datetime(), | ||
}); | ||
|
||
export type GetChatLikeResponse = z.infer<typeof GetChatLikeResponseSchema>; |
26 changes: 26 additions & 0 deletions
26
packages/frontend/src/apis/queries/chat/usePostChatLike.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,26 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
import { | ||
GetChatLikeResponseSchema, | ||
type GetChatLikeRequest, | ||
type GetChatLikeResponse, | ||
} from './schema'; | ||
import { post } from '@/apis/utils/post'; | ||
|
||
const postChatLike = ({ chatId }: GetChatLikeRequest) => | ||
post<GetChatLikeResponse>({ | ||
params: { chatId }, | ||
schema: GetChatLikeResponseSchema, | ||
url: '/api/chat/like', | ||
}); | ||
|
||
export const usePostChatLike = () => { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationKey: ['chatLike'], | ||
mutationFn: ({ chatId }: GetChatLikeRequest) => postChatLike({ chatId }), | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ queryKey: ['chatLike'] }); | ||
}, | ||
}); | ||
}; |
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 @@ | ||
export * from './useGetStockDetail'; | ||
export * from './usePostStockView'; | ||
export * from './usePostStockUser'; | ||
export * from './schema'; | ||
export * from './useGetStockOwnership'; | ||
export * from './useDeleteStockUser'; |
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,57 @@ | ||
import { z } from 'zod'; | ||
|
||
export const GetStockRequestSchema = z.object({ | ||
stockId: z.string(), | ||
}); | ||
|
||
export type GetStockRequest = z.infer<typeof GetStockRequestSchema>; | ||
|
||
export const GetStockResponseSchema = z.object({ | ||
marketCap: z.number(), | ||
name: z.string(), | ||
eps: z.number(), | ||
per: z.string(), | ||
high52w: z.number(), | ||
low52w: z.number(), | ||
}); | ||
|
||
export type GetStockResponse = z.infer<typeof GetStockResponseSchema>; | ||
|
||
export const PostStockRequestSchema = z.object({ | ||
stockId: z.string(), | ||
}); | ||
|
||
export type PostStockRequest = z.infer<typeof PostStockRequestSchema>; | ||
|
||
export const PostStockResponseSchema = z.object({ | ||
id: z.string(), | ||
message: z.string(), | ||
date: z.string().datetime(), | ||
}); | ||
|
||
export type PostStockResponse = z.infer<typeof PostStockResponseSchema>; | ||
|
||
export const GetStockOwnershipResponseSchema = z.object({ | ||
isOwner: z.boolean(), | ||
date: z.string().datetime(), | ||
}); | ||
|
||
export type GetStockOwnershipResponse = z.infer< | ||
typeof GetStockOwnershipResponseSchema | ||
>; | ||
|
||
export const DeleteStockUserRequestSchema = z.object({ | ||
stockId: z.string(), | ||
}); | ||
|
||
export type DeleteStockUserRequest = z.infer< | ||
typeof DeleteStockUserRequestSchema | ||
>; | ||
|
||
export const DeleteStockUserSchema = z.object({ | ||
id: z.string(), | ||
message: z.string(), | ||
date: z.string().datetime(), | ||
}); | ||
|
||
export type DeleteStockUser = z.infer<typeof DeleteStockUserRequestSchema>; |
25 changes: 25 additions & 0 deletions
25
packages/frontend/src/apis/queries/stock-detail/useDeleteStockUser.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,25 @@ | ||
import { useMutation, UseMutationOptions } from '@tanstack/react-query'; | ||
import { | ||
DeleteStockUserSchema, | ||
type DeleteStockUserRequest, | ||
type DeleteStockUser, | ||
} from './schema'; | ||
import { deleteRequest } from '@/apis/utils/delete'; | ||
|
||
const deleteStockUser = ({ stockId }: DeleteStockUserRequest) => | ||
deleteRequest<DeleteStockUser>({ | ||
schema: DeleteStockUserSchema, | ||
url: '/api/stock/user', | ||
data: { stockId }, | ||
}); | ||
|
||
export const useDeleteStockUser = ( | ||
options?: UseMutationOptions<DeleteStockUser, Error, DeleteStockUserRequest>, | ||
) => { | ||
return useMutation({ | ||
mutationKey: ['deleteStockUser'], | ||
mutationFn: ({ stockId }: DeleteStockUserRequest) => | ||
deleteStockUser({ stockId }), | ||
...options, | ||
}); | ||
}; |
21 changes: 21 additions & 0 deletions
21
packages/frontend/src/apis/queries/stock-detail/useGetStockDetail.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,21 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { | ||
GetStockResponseSchema, | ||
type GetStockRequest, | ||
type GetStockResponse, | ||
} from './schema'; | ||
import { get } from '@/apis/utils/get'; | ||
|
||
const getStockDetail = ({ stockId }: GetStockRequest) => | ||
get<GetStockResponse>({ | ||
schema: GetStockResponseSchema, | ||
url: `/api/stock/${stockId}/detail`, | ||
}); | ||
|
||
export const useGetStockDetail = ({ stockId }: GetStockRequest) => { | ||
return useQuery({ | ||
queryKey: ['stockDetail', stockId], | ||
queryFn: () => getStockDetail({ stockId }), | ||
enabled: !!stockId, | ||
}); | ||
}; |
Oops, something went wrong.