diff --git a/src/hooks/query/useProjectQuery.ts b/src/hooks/query/useProjectQuery.ts new file mode 100644 index 00000000..e2893ff2 --- /dev/null +++ b/src/hooks/query/useProjectQuery.ts @@ -0,0 +1,22 @@ +import { useQuery } from '@tanstack/react-query'; +import { getProjectList } from '@services/projectService'; + +import type { Team } from '@/types/TeamType'; + +// Todo: Project Query CUD로직 작성하기 +export default function useReadProjects(teamId: Team['teamId']) { + const { + data: projectList = [], + isLoading: isProjectLoading, + isError: isProjectError, + error: projectError, + } = useQuery({ + queryKey: ['teams', teamId, 'projects'], + queryFn: async () => { + const { data } = await getProjectList(teamId); + return data; + }, + }); + + return { projectList, isProjectLoading, isProjectError, projectError }; +} diff --git a/src/services/projectService.ts b/src/services/projectService.ts index b89aa788..402b99b6 100644 --- a/src/services/projectService.ts +++ b/src/services/projectService.ts @@ -1,15 +1,17 @@ import { authAxios } from '@services/axiosProvider'; + import type { AxiosRequestConfig } from 'axios'; -import type { User, UserWithRole } from '@/types/UserType'; +import type { Team } from '@/types/TeamType'; import type { Project } from '@/types/ProjectType'; +import type { User, UserWithRole } from '@/types/UserType'; /** * 프로젝트에 속한 유저 목록을 검색하는 API * * @export * @async - * @param {Project['projectId']} projectId - 프로젝트 아이디 - * @param {User['nickname']} nickname - 유저 닉네임 + * @param {Project['projectId']} projectId - 프로젝트 ID + * @param {User['nickname']} nickname - 유저 닉네임 * @param {AxiosRequestConfig} [axiosConfig={}] - axios 요청 옵션 설정 객체 * @returns {Promise>} */ @@ -20,3 +22,16 @@ export async function findUserByProject( ) { return authAxios.get(`project/${projectId}/user/search?nickname=${nickname}`, axiosConfig); } + +/** + * 프로젝트 목록 조회 API + * + * @export + * @async + * @param {Team['teamId']} teamId - 팀 ID + * @param {AxiosRequestConfig} axiosConfig - axios 요청 옵션 설정 객체 + * @returns {Promise>} + */ +export async function getProjectList(teamId: Team['teamId'], axiosConfig: AxiosRequestConfig = {}) { + return authAxios.get(`team/${teamId}/project`, axiosConfig); +}