-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: home mocking api 생성 및 함수 작성 (#249)
- Loading branch information
1 parent
d1602ad
commit a8ba6c2
Showing
9 changed files
with
139 additions
and
15 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { commonResolvers } from './common/common.resolvers'; | ||
import { homeResolvers } from './home/resolvers/homeResolvers'; | ||
import { homeResolvers } from './home/home.resolvers'; | ||
import { onboardingResolvers } from './onboarding/onboarding.resolvers'; | ||
|
||
export const handlers = [...homeResolvers, ...onboardingResolvers, ...commonResolvers]; |
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 was deleted.
Oops, something went wrong.
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,53 @@ | ||
import axios from 'axios'; | ||
|
||
import { | ||
DeleteCategoryReq, | ||
GetCategoryTaskReq, | ||
GetCategoryTaskRes, | ||
GetWorkTimeReq, | ||
GetWorkTimeRes, | ||
PostCreateTaskReq, | ||
PostToggleTaskStatusReq, | ||
postAddTodayTodosReq, | ||
} from '@/shared/types/api/home'; | ||
|
||
import { HOME_MOCK_URL } from '@/mocks/home/home.resolvers'; | ||
|
||
export const getCategoryTask = async ({ startDate, endDate }: GetCategoryTaskReq): Promise<GetCategoryTaskRes> => { | ||
const { data } = await axios.get(HOME_MOCK_URL.GET_CATEGORY, { | ||
params: { startDate, endDate }, | ||
}); | ||
return data; | ||
}; | ||
|
||
export const getWorkTime = async ({ targetDate }: GetWorkTimeReq): Promise<GetWorkTimeRes> => { | ||
const { data } = await axios.get(HOME_MOCK_URL.GET_WORK_TIME, { | ||
params: { targetDate }, | ||
}); | ||
return data; | ||
}; | ||
|
||
export const postAddTodayTodos = async ({ targetDate, taskList }: postAddTodayTodosReq) => { | ||
const { data } = await axios.post(HOME_MOCK_URL.POST_TIMER_START, { taskList }, { params: { targetDate } }); | ||
return data; | ||
}; | ||
|
||
export const postCreateTask = async ({ categoryId, name, startDate, endDate }: PostCreateTaskReq) => { | ||
const { data } = await axios.post( | ||
HOME_MOCK_URL.POST_CREATE_TASK.replace(':categoryId', String(categoryId)), | ||
{ name }, | ||
{ params: { startDate, endDate } }, | ||
); | ||
|
||
return data; | ||
}; | ||
|
||
export const postToggleTaskStatus = async ({ taskId }: PostToggleTaskStatusReq) => { | ||
const { data } = await axios.post(HOME_MOCK_URL.POST_TOGGLE_TASK_STATUS.replace(':taskId', String(taskId))); | ||
return data; | ||
}; | ||
|
||
export const deleteCategory = async ({ categoryId }: DeleteCategoryReq) => { | ||
const { data } = await axios.delete(HOME_MOCK_URL.DELETE_CATEGORY.replace(':categoryId', String(categoryId))); | ||
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,7 @@ | ||
import { GetCategoryTaskReq, GetWorkTimeReq } from '@/shared/types/api/home'; | ||
|
||
export const homeKeys = { | ||
task: ['task'] as const, | ||
categoryTask: ({ startDate, endDate }: GetCategoryTaskReq) => [...homeKeys.task, startDate, endDate] as const, | ||
workTime: ({ targetDate }: GetWorkTimeReq) => ['workTime', targetDate] as const, | ||
}; |
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,38 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
|
||
import { deleteCategory, postAddTodayTodos, postCreateTask, postToggleTaskStatus } from './home.api'; | ||
import { homeKeys } from './home.keys'; | ||
|
||
export const usePostAddTodayTodos = () => { | ||
return useMutation({ | ||
mutationFn: postAddTodayTodos, | ||
}); | ||
}; | ||
|
||
export const usePostCreateTask = () => { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationFn: postCreateTask, | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ queryKey: homeKeys.task }); | ||
}, | ||
}); | ||
}; | ||
|
||
export const usePostToggleTaskStatus = () => { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationFn: postToggleTaskStatus, | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ queryKey: homeKeys.task }); | ||
}, | ||
}); | ||
}; | ||
|
||
export const useDeleteCategory = () => { | ||
return useMutation({ | ||
mutationFn: deleteCategory, | ||
}); | ||
}; |
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,20 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
import type { GetCategoryTaskReq, GetWorkTimeReq } from '@/shared/types/api/home'; | ||
|
||
import { getCategoryTask, getWorkTime } from './home.api'; | ||
import { homeKeys } from './home.keys'; | ||
|
||
export const useGetCategoryTask = ({ startDate, endDate }: GetCategoryTaskReq) => { | ||
return useQuery({ | ||
queryKey: homeKeys.categoryTask({ startDate, endDate }), | ||
queryFn: () => getCategoryTask({ startDate, endDate }), | ||
}); | ||
}; | ||
|
||
export const useGetWorkTime = ({ targetDate }: GetWorkTimeReq) => { | ||
return useQuery({ | ||
queryKey: homeKeys.workTime({ targetDate }), | ||
queryFn: () => getWorkTime({ targetDate }), | ||
}); | ||
}; |
Empty file.