Skip to content

Commit

Permalink
update db
Browse files Browse the repository at this point in the history
  • Loading branch information
siwonpada committed Jun 18, 2024
1 parent 11f0796 commit 6632a51
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
);
Expand All @@ -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;
12 changes: 6 additions & 6 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,14 @@ model Lecture {
}

model LectureProfessor {
id Int @id @default(autoincrement())
lectureId Int
lecture Lecture @relation(fields: [lectureId], references: [id])
professorId Int
professor Professor @relation(fields: [professorId], references: [id])
Record Record[]
@@id([lectureId, professorId])
@@map("lecture_professor")
}

Expand All @@ -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")
}
2 changes: 2 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -11,6 +12,7 @@ import { UserModule } from './user/user.module';
}),
ProfessorModule,
UserModule,
LectureModule,
],
controllers: [AppController],
})
Expand Down
48 changes: 48 additions & 0 deletions src/lecture/dto/res/lectureRes.dto.ts
Original file line number Diff line number Diff line change
@@ -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;
}
10 changes: 10 additions & 0 deletions src/lecture/lecture.controller.ts
Original file line number Diff line number Diff line change
@@ -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<LectureResDto[]> {
return [];
}
}
12 changes: 12 additions & 0 deletions src/lecture/lecture.module.ts
Original file line number Diff line number Diff line change
@@ -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 {}
20 changes: 20 additions & 0 deletions src/lecture/lecture.repository.ts
Original file line number Diff line number Diff line change
@@ -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<Lecture[]> {
return this.prismaService.lecture.findMany({
include: {
LectureProfessor: {
include: {
professor: true,
},
},
},
});
}
}
4 changes: 4 additions & 0 deletions src/lecture/lecture.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Injectable } from '@nestjs/common';

@Injectable()
export class LectureService {}
File renamed without changes.
2 changes: 1 addition & 1 deletion src/professor/professor.controller.ts
Original file line number Diff line number Diff line change
@@ -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')
Expand Down

0 comments on commit 6632a51

Please sign in to comment.