Skip to content

Commit

Permalink
Feat: #135 일정 파일 목록 조회 API React Query 처리 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Seok93 committed Sep 18, 2024
1 parent bc7588d commit d467b1e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/hooks/query/useTaskQuery.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { createTask, findAssignees, findTaskList, updateTaskOrder } from '@services/taskService';
import { createTask, findAssignees, findTaskFiles, findTaskList, updateTaskOrder } from '@services/taskService';
import useToast from '@hooks/useToast';

import type { Task, TaskForm, TaskListWithStatus, TaskOrder } from '@/types/TaskType';
Expand Down Expand Up @@ -89,7 +89,7 @@ export function useUpdateTasksOrder(projectId: Project['projectId']) {
// 일정 수행자 목록 조회
export function useReadAssignees(projectId: Project['projectId'], taskId: Task['taskId']) {
const {
data: assigneeList,
data: assigneeList = [],
isLoading: isAssigneeLoading,
error: assigneeError,
isError: isAssigneeError,
Expand All @@ -103,3 +103,20 @@ export function useReadAssignees(projectId: Project['projectId'], taskId: Task['

return { assigneeList, isAssigneeLoading, assigneeError, isAssigneeError };
}

// 일정 파일 목록 조회
export function useReadTaskFiles(projectId: Project['projectId'], taskId: Task['taskId']) {
const {
data: taskFileList = [],
isLoading: isTaskFileLoading,
error: taskFileError,
isError: isTaskFileError,
} = useQuery({
queryKey: ['projects', projectId, 'tasks', taskId, 'files'],
queryFn: async () => {
const { data } = await findTaskFiles(projectId, taskId);
return data;
},
});
return { taskFileList, isTaskFileLoading, taskFileError, isTaskFileError };
}
19 changes: 19 additions & 0 deletions src/services/taskService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { authAxios } from '@services/axiosProvider';

import type { AxiosRequestConfig } from 'axios';
import type { TaskFile } from '@/types/FileType';
import type { Project } from '@/types/ProjectType';
import type { Assignee } from '@/types/AssigneeType';
import type { Task, TaskForm, TaskListWithStatus, TaskOrderForm } from '@/types/TaskType';
Expand Down Expand Up @@ -66,3 +67,21 @@ export async function findAssignees(
) {
return authAxios.get<Assignee[]>(`/project/${projectId}/task/${taskId}/taskuser`, axiosConfig);
}

/**
* 일정 파일 목록 조회 API
*
* @export
* @async
* @param {Project['projectId']} projectId - 프로젝트 ID
* @param {Task['taskId']} taskId - 일정 ID
* @param {AxiosRequestConfig} [axiosConfig={}] - axios 요청 옵션 설정 객체
* @returns {Promise<AxiosResponse<TaskFile[]>>}
*/
export async function findTaskFiles(
projectId: Project['projectId'],
taskId: Task['taskId'],
axiosConfig: AxiosRequestConfig = {},
) {
return authAxios.get<TaskFile[]>(`/project/${projectId}/task/${taskId}/attachment`, axiosConfig);
}

0 comments on commit d467b1e

Please sign in to comment.