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 ] 문제 목록 조회 API 연결 #224

Merged
merged 8 commits into from
Nov 27, 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
73 changes: 72 additions & 1 deletion src/api/problems/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { kyInstance } from "@/api";
import type { ProblemContent, ProblemRequest } from "@/api/problems/type";
import type {
EditProblemRequest,
GetProblemRequest,
ProblemContent,
ProblemListResponse,
ProblemRequest,
} from "@/api/problems/type";

export const getProblemInfo = async (problemId: number) => {
const response = await kyInstance
Expand All @@ -21,3 +27,68 @@ export const deleteProblem = (problemId: number) => {

return response;
};

export const getDeadlineReachedProblems = async (groupId: number) => {
const response = await kyInstance
.get<ProblemContent[]>(`api/groups/${groupId}/problems/deadline-reached`)
.json();

return response;
};

export const getInProgressProblems = async ({
groupId,
page,
size,
}: GetProblemRequest) => {
const response = await kyInstance
.get<ProblemListResponse>(
`api/groups/${groupId}/problems/in-progress?page=${page}&size=${size}`,
)
.json();

return response;
};

export const getExpiredProblems = async ({
groupId,
page,
size,
}: GetProblemRequest) => {
const response = await kyInstance
.get<ProblemListResponse>(
`api/groups/${groupId}/problems/expired?page=${page}&size=${size}`,
)
.json();

return response;
};

export const getQueuedProblems = async ({
groupId,
page,
size,
}: GetProblemRequest) => {
const response = await kyInstance
.get<ProblemListResponse>(
`api/groups/${groupId}/problems/queued?page=${page}&size=${size}`,
)
.json();

return response;
};

export const patchProblem = async ({
problemId,
startDate,
endDate,
}: EditProblemRequest) => {
const response = await kyInstance.patch<EditProblemRequest>(
`api/problems/${problemId}`,
{
json: { startDate, endDate },
},
);

return response;
};
23 changes: 13 additions & 10 deletions src/api/problems/type.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { PaginationResponse } from "@/api/type";

export type ProblemStatus = "inProgressProblems" | "expiredProblems";

export type ProblemContent = {
Expand All @@ -14,14 +16,9 @@ export type ProblemContent = {
inProgress?: boolean;
};

export type ProblemResponse = ProblemContent[];
export type ProblemListResponse = {
[key in ProblemStatus]: ProblemContent[];
} & {
currentPage: number;
totalPages: number;
totalItems: number;
};
content: ProblemContent[];
} & PaginationResponse;

export type ProblemRequest = {
link: string;
Expand All @@ -30,7 +27,13 @@ export type ProblemRequest = {
};

export type EditProblemRequest = {
problemId: number;
startDate: string;
endDate: string;
problemId?: number;
startDate: Date;
endDate: Date;
};

export type GetProblemRequest = {
groupId: number;
page: number;
size: number;
};
2 changes: 1 addition & 1 deletion src/api/users/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const getUsers = async (userNickname: string) => {
return response;
};

export const getMe = async () => {
export const getMyInfo = async () => {
const response = await kyInstance.get<UserResponse>("api/users/me").json();

return response;
Expand Down
4 changes: 2 additions & 2 deletions src/app/[user]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getMe } from "@/api/users";
import { getMyInfo } from "@/api/users";
import { IcnMy, IcnPlus, IcnSquare } from "@/asset/svg";
import NavBar from "@/shared/component/NavBar";
import type { Metadata } from "next";
Expand All @@ -15,7 +15,7 @@ export default async function UserLayout({
children: React.ReactNode;
params: { user: string };
}>) {
const { nickname } = await getMe();
const { nickname } = await getMyInfo();
const isMe = nickname === user;

return (
Expand Down
11 changes: 11 additions & 0 deletions src/app/[user]/query.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { getMyInfo } from "@/api/users";
import { useSuspenseQuery } from "@tanstack/react-query";

export const useMyNicknameQuery = () => {
const { data } = useSuspenseQuery({
queryKey: ["me"],
queryFn: () => getMyInfo(),
});

return data.nickname;
};
56 changes: 10 additions & 46 deletions src/app/group/[groupId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getGroupInfo, getGroupMemberList } from "@/api/groups";
import { getAllRanking } from "@/api/groups/ranking";
import type { ProblemContent } from "@/api/problems/type";
import { getDeadlineReachedProblems } from "@/api/problems";
import { listSectionStyle, titleStyle } from "@/app/group/[groupId]/page.css";
import Sidebar from "@/common/component/Sidebar";
import ProblemList from "@/shared/component/ProblemList";
Expand All @@ -15,51 +15,15 @@ const GroupDashboardPage = async ({
const groupInfoData = getGroupInfo(+groupId);
const rankingData = getAllRanking(+groupId);
const memberData = getGroupMemberList(+groupId);
const deadlineReachedData = getDeadlineReachedProblems(+groupId);

const [groupInfo, rankingInfo, memberInfo] = await Promise.all([
groupInfoData,
rankingData,
memberData,
]);

const data: ProblemContent[] = [
{
problemId: 1,
link: "",
title: "트리에서의 동적 계획법",
startDate: "2024-10-10",
endDate: "2024-11-01",
level: 2,
solved: false,
submitMemberCount: 50,
memberCount: 200,
accuracy: 25,
},
{
problemId: 2,
link: "",
title: "트리에서의 동적 계획법",
startDate: "2024-10-10",
endDate: "2024-10-14",
level: 2,
solved: false,
submitMemberCount: 50,
memberCount: 200,
accuracy: 25,
},
{
problemId: 3,
link: "",
title: "트리에서의 동적 계획법",
startDate: "2024-10-10",
endDate: "2024-11-01",
level: 2,
solved: true,
submitMemberCount: 50,
memberCount: 200,
accuracy: 25,
},
];
const [groupInfo, rankingInfo, memberInfo, deadlineReachedInfo] =
await Promise.all([
groupInfoData,
rankingData,
memberData,
deadlineReachedData,
]);

return (
<main className={sidebarWrapper}>
Expand All @@ -73,7 +37,7 @@ const GroupDashboardPage = async ({
<section>
<ProblemList.Header />
<ProblemList>
{data.map((item) => (
{deadlineReachedInfo.map((item) => (
<ProblemList.Item key={item.problemId} {...item} />
))}
</ProblemList>
Expand Down
15 changes: 13 additions & 2 deletions src/app/group/[groupId]/problem-list/action.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use server";

import { postProblem } from "@/api/problems";
import type { ProblemRequest } from "@/api/problems/type";
import { patchProblem, postProblem } from "@/api/problems";
import type { EditProblemRequest, ProblemRequest } from "@/api/problems/type";

export type problemActionRequest = {
groupId: number;
Expand All @@ -21,5 +21,16 @@ export const postProblemAction = async ({
endDate,
};
const response = await postProblem(groupId, body);

return response;
};

export const patchProblemAction = async ({
problemId,
startDate,
endDate,
}: EditProblemRequest) => {
const response = await patchProblem({ problemId, startDate, endDate });

return response;
};
Loading