Skip to content

Commit

Permalink
Merge pull request #67 from Z00One/feat/quiz-bank
Browse files Browse the repository at this point in the history
クイズバンク機能の実装
  • Loading branch information
Z00One authored Apr 22, 2024
2 parents 6ef6ab3 + c659a0b commit 5e6f981
Show file tree
Hide file tree
Showing 11 changed files with 822 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- CreateTable
CREATE TABLE "QuizBank" (
"id" BIGSERIAL NOT NULL,
"title" TEXT NOT NULL,
"content" JSONB NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
"u_id" BIGINT NOT NULL,
"c_id" BIGINT NOT NULL,

CONSTRAINT "QuizBank_pkey" PRIMARY KEY ("id")
);

-- AddForeignKey
ALTER TABLE "QuizBank" ADD CONSTRAINT "QuizBank_u_id_c_id_fkey" FOREIGN KEY ("u_id", "c_id") REFERENCES "ClassUser"("u_id", "c_id") ON DELETE CASCADE ON UPDATE CASCADE;
13 changes: 13 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ model ClassUser {
prompts Prompt[]
class_user_quizs ClassUserQuiz[]
quizFeedbacks QuizFeedback[]
quizBanks QuizBank[]
@@id([u_id, c_id])
Expand Down Expand Up @@ -176,4 +177,16 @@ model QuizList {
setQuiz SetQuiz @relation(fields: [s_id], references: [m_id], onDelete: Cascade)
@@id([q_id, s_id])
}

model QuizBank {
id BigInt @id @default(autoincrement())
title String
content Json
created_at DateTime @default(now())
updated_at DateTime @updatedAt
u_id BigInt
c_id BigInt
class_user ClassUser @relation(fields: [u_id, c_id], references: [u_id, c_id], onDelete: Cascade)
}
4 changes: 4 additions & 0 deletions src/common/guards/owner.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ export class OwnerGuard implements CanActivate {
u_id: BigInt(resourceinfo['u_id']),
s_id: BigInt(resourceinfo['m_id']),
});
case Prisma.ModelName.QuizBank:
return await findResource({
id: BigInt(resourceinfo['id']),
});
default:
return null;
}
Expand Down
2 changes: 2 additions & 0 deletions src/modules/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { MaterialFeedbackModule } from '@modules/material-feedback/material-feed
import { QuizModule } from '@modules/quiz/quiz.module';
import { SetQuizModule } from '@modules/set-quiz/set-quiz.module';
import { QuizFeedbackModule } from '@modules/quiz-feedback/quiz-feedback.module';
import { QuizBankModule } from '@modules/quiz-bank/quiz-bank.module';

@Module({
imports: [
Expand Down Expand Up @@ -50,6 +51,7 @@ import { QuizFeedbackModule } from '@modules/quiz-feedback/quiz-feedback.module'
QuizModule,
SetQuizModule,
QuizFeedbackModule,
QuizBankModule,
],
controllers: [AppController],
providers: [
Expand Down
12 changes: 12 additions & 0 deletions src/modules/prompt/prompt.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,16 @@ export class PromptRepository {
},
});
}

isExist(u_id: bigint, c_id: bigint, m_id: bigint) {
return this.prisma.prompt.findFirst({
where: {
m_id,
class_user: {
u_id,
c_id,
},
},
});
}
}
15 changes: 15 additions & 0 deletions src/modules/prompt/prompt.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
ConflictException,
Injectable,
NotFoundException,
} from '@nestjs/common';
Expand Down Expand Up @@ -38,6 +39,20 @@ export class PromptService {
c_id: bigint,
m_id: bigint,
) {
const isExist = await this.promptRepository.isExist(
u_id,
c_id,
m_id,
);

if (isExist) {
throw new ConflictException(
'the prompt already exists',
);
}

// TODO: 해당 자료가 class에 속해있는지 확인

const prompt = await this.promptRepository.create(
u_id,
c_id,
Expand Down
Loading

0 comments on commit 5e6f981

Please sign in to comment.