Skip to content

Commit

Permalink
feat(be): change contest config nullability (#1528)
Browse files Browse the repository at this point in the history
* feat: unpack contestConfig and modify request parameters nullability

* docs: update bruno docs

* chore: update test code

* fix: modify seed data

* chore: rename migration file

* chore(be): remove unused migration files

---------

Co-authored-by: Jaehyeon Kim <[email protected]>
Co-authored-by: cho-to <[email protected]>
  • Loading branch information
3 people authored Mar 25, 2024
1 parent e527c51 commit 8e311e5
Show file tree
Hide file tree
Showing 15 changed files with 112 additions and 201 deletions.
30 changes: 10 additions & 20 deletions apps/backend/apps/admin/src/contest/contest.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ const contest: Contest = {
description: 'description',
startTime,
endTime,
config: {
isVisible: true,
isRankVisible: true
},
isVisible: true,
isRankVisible: true,
createTime,
updateTime
}
Expand All @@ -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
Expand All @@ -71,10 +67,8 @@ const contestWithParticipants: ContestWithParticipants = {
description: 'description',
startTime,
endTime,
config: {
isVisible: true,
isRankVisible: true
},
isVisible: true,
isRankVisible: true,
createTime,
updateTime,
participants: 10
Expand Down Expand Up @@ -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 = {
Expand All @@ -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 = {
Expand Down
20 changes: 4 additions & 16 deletions apps/backend/apps/admin/src/contest/contest.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
})

Expand All @@ -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'
Expand All @@ -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
}
})
}
Expand Down
39 changes: 18 additions & 21 deletions apps/backend/apps/admin/src/contest/model/contest.input.ts
Original file line number Diff line number Diff line change
@@ -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 })
Expand All @@ -23,27 +14,33 @@ 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()
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
}
3 changes: 2 additions & 1 deletion apps/backend/apps/admin/src/problem/mock/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
6 changes: 2 additions & 4 deletions apps/backend/apps/client/src/contest/contest.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
30 changes: 6 additions & 24 deletions apps/backend/apps/client/src/contest/contest.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ export class ContestService {
endTime: {
gt: now
},
config: {
path: ['isVisible'],
equals: true
}
isVisible: true
},
select: contestSelectOption,
orderBy: {
Expand Down Expand Up @@ -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
},
Expand Down Expand Up @@ -211,10 +205,7 @@ export class ContestService {
title: {
contains: search
},
config: {
path: ['isVisible'],
equals: true
}
isVisible: true
},
select: contestSelectOption,
orderBy: [{ endTime: 'desc' }, { id: 'desc' }]
Expand All @@ -240,10 +231,7 @@ export class ContestService {
lte: now
},
groupId,
config: {
path: ['isVisible'],
equals: true
},
isVisible: true,
title: {
contains: search
}
Expand Down Expand Up @@ -297,10 +285,7 @@ export class ContestService {
where: {
id,
groupId,
config: {
path: ['isVisible'],
equals: true
}
isVisible: true
},
select: {
...contestSelectOption,
Expand Down Expand Up @@ -387,10 +372,7 @@ export class ContestService {
return !!(await this.prisma.contest.count({
where: {
id: contestId,
config: {
path: ['isVisible'],
equals: true
},
isVisible: true,
groupId
}
}))
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
30 changes: 13 additions & 17 deletions apps/backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down
Loading

0 comments on commit 8e311e5

Please sign in to comment.