diff --git a/erd/database.dbml b/erd/database.dbml index be261f3..f202cd8 100644 --- a/erd/database.dbml +++ b/erd/database.dbml @@ -44,13 +44,9 @@ Table Lecture { name varchar } -Table LectureProfessor { +Table LectureSection { + id int [pk, increment] lecture_id int [ref: > Lecture.id] - professor_id int [ref: > Professor.id] - - Indexes { - (lecture_id, professor_id) [pk] - } } Table Record { @@ -72,6 +68,5 @@ Table Record { created_at datetime user_uuid uuid [ref: > User.uuid] - lecture_id int [ref: > Lecture.id] - professor_id int [ref: > Professor.id] -} + section_id int [ref: > LectureSection.id] +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 519e702..da8513f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,7 @@ "@nestjs/core": "^10.0.0", "@nestjs/passport": "^10.0.3", "@nestjs/platform-express": "^10.0.0", - "@nestjs/swagger": "^7.3.1", + "@nestjs/swagger": "^7.4.0", "@prisma/client": "^5.15.1", "class-transformer": "^0.5.1", "class-validator": "^0.14.1", @@ -43,8 +43,8 @@ "eslint-config-prettier": "^9.0.0", "eslint-plugin-prettier": "^5.0.0", "jest": "^29.5.0", - "prettier": "^3.0.0", - "prisma": "^5.15.1", + "prettier": "^3.3.2", + "prisma": "^5.16.1", "source-map-support": "^0.5.21", "supertest": "^6.3.3", "ts-jest": "^29.1.0", @@ -1615,9 +1615,9 @@ } }, "node_modules/@microsoft/tsdoc": { - "version": "0.14.2", - "resolved": "https://registry.npmjs.org/@microsoft/tsdoc/-/tsdoc-0.14.2.tgz", - "integrity": "sha512-9b8mPpKrfeGRuhFH5iO1iwCLeIIsV6+H1sRfxbkoGXIyQE2BTsPd9zqSqQJ+pv5sJ/hT5M1zvOFL02MnEezFug==" + "version": "0.15.0", + "resolved": "https://registry.npmjs.org/@microsoft/tsdoc/-/tsdoc-0.15.0.tgz", + "integrity": "sha512-HZpPoABogPvjeJOdzCOSJsXeL/SMCBgBZMVC3X3d7YYp2gf31MfxhUoYUNwf1ERPJOnQc0wkFn9trqI6ZEdZuA==" }, "node_modules/@nestjs/axios": { "version": "3.0.2", @@ -1922,16 +1922,16 @@ "dev": true }, "node_modules/@nestjs/swagger": { - "version": "7.3.1", - "resolved": "https://registry.npmjs.org/@nestjs/swagger/-/swagger-7.3.1.tgz", - "integrity": "sha512-LUC4mr+5oAleEC/a2j8pNRh1S5xhKXJ1Gal5ZdRjt9XebQgbngXCdW7JTA9WOEcwGtFZN9EnKYdquzH971LZfw==", + "version": "7.4.0", + "resolved": "https://registry.npmjs.org/@nestjs/swagger/-/swagger-7.4.0.tgz", + "integrity": "sha512-dCiwKkRxcR7dZs5jtrGspBAe/nqJd1AYzOBTzw9iCdbq3BGrLpwokelk6lFZPe4twpTsPQqzNKBwKzVbI6AR/g==", "dependencies": { - "@microsoft/tsdoc": "^0.14.2", + "@microsoft/tsdoc": "^0.15.0", "@nestjs/mapped-types": "2.0.5", "js-yaml": "4.1.0", "lodash": "4.17.21", "path-to-regexp": "3.2.0", - "swagger-ui-dist": "5.11.2" + "swagger-ui-dist": "5.17.14" }, "peerDependencies": { "@fastify/static": "^6.0.0 || ^7.0.0", @@ -2072,48 +2072,48 @@ } }, "node_modules/@prisma/debug": { - "version": "5.15.1", - "resolved": "https://registry.npmjs.org/@prisma/debug/-/debug-5.15.1.tgz", - "integrity": "sha512-NQjdEplhXEcPvf84ghxExC+LD+iTimbg3sZvA3BhybVQIocBEBxFf9GTHhmRVPmjrWoBaYJBVgEEBXZT27JTbQ==", + "version": "5.16.1", + "resolved": "https://registry.npmjs.org/@prisma/debug/-/debug-5.16.1.tgz", + "integrity": "sha512-JsNgZAg6BD9RInLSrg7ZYzo11N7cVvYArq3fHGSD89HSgtN0VDdjV6bib7YddbcO6snzjchTiLfjeTqBjtArVQ==", "devOptional": true }, "node_modules/@prisma/engines": { - "version": "5.15.1", - "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-5.15.1.tgz", - "integrity": "sha512-1iTRxJEFvpBpEWf2bYiMG6LBBQhX7X+GA5piH+tmPWgc/v+/ElxQf2kjQxby8AErmZqtZkdoKJ7FSRjNjBPE9Q==", + "version": "5.16.1", + "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-5.16.1.tgz", + "integrity": "sha512-KkyF3eIUtBIyp5A/rJHCtwQO18OjpGgx18PzjyGcJDY/+vNgaVyuVd+TgwBgeq6NLdd1XMwRCI+58vinHsAdfA==", "devOptional": true, "hasInstallScript": true, "dependencies": { - "@prisma/debug": "5.15.1", - "@prisma/engines-version": "5.15.1-1.5675a3182f972f1a8f31d16eee6abf4fd54910e3", - "@prisma/fetch-engine": "5.15.1", - "@prisma/get-platform": "5.15.1" + "@prisma/debug": "5.16.1", + "@prisma/engines-version": "5.16.0-24.34ace0eb2704183d2c05b60b52fba5c43c13f303", + "@prisma/fetch-engine": "5.16.1", + "@prisma/get-platform": "5.16.1" } }, "node_modules/@prisma/engines-version": { - "version": "5.15.1-1.5675a3182f972f1a8f31d16eee6abf4fd54910e3", - "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-5.15.1-1.5675a3182f972f1a8f31d16eee6abf4fd54910e3.tgz", - "integrity": "sha512-7csphKGCG6n/cN1MkT1mJvQ78Ir18IknlYZ8eyEoLKdQBb0HscR/6TyPmzqrMA7Rz01K1KeXqctwAqxtA/lKQg==", + "version": "5.16.0-24.34ace0eb2704183d2c05b60b52fba5c43c13f303", + "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-5.16.0-24.34ace0eb2704183d2c05b60b52fba5c43c13f303.tgz", + "integrity": "sha512-HkT2WbfmFZ9WUPyuJHhkiADxazHg8Y4gByrTSVeb3OikP6tjQ7txtSUGu9OBOBH0C13dPKN2qqH12xKtHu/Hiw==", "devOptional": true }, "node_modules/@prisma/fetch-engine": { - "version": "5.15.1", - "resolved": "https://registry.npmjs.org/@prisma/fetch-engine/-/fetch-engine-5.15.1.tgz", - "integrity": "sha512-mj0wfsJ+mAdDp1ynT2JKxAXa+CoYMT267qF7g2Uv+oaVTI2CMfGWouMARht8T2QLTgl+gpXSFTwIYbcR+oWEtw==", + "version": "5.16.1", + "resolved": "https://registry.npmjs.org/@prisma/fetch-engine/-/fetch-engine-5.16.1.tgz", + "integrity": "sha512-oOkjaPU1lhcA/Rvr4GVfd1NLJBwExgNBE36Ueq7dr71kTMwy++a3U3oLd2ZwrV9dj9xoP6LjCcky799D9nEt4w==", "devOptional": true, "dependencies": { - "@prisma/debug": "5.15.1", - "@prisma/engines-version": "5.15.1-1.5675a3182f972f1a8f31d16eee6abf4fd54910e3", - "@prisma/get-platform": "5.15.1" + "@prisma/debug": "5.16.1", + "@prisma/engines-version": "5.16.0-24.34ace0eb2704183d2c05b60b52fba5c43c13f303", + "@prisma/get-platform": "5.16.1" } }, "node_modules/@prisma/get-platform": { - "version": "5.15.1", - "resolved": "https://registry.npmjs.org/@prisma/get-platform/-/get-platform-5.15.1.tgz", - "integrity": "sha512-oFccp7bYys+ZYkmtYzjR+0cRrGKvSuF+h5QhSkyEsYQ9kzJzQRvuWt2SiHRPt8xOQ4MTmujM+bP5uOexnnAHdQ==", + "version": "5.16.1", + "resolved": "https://registry.npmjs.org/@prisma/get-platform/-/get-platform-5.16.1.tgz", + "integrity": "sha512-R4IKnWnMkR2nUAbU5gjrPehdQYUUd7RENFD2/D+xXTNhcqczp0N+WEGQ3ViyI3+6mtVcjjNIMdnUTNyu3GxIgA==", "devOptional": true, "dependencies": { - "@prisma/debug": "5.15.1" + "@prisma/debug": "5.16.1" } }, "node_modules/@sinclair/typebox": { @@ -7355,13 +7355,13 @@ } }, "node_modules/prisma": { - "version": "5.15.1", - "resolved": "https://registry.npmjs.org/prisma/-/prisma-5.15.1.tgz", - "integrity": "sha512-pYsUVpTlYvZ6mWvZKDv9rKdUa7tlfSUJY1CVtgb8Had1pHbIm9fr1MBASccr5XnSuCUrjnvKhWNwgSYy6aCajA==", + "version": "5.16.1", + "resolved": "https://registry.npmjs.org/prisma/-/prisma-5.16.1.tgz", + "integrity": "sha512-Z1Uqodk44diztImxALgJJfNl2Uisl9xDRvqybMKEBYJLNKNhDfAHf+ZIJbZyYiBhLMbKU9cYGdDVG5IIXEnL2Q==", "devOptional": true, "hasInstallScript": true, "dependencies": { - "@prisma/engines": "5.15.1" + "@prisma/engines": "5.16.1" }, "bin": { "prisma": "build/index.js" @@ -8321,9 +8321,9 @@ } }, "node_modules/swagger-ui-dist": { - "version": "5.11.2", - "resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-5.11.2.tgz", - "integrity": "sha512-jQG0cRgJNMZ7aCoiFofnoojeSaa/+KgWaDlfgs8QN+BXoGMpxeMVY5OEnjq4OlNvF3yjftO8c9GRAgcHlO+u7A==" + "version": "5.17.14", + "resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-5.17.14.tgz", + "integrity": "sha512-CVbSfaLpstV65OnSjbXfVd6Sta3q3F7Cj/yYuvHMp1P90LztOLs6PfUnKEVAeiIVQt9u2SaPwv0LiH/OyMjHRw==" }, "node_modules/symbol-observable": { "version": "4.0.0", diff --git a/package.json b/package.json index 346da74..38f2bf6 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "@nestjs/core": "^10.0.0", "@nestjs/passport": "^10.0.3", "@nestjs/platform-express": "^10.0.0", - "@nestjs/swagger": "^7.3.1", + "@nestjs/swagger": "^7.4.0", "@prisma/client": "^5.15.1", "class-transformer": "^0.5.1", "class-validator": "^0.14.1", @@ -55,8 +55,8 @@ "eslint-config-prettier": "^9.0.0", "eslint-plugin-prettier": "^5.0.0", "jest": "^29.5.0", - "prettier": "^3.0.0", - "prisma": "^5.15.1", + "prettier": "^3.3.2", + "prisma": "^5.16.1", "source-map-support": "^0.5.21", "supertest": "^6.3.3", "ts-jest": "^29.1.0", diff --git a/prisma/migrations/20240628120236_rename_lecture_name_to_name/migration.sql b/prisma/migrations/20240628120236_rename_lecture_name_to_name/migration.sql deleted file mode 100644 index b8a5a20..0000000 --- a/prisma/migrations/20240628120236_rename_lecture_name_to_name/migration.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE "lecture" RENAME COLUMN "lecture_name" TO "name"; \ No newline at end of file diff --git a/prisma/migrations/20240711075735_add_record_like/migration.sql b/prisma/migrations/20240711075735_add_record_like/migration.sql deleted file mode 100644 index a574dff..0000000 --- a/prisma/migrations/20240711075735_add_record_like/migration.sql +++ /dev/null @@ -1,16 +0,0 @@ --- CreateTable -CREATE TABLE "record_like" ( - "id" SERIAL NOT NULL, - "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deleted_at" TIMESTAMP(3), - "user_uuid" UUID NOT NULL, - "record_id" INTEGER NOT NULL, - - CONSTRAINT "record_like_pkey" PRIMARY KEY ("id") -); - --- AddForeignKey -ALTER TABLE "record_like" ADD CONSTRAINT "record_like_user_uuid_fkey" FOREIGN KEY ("user_uuid") REFERENCES "user"("uuid") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "record_like" ADD CONSTRAINT "record_like_record_id_fkey" FOREIGN KEY ("record_id") REFERENCES "record"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/migrations/20240711082736_lecture_section/migration.sql b/prisma/migrations/20240711082736_lecture_section/migration.sql new file mode 100644 index 0000000..5a04888 --- /dev/null +++ b/prisma/migrations/20240711082736_lecture_section/migration.sql @@ -0,0 +1,80 @@ +/* + Warnings: + + - You are about to drop the column `lecture_name` on the `lecture` table. All the data in the column will be lost. + - You are about to drop the column `lecture_id` on the `record` table. All the data in the column will be lost. + - You are about to drop the column `professor_id` on the `record` table. All the data in the column will be lost. + - You are about to drop the `lecture_professor` table. If the table is not empty, all the data it contains will be lost. + - Added the required column `name` to the `lecture` table without a default value. This is not possible if the table is not empty. + - Added the required column `section_id` to the `record` table without a default value. This is not possible if the table is not empty. + +*/ +-- DropForeignKey +ALTER TABLE "lecture_professor" DROP CONSTRAINT "lecture_professor_lecture_id_fkey"; + +-- DropForeignKey +ALTER TABLE "lecture_professor" DROP CONSTRAINT "lecture_professor_professor_id_fkey"; + +-- DropForeignKey +ALTER TABLE "record" DROP CONSTRAINT "record_lecture_id_professor_id_fkey"; + +-- AlterTable +ALTER TABLE "lecture" DROP COLUMN "lecture_name", +ADD COLUMN "name" TEXT NOT NULL; + +-- AlterTable +ALTER TABLE "record" DROP COLUMN "lecture_id", +DROP COLUMN "professor_id", +ADD COLUMN "section_id" INTEGER NOT NULL; + +-- DropTable +DROP TABLE "lecture_professor"; + +-- CreateTable +CREATE TABLE "lecture_section" ( + "id" SERIAL NOT NULL, + "lecture_id" INTEGER NOT NULL, + + CONSTRAINT "lecture_section_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "record_like" ( + "id" SERIAL NOT NULL, + "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "deleted_at" TIMESTAMP(3), + "user_uuid" UUID NOT NULL, + "record_id" INTEGER NOT NULL, + + CONSTRAINT "record_like_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "_LectureSectionToProfessor" ( + "A" INTEGER NOT NULL, + "B" INTEGER NOT NULL +); + +-- CreateIndex +CREATE UNIQUE INDEX "_LectureSectionToProfessor_AB_unique" ON "_LectureSectionToProfessor"("A", "B"); + +-- CreateIndex +CREATE INDEX "_LectureSectionToProfessor_B_index" ON "_LectureSectionToProfessor"("B"); + +-- AddForeignKey +ALTER TABLE "lecture_section" ADD CONSTRAINT "lecture_section_lecture_id_fkey" FOREIGN KEY ("lecture_id") REFERENCES "lecture"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "record" ADD CONSTRAINT "record_section_id_fkey" FOREIGN KEY ("section_id") REFERENCES "lecture_section"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "record_like" ADD CONSTRAINT "record_like_user_uuid_fkey" FOREIGN KEY ("user_uuid") REFERENCES "user"("uuid") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "record_like" ADD CONSTRAINT "record_like_record_id_fkey" FOREIGN KEY ("record_id") REFERENCES "record"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "_LectureSectionToProfessor" ADD CONSTRAINT "_LectureSectionToProfessor_A_fkey" FOREIGN KEY ("A") REFERENCES "lecture_section"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "_LectureSectionToProfessor" ADD CONSTRAINT "_LectureSectionToProfessor_B_fkey" FOREIGN KEY ("B") REFERENCES "professor"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 094c1ea..3d2eec8 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -8,11 +8,15 @@ generator client { provider = "prisma-client-js" } + + datasource db { provider = "postgresql" url = env("DATABASE_URL") } + + enum Semester { SPRING SUMMER @@ -21,12 +25,16 @@ enum Semester { ALL } + + enum Recommendation { YES NO MAYBE } + + model User { uuid String @id @db.Uuid name String @@ -36,50 +44,64 @@ model User { Record Record[] RecordLike RecordLike[] + + @@map("user") + } + + model Professor { - id Int @id @default(autoincrement()) + id Int @id @default(autoincrement()) + name String - name String - LectureProfessor LectureProfessor[] + LectureSection LectureSection[] @@map("professor") + } + + model LectureCode { code String @id + lectureId Int @map("lecture_id") Lecture Lecture @relation(fields: [lectureId], references: [id]) - lectureId Int @map("lecture_id") @@map("lecture_code") + } -model Lecture { - id Int @id @default(autoincrement()) - name String @map("name") - LectureCode LectureCode[] - LectureProfessor LectureProfessor[] +model Lecture { + id Int @id @default(autoincrement()) @map("id") + name String + + LectureCode LectureCode[] + LectureSection LectureSection[] @@map("lecture") + } -model LectureProfessor { - lectureId Int @map("lecture_id") - lecture Lecture @relation(fields: [lectureId], references: [id]) - professorId Int @map("professor_id") - professor Professor @relation(fields: [professorId], references: [id]) - Record Record[] - @@id([lectureId, professorId]) - @@map("lecture_professor") +model LectureSection { + id Int @id @default(autoincrement()) + lectureId Int @map("lecture_id") + + Lecture Lecture @relation(fields: [lectureId], references: [id]) + Professor Professor[] + Record Record[] + + @@map("lecture_section") } + + model Record { id Int @id @default(autoincrement()) @@ -98,11 +120,11 @@ model Record { createdAt DateTime @default(now()) @map("created_at") - userUuid String @map("user_uuid") @db.Uuid - user User @relation(fields: [userUuid], references: [uuid]) - lectureId Int @map("lecture_id") - professorId Int @map("professor_id") - lectureProfessor LectureProfessor @relation(fields: [lectureId, professorId], references: [lectureId, professorId]) + sectionId Int @map("section_id") + userUuid String @map("user_uuid") @db.Uuid + + User User @relation(fields: [userUuid], references: [uuid]) + LectureSection LectureSection @relation(fields: [sectionId], references: [id]) RecordLike RecordLike[] @@ -121,4 +143,4 @@ model RecordLike { record Record @relation(fields: [recordId], references: [id]) @@map("record_like") -} +} \ No newline at end of file diff --git a/src/lecture/dto/req/evaluationReq.dto.ts b/src/lecture/dto/req/evaluationReq.dto.ts index 0d3227b..44edfd6 100644 --- a/src/lecture/dto/req/evaluationReq.dto.ts +++ b/src/lecture/dto/req/evaluationReq.dto.ts @@ -20,7 +20,7 @@ export class EvaluationQueryDto { @ApiProperty({ example: 1, - description: '교수 Id', + description: '강의 section Id', required: false, }) @Transform(({ value }) => { @@ -33,5 +33,5 @@ export class EvaluationQueryDto { @IsNumber() @IsInt() @IsOptional() - professorId?: number; + sectionId?: number; } diff --git a/src/lecture/dto/res/lectureRes.dto.ts b/src/lecture/dto/res/lectureRes.dto.ts index f1a1947..34e62ff 100644 --- a/src/lecture/dto/res/lectureRes.dto.ts +++ b/src/lecture/dto/res/lectureRes.dto.ts @@ -1,5 +1,5 @@ import { ApiProperty } from '@nestjs/swagger'; -import { LectureCode, Prisma, Professor } from '@prisma/client'; +import { Prisma, Professor, LectureCode } from '@prisma/client'; class ProfessorResDto implements Professor { @ApiProperty({ @@ -15,45 +15,42 @@ class ProfessorResDto implements Professor { name: string; } -class LectureProfessorResDto - implements - Prisma.LectureProfessorGetPayload<{ - include: { - professor: true; - }; - }> -{ +class LectureCodeResDto implements LectureCode { @ApiProperty({ example: '1', - description: '강의 Id', + description: '강의코드', }) - lectureId: number; + code: string; @ApiProperty({ example: 1, - description: '교수 Id', + description: '강의 id', }) - professorId: number; - - @ApiProperty({ - description: '강의 교수 Id', - type: ProfessorResDto, - }) - professor: ProfessorResDto; + lectureId: number; } -class LectureCodeResDto implements LectureCode { +class LectureSectionResDto + implements + Prisma.LectureSectionGetPayload<{ + include: { + Professor: true; + }; + }> +{ @ApiProperty({ - example: 'A0001', - description: '강의 코드', + example: 1, + description: '강의 section id', }) - code: string; + id: number; @ApiProperty({ - example: '1', - description: '강의 Id', + example: 1, + description: '강의 id', }) lectureId: number; + + @ApiProperty() + Professor: ProfessorResDto[]; } export class ExpandedLectureResDto @@ -61,20 +58,14 @@ export class ExpandedLectureResDto Prisma.LectureGetPayload<{ include: { LectureCode: true; - LectureProfessor: { + LectureSection: { include: { - professor: true; + Professor: true; }; }; }; }> { - @ApiProperty({ - description: '교수 정보', - type: [LectureProfessorResDto], - }) - LectureProfessor: LectureProfessorResDto[]; - @ApiProperty({ example: 1, description: '강의 Id', @@ -82,14 +73,19 @@ export class ExpandedLectureResDto id: number; @ApiProperty({ - description: '강의 코드', + description: '강의명', + }) + name: string; + + @ApiProperty({ + description: '강의 코드 정보', type: [LectureCodeResDto], }) LectureCode: LectureCodeResDto[]; @ApiProperty({ - example: '운영체제', - description: '강의 이름', + description: '강의 section 정보', + type: [LectureSectionResDto], }) - name: string; + LectureSection: LectureSectionResDto[]; } diff --git a/src/lecture/lecture.controller.ts b/src/lecture/lecture.controller.ts index b8ae44a..33d3065 100644 --- a/src/lecture/lecture.controller.ts +++ b/src/lecture/lecture.controller.ts @@ -14,6 +14,7 @@ import { EvaluationQueryDto } from './dto/req/evaluationReq.dto'; import { EvaluationResDto } from './dto/res/evaluationRes.dto'; import { GetAllQueryDto } from './dto/req/getAllReq.dto'; import { SearchLectureQueryDto } from './dto/req/searchReq.dto'; + @ApiTags('lecture') @UsePipes(new ValidationPipe({ transform: true })) @Controller('lecture') @@ -48,7 +49,7 @@ export class LectureController { @ApiOperation({ summary: '강좌별 강의 평균 점수 조회', description: - '강의 Id만 넣으면 전체의 평균을, 교수 Id도 같이 넣으면, 해당 교수의 평균을 조회합니다.', + 'lecture Id만 넣으면 전체의 평균을, section Id도 같이 넣으면, section의 평균을 조회합니다.', }) @ApiResponse({ type: EvaluationResDto }) @Get('evaluation') diff --git a/src/lecture/lecture.repository.ts b/src/lecture/lecture.repository.ts index 4044c4d..bcb6e6a 100644 --- a/src/lecture/lecture.repository.ts +++ b/src/lecture/lecture.repository.ts @@ -21,25 +21,23 @@ export class LectureRepository { }: GetAllQueryDto): Promise { return this.prismaService.lecture.findMany({ where: { - ...(professorName - ? { - LectureProfessor: { - some: { - professor: { - name: { - contains: professorName, - }, - }, + LectureSection: { + some: { + Professor: { + some: { + name: { + contains: professorName, }, }, - } - : {}), + }, + }, + }, }, include: { LectureCode: true, - LectureProfessor: { + LectureSection: { include: { - professor: true, + Professor: true, }, }, }, @@ -54,9 +52,9 @@ export class LectureRepository { }, include: { LectureCode: true, - LectureProfessor: { + LectureSection: { include: { - professor: true, + Professor: true, }, }, }, @@ -76,12 +74,16 @@ export class LectureRepository { async getEvaluation({ lectureId, - professorId, + sectionId, }: EvaluationQueryDto): Promise { const evaluation = await this.prismaService.record.aggregate({ where: { - lectureId, - professorId, + sectionId, + LectureSection: { + Lecture: { + id: lectureId, + }, + }, }, _avg: { difficulty: true, @@ -97,11 +99,10 @@ export class LectureRepository { } async getEvaluationDetail({ - lectureId, - professorId, + sectionId, }: EvaluationQueryDto): Promise { return this.prismaService.record.findMany({ - where: { lectureId, professorId }, + where: { sectionId }, }); } @@ -129,9 +130,9 @@ export class LectureRepository { }, include: { LectureCode: true, - LectureProfessor: { + LectureSection: { include: { - professor: true, + Professor: true, }, }, }, diff --git a/src/record/dto/req/createRecordBody.dto.ts b/src/record/dto/req/createRecordBody.dto.ts index 5e3c70a..5ec9240 100644 --- a/src/record/dto/req/createRecordBody.dto.ts +++ b/src/record/dto/req/createRecordBody.dto.ts @@ -112,10 +112,10 @@ export class CreateRecordBodyDto { lectureId: number; @ApiProperty({ - description: '교수님 id', + description: 'section id', example: 1, }) @IsNumber() @IsInt() - professorId: number; + sectionId: number; } diff --git a/src/record/dto/req/getAllRecordQuery.dto.ts b/src/record/dto/req/getAllRecordQuery.dto.ts index 2149f6f..f981411 100644 --- a/src/record/dto/req/getAllRecordQuery.dto.ts +++ b/src/record/dto/req/getAllRecordQuery.dto.ts @@ -31,7 +31,7 @@ export class GetAllRecordQueryDto extends PagenationQueryDto { lectureId?: number; @ApiProperty({ - description: 'Professor id', + description: '강의 section id', example: 1, required: false, }) @@ -45,5 +45,5 @@ export class GetAllRecordQueryDto extends PagenationQueryDto { @IsNumber() @IsInt() @IsOptional() - professorId?: number; + sectionId?: number; } diff --git a/src/record/dto/req/updateRecordBoty.dto.ts b/src/record/dto/req/updateRecordBody.dto.ts similarity index 100% rename from src/record/dto/req/updateRecordBoty.dto.ts rename to src/record/dto/req/updateRecordBody.dto.ts diff --git a/src/record/dto/res/expandedRes.dto.ts b/src/record/dto/res/expandedRes.dto.ts index 1b8c480..a17e39d 100644 --- a/src/record/dto/res/expandedRes.dto.ts +++ b/src/record/dto/res/expandedRes.dto.ts @@ -1,6 +1,7 @@ import { ApiProperty } from '@nestjs/swagger'; import { RecordResDto } from './recordRes.dto'; import { Lecture, Professor } from '@prisma/client'; +import { ExpandedRecordType } from 'src/record/types/ExpandedRecord.type'; class LectureResDto implements Lecture { @ApiProperty() @@ -18,15 +19,12 @@ class ProfessorResDto implements Professor { name: string; } -class LectureProfessorResDto { - @ApiProperty() - lecture: LectureResDto; - - @ApiProperty() - professor: ProfessorResDto; -} - -export class ExpandedRecordResDto extends RecordResDto { - @ApiProperty() - lectureProfessor: LectureProfessorResDto; +export class ExpandedRecordResDto + extends RecordResDto + implements ExpandedRecordType +{ + LectureSection: { + Lecture: LectureResDto; + Professor: ProfessorResDto[]; + } & { id: number; lectureId: number }; } diff --git a/src/record/dto/res/recordRes.dto.ts b/src/record/dto/res/recordRes.dto.ts index d748db5..b4f6651 100644 --- a/src/record/dto/res/recordRes.dto.ts +++ b/src/record/dto/res/recordRes.dto.ts @@ -48,8 +48,5 @@ export class RecordResDto implements Record { userUuid: string; @ApiProperty() - lectureId: number; - - @ApiProperty() - professorId: number; + sectionId: number; } diff --git a/src/record/record.controller.ts b/src/record/record.controller.ts index d07bc10..bccda70 100644 --- a/src/record/record.controller.ts +++ b/src/record/record.controller.ts @@ -20,7 +20,7 @@ import { IdPGuard, IdPOptionalGuard } from 'src/user/guard/idp.guard'; import { CreateRecordBodyDto } from './dto/req/createRecordBody.dto'; import { GetUser } from 'src/user/decorator/get-user.decorator'; import { User } from '@prisma/client'; -import { UpdateRecordBodyDto } from './dto/req/updateRecordBoty.dto'; +import { UpdateRecordBodyDto } from './dto/req/updateRecordBody.dto'; import { ExpandedRecordResDto } from './dto/res/expandedRes.dto'; @ApiTags('record') @@ -32,7 +32,7 @@ export class RecordController { @ApiOperation({ summary: '강의평 조회', description: - 'type이 recent면 최근 강의평을, type이 evaluation이면, professorId와 lectureId가 있으면 해당 강의평을 조회합니다. type이 user이면 유저의 강의평을 조회합니다.', + 'type이 recent면 최근 강의평을, type이 evaluation이면, lectureId, sectionId가 있으면 해당 강의평을 조회합니다. type이 user이면 유저의 강의평을 조회합니다.', }) @ApiOAuth2(['email', 'profile', 'openid'], 'oauth2') @ApiResponse({ type: [RecordResDto] }) diff --git a/src/record/record.repository.ts b/src/record/record.repository.ts index 4c2ec37..7f043fe 100644 --- a/src/record/record.repository.ts +++ b/src/record/record.repository.ts @@ -4,7 +4,7 @@ import { PrismaService } from 'src/prisma/prisma.service'; import { PagenationQueryDto } from './dto/req/pagenationQuery.dto'; import { GetAllRecordQueryDto } from './dto/req/getAllRecordQuery.dto'; import { CreateRecordBodyDto } from './dto/req/createRecordBody.dto'; -import { UpdateRecordBodyDto } from './dto/req/updateRecordBoty.dto'; +import { UpdateRecordBodyDto } from './dto/req/updateRecordBody.dto'; import { ExpandedRecordType } from './types/ExpandedRecord.type'; @Injectable() @@ -22,10 +22,10 @@ export class RecordRepository { createdAt: 'desc', }, include: { - lectureProfessor: { + LectureSection: { include: { - lecture: true, - professor: true, + Lecture: true, + Professor: true, }, }, }, @@ -46,26 +46,29 @@ export class RecordRepository { userUuid, }, include: { - lectureProfessor: { + LectureSection: { include: { - lecture: true, - professor: true, + Lecture: true, + Professor: true, }, }, }, }); } - async getRecordByLectureProfessor({ + async getRecordByLectureSection({ lectureId, - professorId, + sectionId, take, offset, }: Omit): Promise { return this.prismaService.record.findMany({ where: { - lectureId, - professorId, + sectionId, + LectureSection: { + id: sectionId, + lectureId, + }, }, skip: offset, take, @@ -73,10 +76,10 @@ export class RecordRepository { createdAt: 'desc', }, include: { - lectureProfessor: { + LectureSection: { include: { - lecture: true, - professor: true, + Lecture: true, + Professor: true, }, }, _count: { @@ -104,8 +107,7 @@ export class RecordRepository { recommendation, semester, year, - lectureId, - professorId, + sectionId, }: CreateRecordBodyDto, userUuid: string, ): Promise { @@ -121,9 +123,8 @@ export class RecordRepository { recommendation, semester, year, - lectureId, - professorId, userUuid, + sectionId, }, }); } diff --git a/src/record/record.service.ts b/src/record/record.service.ts index 772a56e..0681d16 100644 --- a/src/record/record.service.ts +++ b/src/record/record.service.ts @@ -7,7 +7,7 @@ import { RecordRepository } from './record.repository'; import { Record, RecordLike, User } from '@prisma/client'; import { GetAllRecordQueryDto } from './dto/req/getAllRecordQuery.dto'; import { CreateRecordBodyDto } from './dto/req/createRecordBody.dto'; -import { UpdateRecordBodyDto } from './dto/req/updateRecordBoty.dto'; +import { UpdateRecordBodyDto } from './dto/req/updateRecordBody.dto'; import { ExpandedRecordType } from './types/ExpandedRecord.type'; @Injectable() @@ -30,7 +30,7 @@ export class RecordService { if (!query.lectureId) { throw new BadRequestException('need lectureId'); } - return this.recordRepository.getRecordByLectureProfessor(query); + return this.recordRepository.getRecordByLectureSection(query); } async createRecord(body: CreateRecordBodyDto, user: User): Promise { diff --git a/src/record/types/ExpandedRecord.type.ts b/src/record/types/ExpandedRecord.type.ts index 716de33..d63f551 100644 --- a/src/record/types/ExpandedRecord.type.ts +++ b/src/record/types/ExpandedRecord.type.ts @@ -2,10 +2,10 @@ import { Prisma } from '@prisma/client'; export type ExpandedRecordType = Prisma.RecordGetPayload<{ include: { - lectureProfessor: { + LectureSection: { include: { - lecture: true; - professor: true; + Lecture: true; + Professor: true; }; }; };