From cc7b63f69873941cfc92aaebf557923ce197b62b Mon Sep 17 00:00:00 2001 From: Z00One <9000248@g.yju.ac.kr> Date: Mon, 21 Oct 2024 13:47:53 +0900 Subject: [PATCH 1/7] =?UTF-8?q?=F0=9F=97=83=EF=B8=8F=20feat:=20Add=20Answe?= =?UTF-8?q?r=20enum=20and=20answer=20field=20to=20ClassUserQuiz?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migration.sql | 11 +++++++++++ prisma/schema.prisma | 8 ++++++++ 2 files changed, 19 insertions(+) create mode 100644 prisma/migrations/20241014054658_add_column_of_classuserquiz_table/migration.sql diff --git a/prisma/migrations/20241014054658_add_column_of_classuserquiz_table/migration.sql b/prisma/migrations/20241014054658_add_column_of_classuserquiz_table/migration.sql new file mode 100644 index 0000000..fe0d3d7 --- /dev/null +++ b/prisma/migrations/20241014054658_add_column_of_classuserquiz_table/migration.sql @@ -0,0 +1,11 @@ +/* + Warnings: + + - Added the required column `answer` to the `class_user_quizzes` table without a default value. This is not possible if the table is not empty. + +*/ +-- CreateEnum +CREATE TYPE "Answer" AS ENUM ('a', 'b', 'c', 'd'); + +-- AlterTable +ALTER TABLE "class_user_quizzes" ADD COLUMN "answer" "Answer" NOT NULL; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 6c1759c..66daf45 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -142,10 +142,18 @@ model Quiz { @@map("quizzes") } +enum Answer { + a + b + c + d +} + model ClassUserQuiz { result Boolean? created_at DateTime @default(now()) updated_at DateTime @updatedAt + answer Answer u_id BigInt @map("uid") c_id BigInt @map("cid") From 083fac0c1b3e7a93c75989a11547a1c952b4dee7 Mon Sep 17 00:00:00 2001 From: Z00One <9000248@g.yju.ac.kr> Date: Mon, 21 Oct 2024 13:50:40 +0900 Subject: [PATCH 2/7] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20Updated=20?= =?UTF-8?q?the=20references=20to=20Answer=20properties=20in=20the=20quiz?= =?UTF-8?q?=20questions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../quiz/langchain/langchain.service.ts | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/modules/quiz/langchain/langchain.service.ts b/src/modules/quiz/langchain/langchain.service.ts index 1d342ce..03c77a4 100644 --- a/src/modules/quiz/langchain/langchain.service.ts +++ b/src/modules/quiz/langchain/langchain.service.ts @@ -9,6 +9,7 @@ import { LangchainConfig } from '@common/configs/config.interface'; import { ConfigService } from '@nestjs/config'; import { ChatOpenAI } from '@langchain/openai'; import { QuizContent } from '../dto/create-update.dto'; +import { Answer } from '@prisma/client'; @Injectable() export class LangchainService { @@ -60,52 +61,52 @@ export class LangchainService { {{ question: '관계 데이터베이스 관리 시스템(RDBMS)과 NoSQL에 대한 설명으로 옳은 것은?', answer: {{ - a: 'RDBMS는 NoSQL보다 약한 스키마를 요구한다.', - b: 'NoSQL은 RDBMS보다 엄격한 일관성 모델을 보장한다.', - c: 'NoSQL은 RDBMS보다 정형 데이터를 저장하기에 적합하다.', - d: 'NoSQL 데이터 모델로 키-값(key-value), 문서 기반(document-based), 그래프 기반(graph-based) 모델이 있다.', + ${Answer.a}: 'RDBMS는 NoSQL보다 약한 스키마를 요구한다.', + ${Answer.b}: 'NoSQL은 RDBMS보다 엄격한 일관성 모델을 보장한다.', + ${Answer.c}: 'NoSQL은 RDBMS보다 정형 데이터를 저장하기에 적합하다.', + ${Answer.d}: 'NoSQL 데이터 모델로 키-값(key-value), 문서 기반(document-based), 그래프 기반(graph-based) 모델이 있다.', }}, commentary: {{ - correctAnswer: 'd', + correctAnswer: '${Answer.d}', content: 'RDBMS는 NoSQL보다 구체적이고 엄격한 스키마를 요구하며, NoSQL보다 엄격하게 일관성을 보장한다. 또 RDBMS가 정형 데이터를 저장하기에 적합하다. D는 올바른 설명이다.', }}, }}, {{ question: 'Python의 주요 특징 중 하나는 무엇인가요?', answer: {{ - a: 'Python은 정적 타이핑을 지원한다.', - b: 'Python은 객체 지향 언어이다.', - c: 'Python은 컴파일 언어이다.', - d: 'Python은 다중 스레딩을 지원하지 않는다.', + ${Answer.a}: 'Python은 정적 타이핑을 지원한다.', + ${Answer.b}: 'Python은 객체 지향 언어이다.', + ${Answer.c}: 'Python은 컴파일 언어이다.', + ${Answer.d}: 'Python은 다중 스레딩을 지원하지 않는다.', }}, commentary: {{ - correctAnswer: 'b', + correctAnswer: '${Answer.b}', content: 'Python은 객체 지향 프로그래밍을 지원하는 동적 타이핑 언어입니다. B가 올바른 설명입니다.', }}, }}, {{ question: '다음 중 프로그래밍 언어가 아닌 것은?', answer: {{ - a: 'Java', - b: 'Python', - c: 'HTML', - d: 'C++', + ${Answer.a}: 'Java', + ${Answer.b}: 'Python', + ${Answer.c}: 'HTML', + ${Answer.d}: 'C++', }}, commentary: {{ - correctAnswer: 'c', + correctAnswer: '${Answer.c}', content: 'HTML은 마크업 언어로, 프로그래밍 언어가 아닙니다. C가 올바른 설명입니다.', }} }}, {{ question: 'CSS의 주요 목적은 무엇인가요?', answer: {{ - a: '웹 페이지의 기능을 정의한다.', - b: '웹 페이지의 스타일을 정의한다.', - c: '서버와 클라이언트 간의 통신을 담당한다.', - d: '데이터베이스를 관리한다.', + ${Answer.a}: '웹 페이지의 기능을 정의한다.', + ${Answer.b}: '웹 페이지의 스타일을 정의한다.', + ${Answer.c}: '서버와 클라이언트 간의 통신을 담당한다.', + ${Answer.d}: '데이터베이스를 관리한다.', }}, commentary: {{ - correctAnswer: 'b', + correctAnswer: '${Answer.b}', content: 'CSS는 웹 페이지의 스타일을 정의하는 언어입니다. B가 올바른 설명입니다.', }} }}, From e50eabe8083855dda5f7abaeb81cb86600a63f6a Mon Sep 17 00:00:00 2001 From: Z00One <9000248@g.yju.ac.kr> Date: Mon, 21 Oct 2024 13:52:53 +0900 Subject: [PATCH 3/7] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20Add=20the?= =?UTF-8?q?=20'answer'=20field=20to=20the=20select=20query?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/set-quiz/set-quiz.repository.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/modules/set-quiz/set-quiz.repository.ts b/src/modules/set-quiz/set-quiz.repository.ts index 0d84c0f..59946d6 100644 --- a/src/modules/set-quiz/set-quiz.repository.ts +++ b/src/modules/set-quiz/set-quiz.repository.ts @@ -73,6 +73,7 @@ export class SetQuizRepository { }, select: { result: true, + answer: true, class_user: { select: { u_id: true, @@ -95,6 +96,7 @@ export class SetQuizRepository { }, select: { result: true, + answer: true, class_user: { select: { u_id: true, @@ -155,6 +157,7 @@ export class SetQuizRepository { }, select: { result: true, + answer: true, q_id: true, quizList: { select: { From ac929cef0f281a9e256ee1b436e77afa620859f7 Mon Sep 17 00:00:00 2001 From: Z00One <9000248@g.yju.ac.kr> Date: Mon, 21 Oct 2024 13:54:29 +0900 Subject: [PATCH 4/7] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20add=20answ?= =?UTF-8?q?er=20property=20to=20QuizResultEntity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/set-quiz/entity/quiz-result.entity.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/modules/set-quiz/entity/quiz-result.entity.ts b/src/modules/set-quiz/entity/quiz-result.entity.ts index 56d9a74..f7401cf 100644 --- a/src/modules/set-quiz/entity/quiz-result.entity.ts +++ b/src/modules/set-quiz/entity/quiz-result.entity.ts @@ -1,4 +1,5 @@ import { ApiProperty } from '@nestjs/swagger'; +import { Answer } from '@prisma/client'; class QuizContent { @ApiProperty({ @@ -18,6 +19,9 @@ class QuizResult { @ApiProperty() result: boolean; + + @ApiProperty() + answer: Answer; } export class QuizResultEntity { @@ -34,6 +38,7 @@ export class QuizResultEntity { question: 'What is the capital of Japan?', }, result: true, + answer: Answer.a, }, ], }) From 08ddf9b1b2d2c1a5c546f54d48817a0a17bdbcb5 Mon Sep 17 00:00:00 2001 From: Z00One <9000248@g.yju.ac.kr> Date: Mon, 21 Oct 2024 13:55:04 +0900 Subject: [PATCH 5/7] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20add=20answ?= =?UTF-8?q?er=20field=20to=20QuizResult?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/set-quiz/dto/mark.dto.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/modules/set-quiz/dto/mark.dto.ts b/src/modules/set-quiz/dto/mark.dto.ts index 57a95de..99b3b1d 100644 --- a/src/modules/set-quiz/dto/mark.dto.ts +++ b/src/modules/set-quiz/dto/mark.dto.ts @@ -13,6 +13,7 @@ import { import { ApiProperty } from '@nestjs/swagger'; import { Transform, Type } from 'class-transformer'; import { MAX_QUIZ_DATA_SIZE } from './create.dto'; +import { Answer } from '@prisma/client'; @ValidatorConstraint({ async: true }) class IsQuizResultArrayConstraint { @@ -20,8 +21,9 @@ class IsQuizResultArrayConstraint { if (!Array.isArray(value)) return false; return value.every( (v) => - typeof v.q_id === 'bigint' && - typeof v.result === 'boolean', + typeof v?.q_id === 'bigint' && + typeof v?.result === 'boolean' && + Object.values(Answer).includes(v?.answer), ); } @@ -65,6 +67,12 @@ export class QuizResult { example: true, }) result: boolean; + + @IsNotEmpty() + @ApiProperty({ + example: Answer.a, + }) + answer: Answer; } export class MarkSetQuizDto { @@ -86,6 +94,7 @@ export class MarkSetQuizDto { { q_id: 1, result: true, + answer: Answer.a, }, ], }) From a888d7d0b58ead41c3ee142ebaba7465f0c99882 Mon Sep 17 00:00:00 2001 From: Z00One <9000248@g.yju.ac.kr> Date: Mon, 21 Oct 2024 13:56:14 +0900 Subject: [PATCH 6/7] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20add=20answ?= =?UTF-8?q?er=20field=20to=20quiz=20result?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/set-quiz/set-quiz.service.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/set-quiz/set-quiz.service.ts b/src/modules/set-quiz/set-quiz.service.ts index ddab8df..e70e4a7 100644 --- a/src/modules/set-quiz/set-quiz.service.ts +++ b/src/modules/set-quiz/set-quiz.service.ts @@ -351,6 +351,7 @@ export class SetQuizService { question, }, result: r.result, + answer: r.answer, }; }); From fd44ee3e5660e6654c4520b9b79f8a6f4ba3cc1c Mon Sep 17 00:00:00 2001 From: Z00One <9000248@g.yju.ac.kr> Date: Mon, 21 Oct 2024 13:57:14 +0900 Subject: [PATCH 7/7] =?UTF-8?q?=E2=9C=85=20refactor:=20add=20answer=20fiel?= =?UTF-8?q?d=20to=20quiz=20result?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/set-quiz/set-quiz.controller.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/set-quiz/set-quiz.controller.spec.ts b/src/modules/set-quiz/set-quiz.controller.spec.ts index c5d0014..6d4b4fa 100644 --- a/src/modules/set-quiz/set-quiz.controller.spec.ts +++ b/src/modules/set-quiz/set-quiz.controller.spec.ts @@ -229,6 +229,7 @@ describe('SetQuizController', () => { { q_id: BigInt(1), result: true, + answer: 'a', }, ], });