Skip to content

Commit

Permalink
Merge pull request #877 from KEEPER31337/feature/libraryApi_쿼리키_포맷_통일…
Browse files Browse the repository at this point in the history
…_#866

refactor :  query key 수정
  • Loading branch information
pipisebastian authored Jan 18, 2024
2 parents 7e941a5 + 6d50e5e commit 54dce76
Showing 1 changed file with 20 additions and 13 deletions.
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

0 comments on commit 54dce76

Please sign in to comment.