From e351f998aae92a2d8bee2093852b1d4c9af7796b Mon Sep 17 00:00:00 2001 From: marzban-dev Date: Sun, 2 Feb 2025 21:20:24 +0330 Subject: [PATCH] Create article api composable --- .../composables/api/blog/useGetArticle.ts | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 frontend/composables/api/blog/useGetArticle.ts diff --git a/frontend/composables/api/blog/useGetArticle.ts b/frontend/composables/api/blog/useGetArticle.ts new file mode 100644 index 0000000..a797974 --- /dev/null +++ b/frontend/composables/api/blog/useGetArticle.ts @@ -0,0 +1,29 @@ +// imports + +import { useQuery } from "@tanstack/vue-query"; +import { API_ENDPOINTS, QUERY_KEYS } from "~/constants"; + +// types + +export type GetArticleResponse = Article; + +const useGetArticle = (id: number | string | undefined) => { + + // state + + const { $axios: axios } = useNuxtApp(); + + // methods + + const handleGetArticle = async () => { + const { data } = await axios.get(`${API_ENDPOINTS.blog.article}/${id}`); + return data; + }; + + return useQuery({ + queryKey: [QUERY_KEYS.article, id], + queryFn: () => handleGetArticle() + }); +}; + +export default useGetArticle;