Skip to content

Commit

Permalink
Feat: #109 프로젝트 목록 조회 API를 위한 React Query 처리 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Seok93 committed Sep 5, 2024
1 parent f4a8e48 commit 7df80a0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
22 changes: 22 additions & 0 deletions src/hooks/query/useProjectQuery.ts
Original file line number Diff line number Diff line change
@@ -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 };
}
21 changes: 18 additions & 3 deletions src/services/projectService.ts
Original file line number Diff line number Diff line change
@@ -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<AxiosResponse<UserWithRole[]>>}
*/
Expand All @@ -20,3 +22,16 @@ export async function findUserByProject(
) {
return authAxios.get<UserWithRole[]>(`project/${projectId}/user/search?nickname=${nickname}`, axiosConfig);
}

/**
* 프로젝트 목록 조회 API
*
* @export
* @async
* @param {Team['teamId']} teamId - 팀 ID
* @param {AxiosRequestConfig} axiosConfig - axios 요청 옵션 설정 객체
* @returns {Promise<AxiosResponse<Project[]>>}
*/
export async function getProjectList(teamId: Team['teamId'], axiosConfig: AxiosRequestConfig = {}) {
return authAxios.get<Project[]>(`team/${teamId}/project`, axiosConfig);
}

0 comments on commit 7df80a0

Please sign in to comment.