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

クイズバンク機能の実装 #67

Merged
merged 10 commits into from
Apr 22, 2024
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;
Z00One marked this conversation as resolved.
Show resolved Hide resolved
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)
}
Z00One marked this conversation as resolved.
Show resolved Hide resolved
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;
}
Z00One marked this conversation as resolved.
Show resolved Hide resolved
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: [
Z00One marked this conversation as resolved.
Show resolved Hide resolved
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,
Z00One marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Loading
Loading