Skip to content

Commit

Permalink
refactor : 쿼리키 객체 백엔드 네이밍에 맞게 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
pipisebastian committed Jan 16, 2024
1 parent 15f9432 commit 7e0ff77
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/api/libraryApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import axios from 'axios';
import { BookInfo, BorrowedBookInfo, BookListSearch, PageAndSize } from './dto';

const libraryKeys = {
bookList: (params: BookListSearch) => ['bookList', params] as const,
borrowedBookList: ['borrowedBookList'] as const,
base: ['books'],
bookList: (params: BookListSearch) => [...libraryKeys.base, params] as const,
borrowedBookList: () => [...libraryKeys.base, 'bookBorrows'] as const,
};

const useGetBookListQuery = ({ page, size = 6, searchType, search }: BookListSearch) => {
Expand All @@ -27,7 +28,7 @@ const useGetBorrowedBookListQuery = ({ page, size }: PageAndSize) => {
axios.get(`/books/book-borrows`, { params }).then(({ data }) => {
return { content: data.content, totalElement: data.totalElements };
});
return useQuery<{ content: BorrowedBookInfo[]; totalElement: number }>(libraryKeys.borrowedBookList, fetcher);
return useQuery<{ content: BorrowedBookInfo[]; totalElement: number }>(libraryKeys.borrowedBookList(), fetcher);
};

const useRequestBorrowBookMutation = () => {
Expand All @@ -37,7 +38,7 @@ const useRequestBorrowBookMutation = () => {
return useMutation(fetcher, {
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: libraryKeys.bookList({}) });
queryClient.invalidateQueries({ queryKey: libraryKeys.borrowedBookList });
queryClient.invalidateQueries({ queryKey: libraryKeys.borrowedBookList() });
},
});
};
Expand All @@ -48,7 +49,7 @@ const useRequestReturnBookMutation = () => {

return useMutation(fetcher, {
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: libraryKeys.borrowedBookList });
queryClient.invalidateQueries({ queryKey: libraryKeys.borrowedBookList() });
},
});
};
Expand All @@ -59,7 +60,7 @@ const useCancelReturnBookMutation = () => {

return useMutation(fetcher, {
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: libraryKeys.borrowedBookList });
queryClient.invalidateQueries({ queryKey: libraryKeys.borrowedBookList() });
},
});
};
Expand All @@ -71,7 +72,7 @@ const useCancelBorrowBookMutation = () => {

return useMutation(fetcher, {
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: libraryKeys.borrowedBookList });
queryClient.invalidateQueries({ queryKey: libraryKeys.borrowedBookList() });
},
});
};
Expand Down

0 comments on commit 7e0ff77

Please sign in to comment.