Skip to content

Commit

Permalink
Merge pull request #57 from Team-INSERT/feat/history
Browse files Browse the repository at this point in the history
feat : history api 연결
  • Loading branch information
Ubinquitous authored Mar 10, 2024
2 parents 98d9daf + ad98be0 commit 4d3d9e1
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 2 deletions.
13 changes: 12 additions & 1 deletion app/(docs)/docs/[title]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -18,8 +19,18 @@ const Page = async ({ params: { title } }: PageProps) => {
return (
<Container title={docs.title} classify={docs.docsType}>
{docs.docsType}
<Link
href={`/history/${title}`}
style={{
width: "fit-content",
padding: "20px",
color: "white",
background: "green",
}}
>
버전
</Link>
<HydrationBoundary state={dehydrate(queryClient)}>
{JSON.stringify(docs)}
<Docs docs={docs} />
</HydrationBoundary>
</Container>
Expand Down
7 changes: 7 additions & 0 deletions app/(history)/history/[title]/History.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from "react";

const History = () => {
return <div>asd</div>;
};

export default History;
7 changes: 7 additions & 0 deletions app/(history)/history/[title]/detail/[id]/HistoryDetail.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from "react";

const HistoryDetail = () => {
return <div>asd</div>;
};

export default HistoryDetail;
29 changes: 29 additions & 0 deletions app/(history)/history/[title]/detail/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<Container title={title} classify={title}>
<HydrationBoundary state={dehydrate(queryClient)}>
{/* <History docs={docs} /> */}
{JSON.stringify(history)}
</HydrationBoundary>
</Container>
);
};

export default Page;
39 changes: 39 additions & 0 deletions app/(history)/history/[title]/page.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<Container title={title} classify={title}>
<HydrationBoundary state={dehydrate(queryClient)}>
<Link
href={`/history/${title}/detail/0`}
style={{
width: "fit-content",
padding: "20px",
color: "white",
background: "green",
}}
>
버전디텔
</Link>
{/* <History docs={docs} /> */}
{JSON.stringify(historyList)}
</HydrationBoundary>
</Container>
);
};

export default Page;
Empty file removed services/.gitkeep
Empty file.
2 changes: 1 addition & 1 deletion services/docs/useDocsService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMutation, useQuery } from "@tanstack/react-query";
import { useMutation } from "@tanstack/react-query";
import { docsQuery } from "./docsQuery";

export const useDocsList = ({ classify }: { classify: string }) => {
Expand Down
13 changes: 13 additions & 0 deletions services/history/HistoryService.ts
Original file line number Diff line number Diff line change
@@ -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");
19 changes: 19 additions & 0 deletions services/history/historyQuery.ts
Original file line number Diff line number Diff line change
@@ -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),
}),
};

0 comments on commit 4d3d9e1

Please sign in to comment.