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;