Skip to content

Commit

Permalink
[#557] [도서 검색] 최근 검색어 api 요청 (#587)
Browse files Browse the repository at this point in the history
* feat: storeRecentSearch api 작성

* feat: 최근 검색어 기능 추가
  • Loading branch information
hanyugeon authored and gxxrxn committed Jun 17, 2024
1 parent 3a3f263 commit 591e9a8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/apis/book/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ const bookAPI = {
publicApi.get<APIBestSellerRes>(
`/aladin-api?QueryType=Bestseller&Cover=Big`
),

storeRecentSearch: (queryKeyword: string) =>
publicApi.get(
`/service-api/books?page=1&pageSize=1&query=${queryKeyword}&isStoreRecent=true`
),
};

export default bookAPI;
10 changes: 8 additions & 2 deletions src/app/book/search/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { APIBook } from '@/types/book';

import useBookSearchQuery from '@/queries/book/useBookSearchQuery';
import { useRecentSearchListQuery } from '@/queries/book/useRecentSearchesQuery';
import bookAPI from '@/apis/book';

import SSRSafeSuspense from '@/components/SSRSafeSuspense';
import useDebounceValue from '@/hooks/useDebounce';
Expand Down Expand Up @@ -96,8 +97,13 @@ const BookSearchResult = ({ queryKeyword }: { queryKeyword: string }) => {
? bookSearchInfo.data.pages[0].totalCount
: 0;

const handleBookClick = ({ bookId }: { bookId: APIBook['bookId'] }) => {
router.push(`/book/${bookId}`);
const handleBookClick = async ({ bookId }: { bookId: APIBook['bookId'] }) => {
try {
await bookAPI.storeRecentSearch(queryKeyword);
router.push(`/book/${bookId}`);
} catch (error) {
console.error(error);
}
};

useEffect(() => {
Expand Down

0 comments on commit 591e9a8

Please sign in to comment.