diff --git a/prisma/migrations/20240618155308_init/migration.sql b/prisma/migrations/20240618162856_init/migration.sql similarity index 84% rename from prisma/migrations/20240618155308_init/migration.sql rename to prisma/migrations/20240618162856_init/migration.sql index 308018d..fc15e09 100644 --- a/prisma/migrations/20240618155308_init/migration.sql +++ b/prisma/migrations/20240618162856_init/migration.sql @@ -33,11 +33,10 @@ CREATE TABLE "lecture" ( -- CreateTable CREATE TABLE "lecture_professor" ( - "id" SERIAL NOT NULL, "lectureId" INTEGER NOT NULL, "professorId" INTEGER NOT NULL, - CONSTRAINT "lecture_professor_pkey" PRIMARY KEY ("id") + CONSTRAINT "lecture_professor_pkey" PRIMARY KEY ("lectureId","professorId") ); -- CreateTable @@ -55,7 +54,8 @@ CREATE TABLE "record" ( "year" INTEGER NOT NULL, "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, "userUuid" UUID NOT NULL, - "lectureProfessorId" INTEGER NOT NULL, + "LectureId" INTEGER NOT NULL, + "ProfessorId" INTEGER NOT NULL, CONSTRAINT "record_pkey" PRIMARY KEY ("id") ); @@ -70,4 +70,4 @@ ALTER TABLE "lecture_professor" ADD CONSTRAINT "lecture_professor_professorId_fk ALTER TABLE "record" ADD CONSTRAINT "record_userUuid_fkey" FOREIGN KEY ("userUuid") REFERENCES "user"("uuid") ON DELETE RESTRICT ON UPDATE CASCADE; -- AddForeignKey -ALTER TABLE "record" ADD CONSTRAINT "record_lectureProfessorId_fkey" FOREIGN KEY ("lectureProfessorId") REFERENCES "lecture_professor"("id") ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE "record" ADD CONSTRAINT "record_LectureId_ProfessorId_fkey" FOREIGN KEY ("LectureId", "ProfessorId") REFERENCES "lecture_professor"("lectureId", "professorId") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 57f7227..a6307d1 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -58,8 +58,6 @@ model Lecture { } model LectureProfessor { - id Int @id @default(autoincrement()) - lectureId Int lecture Lecture @relation(fields: [lectureId], references: [id]) professorId Int @@ -67,6 +65,7 @@ model LectureProfessor { Record Record[] + @@id([lectureId, professorId]) @@map("lecture_professor") } @@ -88,10 +87,11 @@ model Record { createdAt DateTime @default(now()) @map("created_at") - userUuid String @db.Uuid - user User @relation(fields: [userUuid], references: [uuid]) - lectureProfessorId Int - lectureProfessor LectureProfessor @relation(fields: [lectureProfessorId], references: [id]) + userUuid String @db.Uuid + user User @relation(fields: [userUuid], references: [uuid]) + LectureId Int + ProfessorId Int + lectureProfessor LectureProfessor @relation(fields: [LectureId, ProfessorId], references: [lectureId, professorId]) @@map("record") } diff --git a/src/app.module.ts b/src/app.module.ts index ebaf419..6204270 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -3,6 +3,7 @@ import { AppController } from './app.controller'; import { ConfigModule } from '@nestjs/config'; import { ProfessorModule } from './professor/professor.module'; import { UserModule } from './user/user.module'; +import { LectureModule } from './lecture/lecture.module'; @Module({ imports: [ @@ -11,6 +12,7 @@ import { UserModule } from './user/user.module'; }), ProfessorModule, UserModule, + LectureModule, ], controllers: [AppController], }) diff --git a/src/lecture/dto/res/lectureRes.dto.ts b/src/lecture/dto/res/lectureRes.dto.ts new file mode 100644 index 0000000..fa18218 --- /dev/null +++ b/src/lecture/dto/res/lectureRes.dto.ts @@ -0,0 +1,48 @@ +import { ApiProperty } from '@nestjs/swagger'; +import { Prisma } from '@prisma/client'; + +export class LectureResDto + implements + Prisma.LectureGetPayload<{ + include: { + LectureProfessor: { + include: { + professor: true; + }; + }; + }; + }> +{ + @ApiProperty({ + example: [ + { + id: 1, + name: '김교수', + }, + ], + description: '교수 정보', + }) + LectureProfessor: ({ professor: { id: number; name: string } } & { + id: number; + lectureId: number; + professorId: number; + })[]; + + @ApiProperty({ + example: 1, + description: '강의 Id', + }) + id: number; + + @ApiProperty({ + example: 'A0001', + description: '강의 코드', + }) + lectureCode: string[]; + + @ApiProperty({ + example: '운영체제', + description: '강의 이름', + }) + lectureName: string; +} diff --git a/src/lecture/lecture.controller.ts b/src/lecture/lecture.controller.ts new file mode 100644 index 0000000..b5fe4e7 --- /dev/null +++ b/src/lecture/lecture.controller.ts @@ -0,0 +1,10 @@ +import { Controller, Get } from '@nestjs/common'; +import { LectureResDto } from './dto/res/lectureRes.dto'; + +@Controller('lecture') +export class LectureController { + @Get() + async getAll(): Promise { + return []; + } +} diff --git a/src/lecture/lecture.module.ts b/src/lecture/lecture.module.ts new file mode 100644 index 0000000..963bf7c --- /dev/null +++ b/src/lecture/lecture.module.ts @@ -0,0 +1,12 @@ +import { Module } from '@nestjs/common'; +import { LectureController } from './lecture.controller'; +import { LectureService } from './lecture.service'; +import { PrismaModule } from 'src/prisma/prisma.module'; +import { LectureRepository } from './lecture.repository'; + +@Module({ + imports: [PrismaModule], + controllers: [LectureController], + providers: [LectureService, LectureRepository], +}) +export class LectureModule {} diff --git a/src/lecture/lecture.repository.ts b/src/lecture/lecture.repository.ts new file mode 100644 index 0000000..27cfbc2 --- /dev/null +++ b/src/lecture/lecture.repository.ts @@ -0,0 +1,20 @@ +import { Injectable } from '@nestjs/common'; +import { Lecture } from '@prisma/client'; +import { PrismaService } from 'src/prisma/prisma.service'; + +@Injectable() +export class LectureRepository { + constructor(private readonly prismaService: PrismaService) {} + + async getAll(): Promise { + return this.prismaService.lecture.findMany({ + include: { + LectureProfessor: { + include: { + professor: true, + }, + }, + }, + }); + } +} diff --git a/src/lecture/lecture.service.ts b/src/lecture/lecture.service.ts new file mode 100644 index 0000000..7e3b7aa --- /dev/null +++ b/src/lecture/lecture.service.ts @@ -0,0 +1,4 @@ +import { Injectable } from '@nestjs/common'; + +@Injectable() +export class LectureService {} diff --git a/src/professor/dto/res/getProfessorInfoRes.dto.ts b/src/professor/dto/res/lectureRes.dto.ts similarity index 100% rename from src/professor/dto/res/getProfessorInfoRes.dto.ts rename to src/professor/dto/res/lectureRes.dto.ts diff --git a/src/professor/professor.controller.ts b/src/professor/professor.controller.ts index b53042a..61674c7 100644 --- a/src/professor/professor.controller.ts +++ b/src/professor/professor.controller.ts @@ -1,7 +1,7 @@ import { Controller, Get, Param, ParseIntPipe } from '@nestjs/common'; import { ApiOperation, ApiTags } from '@nestjs/swagger'; import { ProfessorService } from './professor.service'; -import { LectureResDto } from './dto/res/getProfessorInfoRes.dto'; +import { LectureResDto } from './dto/res/lectureRes.dto'; @ApiTags('professor') @Controller('professor')