Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor : query key 수정 #877

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions src/api/libraryManageApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,20 @@ import {
} from './dto';

const libraryManageKeys = {
bookManageList: (param: BookListSearch) => ['libraryManage', 'bookManageList', param] as const,
bookDetail: (param: number) => ['library', 'bookDetail', param] as const,
borrowInfoList: (param: BorrowInfoListSearch) => ['libraryManage', 'borrowInfoList', param] as const,
overdueInfoList: (param: BorrowInfoListSearch) => ['libraryManage', 'overdueInfoList', param] as const,
borrowLogList: (param: BorrowLogListSearch) => ['libraryManage', 'borrowLogList', param] as const,
base: ['manage'] as const,
book: () => [...libraryManageKeys.base, 'books'] as const,
borrowInfo: () => [...libraryManageKeys.base, 'borrowInfos'] as const,
bookManageList: (params: BookListSearch) => [...libraryManageKeys.book(), params] as const,
bookDetail: (bookId: number) => [...libraryManageKeys.book(), bookId] as const,
borrowInfoList: (params: BorrowInfoListSearch) => [...libraryManageKeys.borrowInfo(), params] as const,
overdueInfoList: (params: BorrowInfoListSearch) => [...libraryManageKeys.borrowInfo(), 'overdue', params] as const,
borrowLogList: (params: BorrowLogListSearch) => [...libraryManageKeys.borrowInfo(), 'logs', params] as const,
};

const useGetBookManageListQuery = ({ page, size = 10, searchType, search }: BookListSearch) => {
const params = { page, size, searchType, search };
const fetcher = () =>
axios.get('/manage/books', { params: { page, size, searchType, search } }).then(({ data }) => {
axios.get('/manage/books', { params }).then(({ data }) => {
const content = data.content.map((bookInfo: ManageBookInfo) => ({
bookId: bookInfo.bookId,
title: bookInfo.title,
Expand All @@ -35,7 +39,7 @@ const useGetBookManageListQuery = ({ page, size = 10, searchType, search }: Book
});

return useQuery<{ content: ManageBookInfo[]; totalElement: number; size: number }>(
libraryManageKeys.bookManageList({ page, size, searchType, search }),
libraryManageKeys.bookManageList(params),
fetcher,
);
};
Expand Down Expand Up @@ -113,8 +117,9 @@ const useGetBookDetailQuery = (bookId: number) => {
};

const useGetBorrowInfoListQuery = ({ page, size = 10, status, search }: BorrowInfoListSearch) => {
const params = { page, size, status, search };
const fetcher = () =>
axios.get('/manage/borrow-infos', { params: { page, size, status, search } }).then(({ data }) => {
axios.get('/manage/borrow-infos', { params }).then(({ data }) => {
const content = data.content.map((borrowInfo: BorrowInfo) => {
const borrowStatus: { [key: string]: string } = {
대출대기: '대출 신청',
Expand All @@ -134,14 +139,15 @@ const useGetBorrowInfoListQuery = ({ page, size = 10, status, search }: BorrowIn
});

return useQuery<{ content: BorrowInfo[]; totalElement: number; size: number }>(
libraryManageKeys.borrowInfoList({ page, size, status, search }),
libraryManageKeys.borrowInfoList(params),
fetcher,
);
};

const useGetOverdueInfoListQuery = ({ page, size = 10, status = 'overdue' }: BorrowInfoListSearch) => {
const params = { page, size, status };
const fetcher = () =>
axios.get('/manage/borrow-infos', { params: { page, size, status } }).then(({ data }) => {
axios.get('/manage/borrow-infos', { params }).then(({ data }) => {
const content = data.content.map((borrowInfo: BorrowInfo) => {
return {
borrowInfoId: borrowInfo.borrowInfoId,
Expand All @@ -157,7 +163,7 @@ const useGetOverdueInfoListQuery = ({ page, size = 10, status = 'overdue' }: Bor
});

return useQuery<{ content: BorrowInfo[]; totalElement: number; size: number }>(
libraryManageKeys.overdueInfoList({ page, size, status }),
libraryManageKeys.overdueInfoList(params),
fetcher,
);
};
Expand Down Expand Up @@ -204,8 +210,9 @@ const useDenyReturnMutation = () => {
};

const useGetBorrowLogListQuery = ({ page, size = 10, searchType, search }: BorrowLogListSearch) => {
const params = { page, size, searchType, search };
const fetcher = () =>
axios.get('/manage/borrow-infos/logs', { params: { page, size, searchType, search } }).then(({ data }) => {
axios.get('/manage/borrow-infos/logs', { params }).then(({ data }) => {
const content = data.content.map((borrowLogInfo: BorrowLogInfo) => {
return {
...borrowLogInfo,
Expand All @@ -227,7 +234,7 @@ const useGetBorrowLogListQuery = ({ page, size = 10, searchType, search }: Borro
});

return useQuery<{ content: BorrowLogInfo[]; totalElement: number; size: number }>(
libraryManageKeys.borrowLogList({ page, size, searchType, search }),
libraryManageKeys.borrowLogList(params),
fetcher,
);
};
Expand Down
Loading