Skip to content

Commit

Permalink
chore: update of endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Franqsanz committed Oct 12, 2023
1 parent 0957ad7 commit 34f8c20
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/components/RelatedPost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions src/hooks/querys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
getBooksPaginate,
getBook,
getBooksFilter,
getRelatedPost,
getMoreBooks,
postBook,
} from '../services/api';
import { keys } from '../utils/utils';
Expand Down Expand Up @@ -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,
Expand All @@ -131,5 +131,5 @@ export {
useBooksPaginate,
useBook,
useFilter,
useRelatedPost,
useMoreBooks,
};
12 changes: 6 additions & 6 deletions src/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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',
});

Expand All @@ -71,7 +71,7 @@ export {
getBook,
getBooksFilter,
getAllFilterOptions,
getRelatedPost,
getMoreBooks,
postBook,
deleteBook,
};

1 comment on commit 34f8c20

@vercel
Copy link

@vercel vercel bot commented on 34f8c20 Oct 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

xbu – ./

xbu-git-main-franqsanz.vercel.app
xbu.vercel.app
xbu-franqsanz.vercel.app

Please sign in to comment.