From 654eefcd3a4f77b56622a120f484f9f008c749e7 Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Mon, 9 Mar 2026 15:45:36 +0330 Subject: [PATCH] services --- src/pages/home/hooks/useHomeData.ts | 17 ++++++++++++++++- src/pages/home/service/HomeService.ts | 10 ++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/pages/home/hooks/useHomeData.ts b/src/pages/home/hooks/useHomeData.ts index 9f64ee4..a9abb4e 100644 --- a/src/pages/home/hooks/useHomeData.ts +++ b/src/pages/home/hooks/useHomeData.ts @@ -1,8 +1,23 @@ import * as api from "../service/HomeService"; -import { useMutation } from "@tanstack/react-query"; +import { useMutation, useQuery } from "@tanstack/react-query"; export const useCreateCatalog = () => { return useMutation({ mutationFn: api.createCatalog, }); }; + +export const useGetCatalog = () => { + return useQuery({ + queryKey: ["catalogs"], + queryFn: api.getCatalogs, + }); +}; + +export const useGetCatalogById = (id: string) => { + return useQuery({ + queryKey: ["catalog", id], + queryFn: () => api.getCatalogById(id), + enabled: !!id, + }); +}; diff --git a/src/pages/home/service/HomeService.ts b/src/pages/home/service/HomeService.ts index f7c45e1..45da566 100644 --- a/src/pages/home/service/HomeService.ts +++ b/src/pages/home/service/HomeService.ts @@ -5,3 +5,13 @@ export const createCatalog = async (params: CreateCatalogParamsType) => { const { data } = await axios.post("/catalogue", params); return data; }; + +export const getCatalogs = async () => { + const { data } = await axios.get("/catalogue"); + return data; +}; + +export const getCatalogById = async (id: string) => { + const { data } = await axios.get(`/catalogue/${id}`); + return data; +};