Skip to content

Commit

Permalink
Merge pull request #32 from gsainfoteam/revert-31-revert-30-12-hhj
Browse files Browse the repository at this point in the history
Revert "Revert "feat: lectureSection의 lectureId와 id 복합키""
  • Loading branch information
gurwoghd authored Jul 26, 2024
2 parents 7a24a15 + 2a768fa commit d0f92f8
Show file tree
Hide file tree
Showing 17 changed files with 384 additions and 119 deletions.
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 24 additions & 8 deletions prisma/dbml/schema.dbml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,19 @@ Table user {
Table professor {
id Int [pk, increment]
name String [not null]
LectureSectionProfessor lecture_section_professor [not null]
}

Table lecture_section_professor {
sectionId Int [not null]
lectureId Int [not null]
professorId Int [not null]
LectureSection lecture_section [not null]
Professor professor [not null]

indexes {
(sectionId, lectureId, professorId) [pk]
}
}

Table lecture_code {
Expand All @@ -36,11 +48,15 @@ Table lecture {
}

Table lecture_section {
id Int [pk, increment]
id Int [increment, not null]
lectureId Int [not null]
Lecture lecture [not null]
Professor professor [not null]
LectureSectionProfessor lecture_section_professor [not null]
Record record [not null]

indexes {
(id, lectureId) [pk]
}
}

Table record {
Expand All @@ -56,6 +72,7 @@ Table record {
semester Semester [not null]
year Int [not null]
createdAt DateTime [default: `now()`, not null]
lectureId Int [not null]
sectionId Int [not null]
userUuid String [not null]
User user [not null]
Expand All @@ -73,11 +90,6 @@ Table record_like {
record record [not null]
}

Table LectureSectionToProfessor {
lecturesectionId Int [ref: > lecture_section.id]
professorId Int [ref: > professor.id]
}

Enum Semester {
SPRING
SUMMER
Expand All @@ -92,13 +104,17 @@ Enum Recommendation {
MAYBE
}

Ref: lecture_section_professor.(sectionId, lectureId) > lecture_section.(id, lectureId)

Ref: lecture_section_professor.professorId > professor.id

Ref: lecture_code.lectureId > lecture.id

Ref: lecture_section.lectureId > lecture.id

Ref: record.userUuid > user.uuid

Ref: record.sectionId > lecture_section.id
Ref: record.(lectureId, sectionId) > lecture_section.(lectureId, id)

Ref: record_like.userUuid > user.uuid

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Warnings:
- The primary key for the `lecture_section` table will be changed. If it partially fails, the table could be left without primary key constraint.
- You are about to drop the `_LectureSectionToProfessor` table. If the table is not empty, all the data it contains will be lost.
- Added the required column `lecture_id` to the `record` table without a default value. This is not possible if the table is not empty.
*/
-- DropForeignKey
ALTER TABLE "_LectureSectionToProfessor" DROP CONSTRAINT "_LectureSectionToProfessor_A_fkey";

-- DropForeignKey
ALTER TABLE "_LectureSectionToProfessor" DROP CONSTRAINT "_LectureSectionToProfessor_B_fkey";

-- DropForeignKey
ALTER TABLE "record" DROP CONSTRAINT "record_section_id_fkey";

-- AlterTable
ALTER TABLE "lecture_section" DROP CONSTRAINT "lecture_section_pkey",
ADD CONSTRAINT "lecture_section_pkey" PRIMARY KEY ("id", "lecture_id");

-- AlterTable
ALTER TABLE "record" ADD COLUMN "lecture_id" INTEGER NOT NULL;

-- DropTable
DROP TABLE "_LectureSectionToProfessor";

-- CreateTable
CREATE TABLE "lecture_section_professor" (
"section_id" INTEGER NOT NULL,
"lecture_id" INTEGER NOT NULL,
"professor_id" INTEGER NOT NULL,

CONSTRAINT "lecture_section_professor_pkey" PRIMARY KEY ("section_id","lecture_id","professor_id")
);

-- AddForeignKey
ALTER TABLE "lecture_section_professor" ADD CONSTRAINT "lecture_section_professor_section_id_lecture_id_fkey" FOREIGN KEY ("section_id", "lecture_id") REFERENCES "lecture_section"("id", "lecture_id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "lecture_section_professor" ADD CONSTRAINT "lecture_section_professor_professor_id_fkey" FOREIGN KEY ("professor_id") REFERENCES "professor"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "record" ADD CONSTRAINT "record_lecture_id_section_id_fkey" FOREIGN KEY ("lecture_id", "section_id") REFERENCES "lecture_section"("lecture_id", "id") ON DELETE RESTRICT ON UPDATE CASCADE;
21 changes: 17 additions & 4 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,22 @@ model Professor {
id Int @id @default(autoincrement())
name String
LectureSection LectureSection[]
LectureSectionProfessor LectureSectionProfessor[]
@@map("professor")
}

model LectureSectionProfessor {
sectionId Int @map("section_id")
lectureId Int @map("lecture_id")
professorId Int @map("professor_id")
LectureSection LectureSection @relation(fields: [sectionId, lectureId], references: [id, lectureId])
Professor Professor @relation(fields: [professorId], references: [id])
@@id([sectionId, lectureId, professorId])
@@map("lecture_section_professor")
}

model LectureCode {
code String @id
lectureId Int @map("lecture_id")
Expand All @@ -69,13 +80,14 @@ model Lecture {
}

model LectureSection {
id Int @id @default(autoincrement())
id Int @default(autoincrement())
lectureId Int @map("lecture_id")
Lecture Lecture @relation(fields: [lectureId], references: [id])
Professor Professor[]
LectureSectionProfessor LectureSectionProfessor[]
Record Record[]
@@id(name: "lectureSectionId", [id, lectureId])
@@map("lecture_section")
}

Expand All @@ -97,11 +109,12 @@ model Record {
createdAt DateTime @default(now()) @map("created_at")
lectureId Int @map("lecture_id")
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])
LectureSection LectureSection @relation(fields: [lectureId, sectionId], references: [lectureId, id])
RecordLike RecordLike[]
Expand Down
52 changes: 48 additions & 4 deletions src/lecture/dto/res/lectureRes.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,48 @@ class LectureCodeResDto implements LectureCode {
lectureId: number;
}

export class LectureSectionProfessorResDto
implements
Prisma.LectureSectionProfessorGetPayload<{
include: {
Professor: true;
};
}>
{
@ApiProperty({
example: 1,
description: '강의 section id',
})
sectionId: number;

@ApiProperty({
example: 1,
description: '강의 id',
})
lectureId: number;

@ApiProperty({
example: 1,
description: '교수 id',
})
professorId: number;

@ApiProperty({
description: '교수 정보',
type: ProfessorResDto,
})
Professor: ProfessorResDto;
}

class LectureSectionResDto
implements
Prisma.LectureSectionGetPayload<{
include: {
Professor: true;
LectureSectionProfessor: {
include: {
Professor: true;
};
};
};
}>
{
Expand All @@ -49,8 +86,11 @@ class LectureSectionResDto
})
lectureId: number;

@ApiProperty()
Professor: ProfessorResDto[];
@ApiProperty({
type: [LectureSectionProfessorResDto],
description: '강의 section 교수 정보',
})
LectureSectionProfessor: LectureSectionProfessorResDto[];
}

export class ExpandedLectureResDto
Expand All @@ -60,7 +100,11 @@ export class ExpandedLectureResDto
LectureCode: true;
LectureSection: {
include: {
Professor: true;
LectureSectionProfessor: {
include: {
Professor: true;
};
};
};
};
};
Expand Down
26 changes: 20 additions & 6 deletions src/lecture/lecture.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ export class LectureRepository {
where: {
LectureSection: {
some: {
Professor: {
LectureSectionProfessor: {
some: {
name: {
contains: professorName,
Professor: {
name: {
contains: professorName,
},
},
},
},
Expand All @@ -37,7 +39,11 @@ export class LectureRepository {
LectureCode: true,
LectureSection: {
include: {
Professor: true,
LectureSectionProfessor: {
include: {
Professor: true,
},
},
},
},
},
Expand All @@ -62,7 +68,11 @@ export class LectureRepository {
LectureCode: true,
LectureSection: {
include: {
Professor: true,
LectureSectionProfessor: {
include: {
Professor: true,
},
},
},
},
},
Expand Down Expand Up @@ -142,7 +152,11 @@ export class LectureRepository {
LectureCode: true,
LectureSection: {
include: {
Professor: true,
LectureSectionProfessor: {
include: {
Professor: true,
},
},
},
},
},
Expand Down
29 changes: 25 additions & 4 deletions src/record/dto/res/expandedRes.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { RecordResDto } from './recordRes.dto';
import { Lecture, Professor } from '@prisma/client';
import {
Lecture,
LectureSection,
Professor,
LectureSectionProfessor,
} from '@prisma/client';
import { ExpandedRecordType } from 'src/record/types/ExpandedRecord.type';

class LectureResDto implements Lecture {
Expand All @@ -19,17 +24,33 @@ class ProfessorResDto implements Professor {
name: string;
}

class LectureSectionResDto {
class LectureSectionProfessorResDto implements LectureSectionProfessor {
@ApiProperty()
sectionId: number;

@ApiProperty()
professorId: number;

@ApiProperty()
lectureId: number;

@ApiProperty({
type: ProfessorResDto,
})
Professor: ProfessorResDto;
}

class LectureSectionResDto implements LectureSection {
@ApiProperty()
id: number;

@ApiProperty()
lectureId: number;

@ApiProperty({
type: [ProfessorResDto],
type: [LectureSectionProfessorResDto],
})
Professor: ProfessorResDto[];
LectureSectionProfessor: LectureSectionProfessorResDto[];

@ApiProperty({
type: LectureResDto,
Expand Down
3 changes: 3 additions & 0 deletions src/record/dto/res/recordRes.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export class RecordResDto implements Record {
@ApiProperty()
userUuid: string;

@ApiProperty()
lectureId: number;

@ApiProperty()
sectionId: number;
}
Loading

0 comments on commit d0f92f8

Please sign in to comment.