From 34f8c2022ea7dbb350c53f72658afadf6a02f776 Mon Sep 17 00:00:00 2001 From: franco sanchez Date: Thu, 12 Oct 2023 12:12:18 -0300 Subject: [PATCH] chore: update of endpoints --- src/components/RelatedPost.tsx | 4 ++-- src/hooks/querys.ts | 8 ++++---- src/services/api.ts | 12 ++++++------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/components/RelatedPost.tsx b/src/components/RelatedPost.tsx index 5f3a075..2379f15 100644 --- a/src/components/RelatedPost.tsx +++ b/src/components/RelatedPost.tsx @@ -3,11 +3,11 @@ import { Flex, useColorModeValue } from '@chakra-ui/react'; import { RelatedCard } from '../components/cards/RelatedCard'; import { CardType, ReleatedBooksType } from '../components/types'; -import { useRelatedPost } from '../hooks/querys'; +import { useMoreBooks } from '../hooks/querys'; export default function RelatedPost({ currentBookId }: ReleatedBooksType) { const colorCard = useColorModeValue('gray.900', 'gray.100'); - const { data, refetch } = useRelatedPost(); + const { data, refetch } = useMoreBooks(); // Filtrar el ID que coincide con el libro que se esta viendo para evitar ver el mismo en los relacionados, // si eso pasa se hace un refetch() a la api para mostrar otros libros, diff --git a/src/hooks/querys.ts b/src/hooks/querys.ts index a90467b..0b12e9c 100644 --- a/src/hooks/querys.ts +++ b/src/hooks/querys.ts @@ -12,7 +12,7 @@ import { getBooksPaginate, getBook, getBooksFilter, - getRelatedPost, + getMoreBooks, postBook, } from '../services/api'; import { keys } from '../utils/utils'; @@ -102,10 +102,10 @@ function useFilter(query: string | undefined, param: string | undefined) { }); } -function useRelatedPost() { +function useMoreBooks() { return useQuery({ queryKey: [keys.random], - queryFn: getRelatedPost, + queryFn: getMoreBooks, suspense: true, refetchOnWindowFocus: false, cacheTime: 3000, @@ -131,5 +131,5 @@ export { useBooksPaginate, useBook, useFilter, - useRelatedPost, + useMoreBooks, }; diff --git a/src/services/api.ts b/src/services/api.ts index 5e905b3..536a21b 100644 --- a/src/services/api.ts +++ b/src/services/api.ts @@ -26,7 +26,7 @@ async function getBook(pathUrl: string | undefined) { } async function postBook(books: any) { - const post = await fetchData(`${API_URL}/books`, { + const post = await fetchData(`${API_URL}/book/post`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(books), @@ -44,20 +44,20 @@ async function getBooksFilter( return data; } -async function getRelatedPost() { - const data = await fetchData(`${API_URL}/related-post`); +async function getMoreBooks() { + const data = await fetchData(`${API_URL}/books/more-books`); return data; } async function getAllFilterOptions() { - const data = await fetchData(`${API_URL}/options`); + const data = await fetchData(`${API_URL}/books/options`); return data; } async function deleteBook(id: any) { - const data = await fetchData(`${API_URL}/book/${id}`, { + const data = await fetchData(`${API_URL}/book/delete/${id}`, { method: 'DELETE', }); @@ -71,7 +71,7 @@ export { getBook, getBooksFilter, getAllFilterOptions, - getRelatedPost, + getMoreBooks, postBook, deleteBook, };