From e1413ab9bf9df895d6b46101ec3202360eab0ce9 Mon Sep 17 00:00:00 2001 From: YooJin Lee <113789141+youznn@users.noreply.github.com> Date: Tue, 27 Aug 2024 11:25:51 +0900 Subject: [PATCH] fix(fe): add score field at contestProblem (#2019) Co-authored-by: jimin9038 --- .../app/admin/contest/[id]/edit/page.tsx | 16 ++++++++++++++-- apps/frontend/app/admin/contest/create/page.tsx | 15 ++++++++++++++- apps/frontend/app/admin/contest/utils.ts | 1 + apps/frontend/components/DataTableAdmin.tsx | 5 +++-- apps/frontend/graphql/contest/mutations.ts | 4 ++-- apps/frontend/graphql/problem/queries.ts | 1 + 6 files changed, 35 insertions(+), 7 deletions(-) diff --git a/apps/frontend/app/admin/contest/[id]/edit/page.tsx b/apps/frontend/app/admin/contest/[id]/edit/page.tsx index 9755e9f602..7fa2795e36 100644 --- a/apps/frontend/app/admin/contest/[id]/edit/page.tsx +++ b/apps/frontend/app/admin/contest/[id]/edit/page.tsx @@ -119,7 +119,8 @@ export default function Page({ params }: { params: { id: string } }) { id: problem.problemId, title: problem.problem.title, order: problem.order, - difficulty: problem.problem.difficulty + difficulty: problem.problem.difficulty, + score: problem.score ?? 0 // Score 기능 완료되면 수정해주세요!! } }) localStorage.setItem( @@ -134,6 +135,10 @@ export default function Page({ params }: { params: { id: string } }) { } else { const parsedData = JSON.parse(importedProblems) if (parsedData.length > 0) { + console.log(parsedData) + parsedData.forEach((problem: ContestProblem) => { + problem.score = problem.score ?? 0 // Score 기능 완료되면 수정해주세요!! + }) setProblems(parsedData) const orderArray = parsedData.map( // eslint-disable-next-line @@ -198,7 +203,12 @@ export default function Page({ params }: { params: { id: string } }) { variables: { groupId: 1, contestId: Number(id), - problemIds + problemIdsWithScore: problems.map((problem) => { + return { + problemId: problem.id, + score: problem.score + } + }) } }) @@ -206,6 +216,8 @@ export default function Page({ params }: { params: { id: string } }) { orderArray.forEach((order: number, index: number) => { orders[order] = problemIds[index] }) + console.log(orders) + await updateContestProblemsOrder({ variables: { groupId: 1, diff --git a/apps/frontend/app/admin/contest/create/page.tsx b/apps/frontend/app/admin/contest/create/page.tsx index 61a79d40c0..0cb9be9100 100644 --- a/apps/frontend/app/admin/contest/create/page.tsx +++ b/apps/frontend/app/admin/contest/create/page.tsx @@ -69,6 +69,7 @@ export default function Page() { return } const orderArray = JSON.parse(storedData) + if (orderArray.length !== problemIds.length) { toast.error('Problem order not set') return @@ -101,14 +102,22 @@ export default function Page() { variables: { groupId: 1, contestId, - problemIds + problemIdsWithScore: problems.map((problem) => { + return { + problemId: problem.id, + score: problem.score + } + }) } + }).then(() => { + console.log('Problems imported') }) const orders: number[] = [] orderArray.forEach((order: number, index: number) => { orders[order] = problemIds[index] }) + console.log(orders, problemIds) await updateContestProblemsOrder({ variables: { groupId: 1, @@ -155,6 +164,10 @@ export default function Page() { const importedProblems = JSON.parse( localStorage.getItem('importProblems') || '[]' ) + importedProblems?.forEach((problem: ContestProblem) => { + problem.score = problem.score ?? 0 // Score 기능 완료되면 수정해주세요!! + }) + setProblems(importedProblems) // eslint-disable-next-line diff --git a/apps/frontend/app/admin/contest/utils.ts b/apps/frontend/app/admin/contest/utils.ts index 2bb8139a79..e6e7a39c87 100644 --- a/apps/frontend/app/admin/contest/utils.ts +++ b/apps/frontend/app/admin/contest/utils.ts @@ -30,4 +30,5 @@ export interface ContestProblem { title: string order: number difficulty: string + score: number } diff --git a/apps/frontend/components/DataTableAdmin.tsx b/apps/frontend/components/DataTableAdmin.tsx index 36af6e6f46..a85f2f5f3c 100644 --- a/apps/frontend/components/DataTableAdmin.tsx +++ b/apps/frontend/components/DataTableAdmin.tsx @@ -180,12 +180,13 @@ export function DataTableAdmin({ const handleImportProblems = async () => { const selectedProblems = table.getSelectedRowModel().rows as { - original: { id: number; title: string; difficulty: string } + original: { id: number; title: string; difficulty: string; score: number } }[] const problems = selectedProblems.map((problem) => ({ id: problem.original.id, title: problem.original.title, - difficulty: problem.original.difficulty + difficulty: problem.original.difficulty, + score: problem.original.score ?? 0 // Score 기능 완료되면 수정해주세요!! })) if (contestId === null) { localStorage.setItem('importProblems', JSON.stringify(problems)) diff --git a/apps/frontend/graphql/contest/mutations.ts b/apps/frontend/graphql/contest/mutations.ts index 760c7d0298..1a03581c94 100644 --- a/apps/frontend/graphql/contest/mutations.ts +++ b/apps/frontend/graphql/contest/mutations.ts @@ -56,12 +56,12 @@ const IMPORT_PROBLEMS_TO_CONTEST = gql(` mutation ImportProblemsToContest( $groupId: Int!, $contestId: Int!, - $problemIds: [Int!]! + $problemIdsWithScore: [ProblemScoreInput!]! ) { importProblemsToContest( groupId: $groupId, contestId: $contestId, - problemIds: $problemIds + problemIdsWithScore: $problemIdsWithScore ) { contestId problemId diff --git a/apps/frontend/graphql/problem/queries.ts b/apps/frontend/graphql/problem/queries.ts index 8c26b0a027..f8fe547133 100644 --- a/apps/frontend/graphql/problem/queries.ts +++ b/apps/frontend/graphql/problem/queries.ts @@ -80,6 +80,7 @@ const GET_CONTEST_PROBLEMS = gql(` query GetContestProblems($groupId: Int!, $contestId: Int!) { getContestProblems(groupId: $groupId, contestId: $contestId) { order + score problemId problem { title