Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat : user, mypage api 연결 #60

Merged
merged 4 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
19 changes: 19 additions & 0 deletions app/(user)/mypage/page.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<Container title="마이페이지" classify="유저">
{isSuccess && JSON.stringify(data)}
</Container>
);
};

export default Page;
26 changes: 26 additions & 0 deletions app/(user)/user/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<Container title={user.nickName} classify="유저">
<HydrationBoundary state={dehydrate(queryClient)}>
{JSON.stringify(user)}
</HydrationBoundary>
</Container>
);
};

export default Page;
Empty file removed services/.gitkeep
Empty file.
14 changes: 1 addition & 13 deletions services/docs/useDocsService.ts
Original file line number Diff line number Diff line change
@@ -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());
};
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),
}),
};
17 changes: 17 additions & 0 deletions services/user/UserService.ts
Original file line number Diff line number Diff line change
@@ -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");
6 changes: 6 additions & 0 deletions services/user/useUserService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { useQuery } from "@tanstack/react-query";
import { userQuery } from "./userQuery";

export const useUserService = () => {
return useQuery(userQuery.getMyInfo());
};
18 changes: 18 additions & 0 deletions services/user/userQuery.ts
Original file line number Diff line number Diff line change
@@ -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),
}),
};