diff --git a/app/(docs)/docs/[title]/page.tsx b/app/(docs)/docs/[title]/page.tsx index 6ab4de4..ecea1f4 100644 --- a/app/(docs)/docs/[title]/page.tsx +++ b/app/(docs)/docs/[title]/page.tsx @@ -3,6 +3,7 @@ import { docsQuery } from "@/services/docs/docsQuery"; import React from "react"; import { HydrationBoundary, dehydrate } from "@tanstack/react-query"; import getQueryClient from "@/app/getQueryClient"; +import Link from "next/link"; import Docs from "./Docs"; interface PageProps { @@ -18,8 +19,18 @@ const Page = async ({ params: { title } }: PageProps) => { return ( {docs.docsType} + + 버전 + - {JSON.stringify(docs)} diff --git a/app/(history)/history/[title]/History.tsx b/app/(history)/history/[title]/History.tsx new file mode 100644 index 0000000..28e1ae7 --- /dev/null +++ b/app/(history)/history/[title]/History.tsx @@ -0,0 +1,7 @@ +import React from "react"; + +const History = () => { + return
asd
; +}; + +export default History; diff --git a/app/(history)/history/[title]/detail/[id]/HistoryDetail.tsx b/app/(history)/history/[title]/detail/[id]/HistoryDetail.tsx new file mode 100644 index 0000000..cc1bc6b --- /dev/null +++ b/app/(history)/history/[title]/detail/[id]/HistoryDetail.tsx @@ -0,0 +1,7 @@ +import React from "react"; + +const HistoryDetail = () => { + return
asd
; +}; + +export default HistoryDetail; diff --git a/app/(history)/history/[title]/detail/[id]/page.tsx b/app/(history)/history/[title]/detail/[id]/page.tsx new file mode 100644 index 0000000..5bec1a1 --- /dev/null +++ b/app/(history)/history/[title]/detail/[id]/page.tsx @@ -0,0 +1,29 @@ +import Container from "@/components/Container"; +import React from "react"; +import { HydrationBoundary, dehydrate } from "@tanstack/react-query"; +import getQueryClient from "@/app/getQueryClient"; +import { historyQuery } from "@/services/history/historyQuery"; + +interface PageProps { + params: { + title: string; + }; +} + +const Page = async ({ params: { title } }: PageProps) => { + const queryClient = getQueryClient(); + const history = await queryClient.fetchQuery( + historyQuery.getDetail(title, 0), + ); + + return ( + + + {/* */} + {JSON.stringify(history)} + + + ); +}; + +export default Page; diff --git a/app/(history)/history/[title]/page.tsx b/app/(history)/history/[title]/page.tsx new file mode 100644 index 0000000..13f8ab9 --- /dev/null +++ b/app/(history)/history/[title]/page.tsx @@ -0,0 +1,39 @@ +import Container from "@/components/Container"; +import React from "react"; +import { HydrationBoundary, dehydrate } from "@tanstack/react-query"; +import getQueryClient from "@/app/getQueryClient"; +import { historyQuery } from "@/services/history/historyQuery"; +import Link from "next/link"; + +interface PageProps { + params: { + title: string; + }; +} + +const Page = async ({ params: { title } }: PageProps) => { + const queryClient = getQueryClient(); + const historyList = await queryClient.fetchQuery(historyQuery.getList(title)); + + return ( + + + + 버전디텔 + + {/* */} + {JSON.stringify(historyList)} + + + ); +}; + +export default Page; diff --git a/app/(user)/mypage/page.tsx b/app/(user)/mypage/page.tsx new file mode 100644 index 0000000..feaaa9d --- /dev/null +++ b/app/(user)/mypage/page.tsx @@ -0,0 +1,19 @@ +"use client"; + +import Container from "@/components/Container"; +import React from "react"; +import getQueryClient from "@/app/getQueryClient"; +import { userQuery } from "@/services/user/userQuery"; +import { useUserService } from "@/services/user/useUserService"; + +const Page = () => { + const { isSuccess, data } = useUserService(); + + return ( + + {isSuccess && JSON.stringify(data)} + + ); +}; + +export default Page; diff --git a/app/(user)/user/[id]/page.tsx b/app/(user)/user/[id]/page.tsx new file mode 100644 index 0000000..d94d635 --- /dev/null +++ b/app/(user)/user/[id]/page.tsx @@ -0,0 +1,26 @@ +import Container from "@/components/Container"; +import React from "react"; +import { HydrationBoundary, dehydrate } from "@tanstack/react-query"; +import getQueryClient from "@/app/getQueryClient"; +import { userQuery } from "@/services/user/userQuery"; + +interface PageProps { + params: { + id: number; + }; +} + +const Page = async ({ params: { id } }: PageProps) => { + const queryClient = getQueryClient(); + const user = await queryClient.fetchQuery(userQuery.getUser(id)); + + return ( + + + {JSON.stringify(user)} + + + ); +}; + +export default Page; diff --git a/services/.gitkeep b/services/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/services/docs/useDocsService.ts b/services/docs/useDocsService.ts index 64ef3b0..04d307e 100644 --- a/services/docs/useDocsService.ts +++ b/services/docs/useDocsService.ts @@ -1,18 +1,6 @@ -import { useMutation, useQuery } from "@tanstack/react-query"; +import { useMutation } from "@tanstack/react-query"; import { docsQuery } from "./docsQuery"; -export const useDocsList = ({ classify }: { classify: string }) => { - return useQuery(docsQuery.getList(classify)); -}; - -export const useDocs = ({ title }: { title: string }) => { - return useQuery(docsQuery.getByTitle(title)); -}; - -export const useSearch = ({ keyword }: { keyword: string }) => { - return useQuery(docsQuery.getByKeyword(keyword)); -}; - export const useCreateDocs = () => { return useMutation(docsQuery.create()); }; diff --git a/services/history/HistoryService.ts b/services/history/HistoryService.ts new file mode 100644 index 0000000..43e4c06 --- /dev/null +++ b/services/history/HistoryService.ts @@ -0,0 +1,13 @@ +import { HttpClient } from "@/apis/httpClient"; + +class HistoryService extends HttpClient { + getList(title: string) { + return this.get(`/find/${title}/version`); + } + + getDetail(title: string, id: number) { + return this.get(`/find/version/${title}/different/${id}`); + } +} + +export default new HistoryService("api/docs"); diff --git a/services/history/historyQuery.ts b/services/history/historyQuery.ts new file mode 100644 index 0000000..2c54d6c --- /dev/null +++ b/services/history/historyQuery.ts @@ -0,0 +1,19 @@ +import HistoryService from "./HistoryService"; + +const queryKeys = { + list: (title: string) => ["history", title] as const, + detail: (title: string, id: number) => + ["history", "detail", title, id] as const, +}; + +export const historyQuery = { + getList: (title: string) => ({ + queryKey: queryKeys.list(title), + queryFn: () => HistoryService.getList(title).then((r) => r.data), + }), + + getDetail: (title: string, id: number) => ({ + queryKey: queryKeys.detail(title, id), + queryFn: () => HistoryService.getDetail(title, id).then((r) => r.data), + }), +}; diff --git a/services/user/UserService.ts b/services/user/UserService.ts new file mode 100644 index 0000000..a181d0f --- /dev/null +++ b/services/user/UserService.ts @@ -0,0 +1,17 @@ +import { HttpClient } from "@/apis/httpClient"; +import { TOKEN } from "@/constants/token.constant"; +import { Storage } from "@/storage"; + +class UserService extends HttpClient { + getMyInfo() { + return this.get(`/`, { + headers: { Authorization: Storage.getItem(TOKEN.ACCESS) }, + }); + } + + getUser(id: number) { + return this.get(`/id/${id}`); + } +} + +export default new UserService("api/user"); diff --git a/services/user/useUserService.ts b/services/user/useUserService.ts new file mode 100644 index 0000000..c6937a1 --- /dev/null +++ b/services/user/useUserService.ts @@ -0,0 +1,6 @@ +import { useQuery } from "@tanstack/react-query"; +import { userQuery } from "./userQuery"; + +export const useUserService = () => { + return useQuery(userQuery.getMyInfo()); +}; diff --git a/services/user/userQuery.ts b/services/user/userQuery.ts new file mode 100644 index 0000000..021008d --- /dev/null +++ b/services/user/userQuery.ts @@ -0,0 +1,18 @@ +import UserService from "./UserService"; + +const queryKeys = { + mypage: ["mypage"] as const, + user: (id: number) => ["user", id] as const, +}; + +export const userQuery = { + getMyInfo: () => ({ + queryKey: queryKeys.mypage, + queryFn: () => UserService.getMyInfo().then((r) => r.data), + }), + + getUser: (id: number) => ({ + queryKey: queryKeys.user(id), + queryFn: () => UserService.getUser(id).then((r) => r.data), + }), +};