diff --git a/apps/backend/apps/admin/src/contest/contest.service.spec.ts b/apps/backend/apps/admin/src/contest/contest.service.spec.ts index 984566d8bf..b11999cb8f 100644 --- a/apps/backend/apps/admin/src/contest/contest.service.spec.ts +++ b/apps/backend/apps/admin/src/contest/contest.service.spec.ts @@ -35,10 +35,8 @@ const contest: Contest = { description: 'description', startTime, endTime, - config: { - isVisible: true, - isRankVisible: true - }, + isVisible: true, + isRankVisible: true, createTime, updateTime } @@ -51,10 +49,8 @@ const contestWithCount = { description: 'description', startTime, endTime, - config: { - isVisible: true, - isRankVisible: true - }, + isVisible: true, + isRankVisible: true, createTime, updateTime, // eslint-disable-next-line @typescript-eslint/naming-convention @@ -71,10 +67,8 @@ const contestWithParticipants: ContestWithParticipants = { description: 'description', startTime, endTime, - config: { - isVisible: true, - isRankVisible: true - }, + isVisible: true, + isRankVisible: true, createTime, updateTime, participants: 10 @@ -144,10 +138,8 @@ const input = { description: 'test description', startTime: faker.date.past(), endTime: faker.date.future(), - config: { - isVisible: false, - isRankVisible: false - } + isVisible: false, + isRankVisible: false } satisfies CreateContestInput const updateInput = { @@ -156,10 +148,8 @@ const updateInput = { description: 'test description', startTime: faker.date.past(), endTime: faker.date.future(), - config: { - isVisible: false, - isRankVisible: false - } + isVisible: false, + isRankVisible: false } satisfies UpdateContestInput const db = { diff --git a/apps/backend/apps/admin/src/contest/contest.service.ts b/apps/backend/apps/admin/src/contest/contest.service.ts index 74a335056e..6939bd9341 100644 --- a/apps/backend/apps/admin/src/contest/contest.service.ts +++ b/apps/backend/apps/admin/src/contest/contest.service.ts @@ -97,14 +97,7 @@ export class ContestService { data: { createdById: userId, groupId, - title: contest.title, - description: contest.description, - startTime: contest.startTime, - endTime: contest.endTime, - config: { - isVisible: contest.config.isVisible, - isRankVisible: contest.config.isRankVisible - } + ...contest } }) @@ -124,7 +117,8 @@ export class ContestService { if (!contestFound) { throw new EntityNotExistException('contest') } - + contest.startTime = contest.startTime || contestFound.startTime + contest.endTime = contest.endTime || contestFound.endTime if (contest.startTime >= contest.endTime) { throw new UnprocessableDataException( 'The start time must be earlier than the end time' @@ -137,13 +131,7 @@ export class ContestService { }, data: { title: contest.title, - description: contest.description, - startTime: contest.startTime, - endTime: contest.endTime, - config: { - isVisible: contest.config.isVisible, - isRankVisible: contest.config.isRankVisible - } + ...contest } }) } diff --git a/apps/backend/apps/admin/src/contest/model/contest.input.ts b/apps/backend/apps/admin/src/contest/model/contest.input.ts index fe1e63c857..eb1431ba21 100644 --- a/apps/backend/apps/admin/src/contest/model/contest.input.ts +++ b/apps/backend/apps/admin/src/contest/model/contest.input.ts @@ -1,14 +1,5 @@ import { Field, GraphQLISODateTime, InputType, Int } from '@nestjs/graphql' -@InputType() -class ContestConfig { - @Field(() => Boolean, { nullable: false }) - isVisible!: boolean - - @Field(() => Boolean, { nullable: false }) - isRankVisible!: boolean -} - @InputType() export class CreateContestInput { @Field(() => String, { nullable: false }) @@ -23,8 +14,11 @@ export class CreateContestInput { @Field(() => GraphQLISODateTime, { nullable: false }) endTime!: Date - @Field(() => ContestConfig, { nullable: false }) - config!: ContestConfig + @Field(() => Boolean, { nullable: false }) + isVisible!: boolean + + @Field(() => Boolean, { nullable: false }) + isRankVisible!: boolean } @InputType() @@ -32,18 +26,21 @@ export class UpdateContestInput { @Field(() => Int, { nullable: false }) id!: number - @Field(() => String, { nullable: false }) - title!: string + @Field(() => String, { nullable: true }) + title?: string - @Field(() => String, { nullable: false }) - description!: string + @Field(() => String, { nullable: true }) + description?: string - @Field(() => GraphQLISODateTime, { nullable: false }) - startTime!: Date + @Field(() => GraphQLISODateTime, { nullable: true }) + startTime?: Date - @Field(() => GraphQLISODateTime, { nullable: false }) - endTime!: Date + @Field(() => GraphQLISODateTime, { nullable: true }) + endTime?: Date + + @Field(() => Boolean, { nullable: true }) + isVisible?: boolean - @Field(() => ContestConfig, { nullable: false }) - config!: ContestConfig + @Field(() => Boolean, { nullable: true }) + isRankVisible?: boolean } diff --git a/apps/backend/apps/admin/src/problem/mock/mock.ts b/apps/backend/apps/admin/src/problem/mock/mock.ts index 05231e9eb8..5c3c46c964 100644 --- a/apps/backend/apps/admin/src/problem/mock/mock.ts +++ b/apps/backend/apps/admin/src/problem/mock/mock.ts @@ -355,7 +355,8 @@ export const exampleContest: Contest = { description: 'example', groupId: 1, createdById: 1, - config: { isVisible: true, isRankVisible: true }, + isVisible: true, + isRankVisible: true, startTime: new Date(), endTime: new Date(), createTime: new Date(), diff --git a/apps/backend/apps/client/src/contest/contest.service.spec.ts b/apps/backend/apps/client/src/contest/contest.service.spec.ts index 023c7104b8..11d41267a6 100644 --- a/apps/backend/apps/client/src/contest/contest.service.spec.ts +++ b/apps/backend/apps/client/src/contest/contest.service.spec.ts @@ -30,10 +30,8 @@ const contest = { description: 'description', startTime: now.add(-1, 'day').toDate(), endTime: now.add(1, 'day').toDate(), - config: { - isVisible: true, - isRankVisible: true - }, + isVisible: true, + isRankVisible: true, createTime: now.add(-1, 'day').toDate(), updateTime: now.add(-1, 'day').toDate(), group: { diff --git a/apps/backend/apps/client/src/contest/contest.service.ts b/apps/backend/apps/client/src/contest/contest.service.ts index 032398d6d8..e4d99e1d56 100644 --- a/apps/backend/apps/client/src/contest/contest.service.ts +++ b/apps/backend/apps/client/src/contest/contest.service.ts @@ -59,10 +59,7 @@ export class ContestService { endTime: { gt: now }, - config: { - path: ['isVisible'], - equals: true - } + isVisible: true }, select: contestSelectOption, orderBy: { @@ -105,10 +102,7 @@ export class ContestService { restContests = await this.prisma.contest.findMany({ where: { groupId, - config: { - path: ['isVisible'], - equals: true - }, + isVisible: true, id: { notIn: registeredContestIds }, @@ -211,10 +205,7 @@ export class ContestService { title: { contains: search }, - config: { - path: ['isVisible'], - equals: true - } + isVisible: true }, select: contestSelectOption, orderBy: [{ endTime: 'desc' }, { id: 'desc' }] @@ -240,10 +231,7 @@ export class ContestService { lte: now }, groupId, - config: { - path: ['isVisible'], - equals: true - }, + isVisible: true, title: { contains: search } @@ -297,10 +285,7 @@ export class ContestService { where: { id, groupId, - config: { - path: ['isVisible'], - equals: true - } + isVisible: true }, select: { ...contestSelectOption, @@ -387,10 +372,7 @@ export class ContestService { return !!(await this.prisma.contest.count({ where: { id: contestId, - config: { - path: ['isVisible'], - equals: true - }, + isVisible: true, groupId } })) diff --git a/apps/backend/prisma/migrations/20240325124437_unpack_config_column/migration.sql b/apps/backend/prisma/migrations/20240325124437_unpack_config_column/migration.sql new file mode 100644 index 0000000000..9b92fc8650 --- /dev/null +++ b/apps/backend/prisma/migrations/20240325124437_unpack_config_column/migration.sql @@ -0,0 +1,7 @@ +/* + contest 레코드가 생기기 전에 migration함 +*/ +-- AlterTable +ALTER TABLE "contest" DROP COLUMN "config", +ADD COLUMN "isRankVisible" BOOLEAN NOT NULL DEFAULT true, +ADD COLUMN "is_visible" BOOLEAN NOT NULL DEFAULT true; diff --git a/apps/backend/prisma/schema.prisma b/apps/backend/prisma/schema.prisma index 20227bc055..4a2e10a28e 100644 --- a/apps/backend/prisma/schema.prisma +++ b/apps/backend/prisma/schema.prisma @@ -259,23 +259,19 @@ model Tag { } model Contest { - id Int @id @default(autoincrement()) - createdBy User? @relation(fields: [createdById], references: [id], onDelete: SetNull) - createdById Int? @map("created_by_id") - group Group @relation(fields: [groupId], references: [id]) - groupId Int @map("group_id") - title String - description String - startTime DateTime @map("start_time") - endTime DateTime @map("end_time") - /// config default value - /// { - /// "isVisible": true, - /// "isRankVisible": true - /// } - config Json - createTime DateTime @default(now()) @map("create_time") - updateTime DateTime @updatedAt @map("update_time") + id Int @id @default(autoincrement()) + createdBy User? @relation(fields: [createdById], references: [id], onDelete: SetNull) + createdById Int? @map("created_by_id") + group Group @relation(fields: [groupId], references: [id]) + groupId Int @map("group_id") + title String + description String + startTime DateTime @map("start_time") + endTime DateTime @map("end_time") + isVisible Boolean @default(true) @map("is_visible") + isRankVisible Boolean @default(true) + createTime DateTime @default(now()) @map("create_time") + updateTime DateTime @updatedAt @map("update_time") contestProblem ContestProblem[] contestRecord ContestRecord[] diff --git a/apps/backend/prisma/seed.ts b/apps/backend/prisma/seed.ts index 40e57805c8..cf26ca601a 100644 --- a/apps/backend/prisma/seed.ts +++ b/apps/backend/prisma/seed.ts @@ -1012,10 +1012,8 @@ const createContests = async () => { groupId: publicGroup.id, startTime: new Date('2024-01-01T00:00:00.000Z'), endTime: new Date('2028-01-01T23:59:59.000Z'), - config: { - isVisible: true, - isRankVisible: true - } + isVisible: true, + isRankVisible: true } }, { @@ -1026,10 +1024,8 @@ const createContests = async () => { groupId: publicGroup.id, startTime: new Date('2024-01-01T00:00:00.000Z'), endTime: new Date('2028-01-01T23:59:59.000Z'), - config: { - isVisible: true, - isRankVisible: true - } + isVisible: true, + isRankVisible: true } }, { @@ -1040,10 +1036,8 @@ const createContests = async () => { groupId: publicGroup.id, startTime: new Date('2024-01-01T00:00:00.000Z'), endTime: new Date('2028-01-01T23:59:59.000Z'), - config: { - isVisible: true, - isRankVisible: true - } + isVisible: true, + isRankVisible: true } }, { @@ -1054,10 +1048,8 @@ const createContests = async () => { groupId: publicGroup.id, startTime: new Date('2024-01-01T00:00:00.000Z'), endTime: new Date('2028-01-01T23:59:59.000Z'), - config: { - isVisible: true, - isRankVisible: true - } + isVisible: true, + isRankVisible: true } }, { @@ -1068,10 +1060,8 @@ const createContests = async () => { groupId: privateGroup.id, startTime: new Date('2024-01-01T00:00:00.000Z'), endTime: new Date('2028-01-01T23:59:59.000Z'), - config: { - isVisible: true, - isRankVisible: true - } + isVisible: true, + isRankVisible: true } }, // Finished Contests @@ -1083,10 +1073,8 @@ const createContests = async () => { groupId: publicGroup.id, startTime: new Date('2023-01-01T00:00:00.000Z'), endTime: new Date('2024-01-01T23:59:59.000Z'), - config: { - isVisible: true, - isRankVisible: false - } + isVisible: true, + isRankVisible: false } }, { @@ -1097,10 +1085,8 @@ const createContests = async () => { groupId: publicGroup.id, startTime: new Date('2023-01-01T00:00:00.000Z'), endTime: new Date('2024-01-01T23:59:59.000Z'), - config: { - isVisible: true, - isRankVisible: true - } + isVisible: true, + isRankVisible: true } }, { @@ -1111,10 +1097,8 @@ const createContests = async () => { groupId: publicGroup.id, startTime: new Date('2023-01-01T00:00:00.000Z'), endTime: new Date('2024-01-01T23:59:59.000Z'), - config: { - isVisible: true, - isRankVisible: false - } + isVisible: true, + isRankVisible: false } }, { @@ -1125,10 +1109,8 @@ const createContests = async () => { groupId: publicGroup.id, startTime: new Date('2023-01-01T00:00:00.000Z'), endTime: new Date('2024-01-01T23:59:59.000Z'), - config: { - isVisible: true, - isRankVisible: false - } + isVisible: true, + isRankVisible: false } }, { @@ -1139,10 +1121,8 @@ const createContests = async () => { groupId: publicGroup.id, startTime: new Date('2023-01-01T00:00:00.000Z'), endTime: new Date('2024-01-01T23:59:59.000Z'), - config: { - isVisible: true, - isRankVisible: false - } + isVisible: true, + isRankVisible: false } }, { @@ -1153,10 +1133,8 @@ const createContests = async () => { groupId: publicGroup.id, startTime: new Date('2023-01-01T00:00:00.000Z'), endTime: new Date('2024-01-01T23:59:59.000Z'), - config: { - isVisible: true, - isRankVisible: false - } + isVisible: true, + isRankVisible: false } }, { @@ -1167,10 +1145,8 @@ const createContests = async () => { groupId: publicGroup.id, startTime: new Date('2023-01-01T00:00:00.000Z'), endTime: new Date('2024-01-01T23:59:59.000Z'), - config: { - isVisible: true, - isRankVisible: false - } + isVisible: true, + isRankVisible: false } }, { @@ -1181,10 +1157,8 @@ const createContests = async () => { groupId: publicGroup.id, startTime: new Date('2023-01-01T00:00:00.000Z'), endTime: new Date('2024-01-01T23:59:59.000Z'), - config: { - isVisible: true, - isRankVisible: false - } + isVisible: true, + isRankVisible: false } }, { @@ -1195,10 +1169,8 @@ const createContests = async () => { groupId: privateGroup.id, startTime: new Date('2023-01-01T00:00:00.000Z'), endTime: new Date('2024-01-01T23:59:59.000Z'), - config: { - isVisible: true, - isRankVisible: true - } + isVisible: true, + isRankVisible: true } }, // Upcoming Contests @@ -1210,10 +1182,8 @@ const createContests = async () => { groupId: publicGroup.id, startTime: new Date('3024-01-01T00:00:00.000Z'), endTime: new Date('3025-01-01T23:59:59.000Z'), - config: { - isVisible: true, - isRankVisible: true - } + isVisible: true, + isRankVisible: true } }, { @@ -1224,10 +1194,8 @@ const createContests = async () => { groupId: publicGroup.id, startTime: new Date('3024-01-01T00:00:00.000Z'), endTime: new Date('3025-01-01T23:59:59.000Z'), - config: { - isVisible: true, - isRankVisible: true - } + isVisible: true, + isRankVisible: true } }, { @@ -1239,10 +1207,8 @@ const createContests = async () => { groupId: publicGroup.id, startTime: new Date('3024-01-01T00:00:00.000Z'), endTime: new Date('3025-01-01T23:59:59.000Z'), - config: { - isVisible: false, - isRankVisible: true - } + isVisible: false, + isRankVisible: true } }, { @@ -1253,10 +1219,8 @@ const createContests = async () => { groupId: privateGroup.id, startTime: new Date('3024-01-01T00:00:00.000Z'), endTime: new Date('3025-01-01T23:59:59.000Z'), - config: { - isVisible: true, - isRankVisible: true - } + isVisible: true, + isRankVisible: true } } ] diff --git a/collection/admin/Contest/Create Contest/Succeed.bru b/collection/admin/Contest/Create Contest/Succeed.bru index 4a0fb7823a..925d571509 100644 --- a/collection/admin/Contest/Create Contest/Succeed.bru +++ b/collection/admin/Contest/Create Contest/Succeed.bru @@ -19,10 +19,8 @@ body:graphql { description: "thisisnewcontest" startTime: "2024-01-01" endTime: "2030-01-01" - config: { - isVisible: true - isRankVisible: true - } + isVisible: true + isRankVisible: true } ) { id @@ -33,7 +31,7 @@ body:graphql { } assert { - res.body.data.createContest: isDefined + res.body.data.createContest: isDefined } docs { diff --git a/collection/admin/Contest/Create Contest/[ERR] End Time Earlier than Start Time.bru b/collection/admin/Contest/Create Contest/[ERR] End Time Earlier than Start Time.bru index 42d4703e96..ae2b21a32f 100644 --- a/collection/admin/Contest/Create Contest/[ERR] End Time Earlier than Start Time.bru +++ b/collection/admin/Contest/Create Contest/[ERR] End Time Earlier than Start Time.bru @@ -19,10 +19,8 @@ body:graphql { description: "thisisnewcontest" startTime: "2030-01-01" endTime: "2020-01-01" - config: { - isVisible: true - isRankVisible: true - } + isVisible: true + isRankVisible: true } ) { id diff --git a/collection/admin/Contest/Create Contest/[ERR] Nonexistent Group.bru b/collection/admin/Contest/Create Contest/[ERR] Nonexistent Group.bru index 1187024c73..d2389c74bc 100644 --- a/collection/admin/Contest/Create Contest/[ERR] Nonexistent Group.bru +++ b/collection/admin/Contest/Create Contest/[ERR] Nonexistent Group.bru @@ -19,10 +19,8 @@ body:graphql { description: "thisisnewcontest" startTime: "2024-01-01" endTime: "2030-01-01" - config: { - isVisible: true - isRankVisible: true - } + isVisible: true + isRankVisible: true } ) { id diff --git a/collection/admin/Contest/Update Contest/Succeed.bru b/collection/admin/Contest/Update Contest/Succeed.bru index 168dce8c60..6250e94cb9 100644 --- a/collection/admin/Contest/Update Contest/Succeed.bru +++ b/collection/admin/Contest/Update Contest/Succeed.bru @@ -13,17 +13,15 @@ post { body:graphql { mutation { updateContest( - groupId: 2 + groupId: 1 input: { id: 3 title: "Updated Contest Group 2" description: "thisisupdatedcontest" startTime: "2024-01-01" endTime: "2030-01-01" - config: { - isVisible: true - isRankVisible: true - } + isVisible: true + isRankVisible: true } ) { id diff --git a/collection/admin/Contest/Update Contest/[ERR] End Time Earlier than Start Time.bru b/collection/admin/Contest/Update Contest/[ERR] End Time Earlier than Start Time.bru index ebed5a6117..44083fdfaf 100644 --- a/collection/admin/Contest/Update Contest/[ERR] End Time Earlier than Start Time.bru +++ b/collection/admin/Contest/Update Contest/[ERR] End Time Earlier than Start Time.bru @@ -20,10 +20,8 @@ body:graphql { description: "thisisupdatedcontest" startTime: "2030-01-01" endTime: "2020-01-01" - config: { - isVisible: true - isRankVisible: true - } + isVisible: true + isRankVisible: true } ) { id diff --git a/collection/admin/Contest/Update Contest/[ERR] Nonexistent Contest.bru b/collection/admin/Contest/Update Contest/[ERR] Nonexistent Contest.bru index fc76e4cb61..3d2aefd3a1 100644 --- a/collection/admin/Contest/Update Contest/[ERR] Nonexistent Contest.bru +++ b/collection/admin/Contest/Update Contest/[ERR] Nonexistent Contest.bru @@ -20,10 +20,8 @@ body:graphql { description: "thisisupdatedcontest" startTime: "2024-01-01" endTime: "2030-01-01" - config: { - isVisible: true - isRankVisible: true - } + isVisible: true + isRankVisible: true } ) { id