From 4a363d4ba991fca94e3996a335cb0103dc140f9c Mon Sep 17 00:00:00 2001 From: siwonpada Date: Fri, 21 Jun 2024 01:35:25 +0900 Subject: [PATCH] expanded Record --- src/record/dto/res/expandedRes.dto.ts | 32 +++++++++++++++++++++++++ src/record/record.controller.ts | 3 ++- src/record/record.repository.ts | 21 ++++++++++++++-- src/record/record.service.ts | 5 +++- src/record/types/ExpandedRecord.type.ts | 12 ++++++++++ 5 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 src/record/dto/res/expandedRes.dto.ts create mode 100644 src/record/types/ExpandedRecord.type.ts diff --git a/src/record/dto/res/expandedRes.dto.ts b/src/record/dto/res/expandedRes.dto.ts new file mode 100644 index 0000000..1c94fe3 --- /dev/null +++ b/src/record/dto/res/expandedRes.dto.ts @@ -0,0 +1,32 @@ +import { ApiProperty } from '@nestjs/swagger'; +import { RecordResDto } from './recordRes.dto'; +import { Lecture, Professor } from '@prisma/client'; + +class LectureResDto implements Lecture { + @ApiProperty() + id: number; + + @ApiProperty() + lectureName: string; +} + +class ProfessorResDto implements Professor { + @ApiProperty() + id: number; + + @ApiProperty() + name: string; +} + +class LectureProfessorResDto { + @ApiProperty() + lecture: LectureResDto; + + @ApiProperty() + professor: ProfessorResDto; +} + +export class ExpandedRecordResDto extends RecordResDto { + @ApiProperty() + lectureProfessor: LectureProfessorResDto; +} diff --git a/src/record/record.controller.ts b/src/record/record.controller.ts index de4fc79..9991252 100644 --- a/src/record/record.controller.ts +++ b/src/record/record.controller.ts @@ -20,6 +20,7 @@ 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 { ExpandedRecordResDto } from './dto/res/expandedRes.dto'; @ApiTags('record') @Controller('record') @@ -36,7 +37,7 @@ export class RecordController { @Get() async getRecordList( @Query() query: GetAllRecordQueryDto, - ): Promise { + ): Promise { return this.recordService.getRecordList(query); } diff --git a/src/record/record.repository.ts b/src/record/record.repository.ts index d2f7e9c..95421db 100644 --- a/src/record/record.repository.ts +++ b/src/record/record.repository.ts @@ -5,6 +5,7 @@ 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 { ExpandedRecordType } from './types/ExpandedRecord.type'; @Injectable() export class RecordRepository { @@ -13,13 +14,21 @@ export class RecordRepository { async getRecentRecord({ take, offset, - }: PagenationQueryDto): Promise { + }: PagenationQueryDto): Promise { return this.prismaService.record.findMany({ skip: offset, take, orderBy: { createdAt: 'desc', }, + include: { + lectureProfessor: { + include: { + lecture: true, + professor: true, + }, + }, + }, }); } @@ -28,7 +37,7 @@ export class RecordRepository { professorId, take, offset, - }: Omit): Promise { + }: Omit): Promise { return this.prismaService.record.findMany({ where: { lectureId, @@ -39,6 +48,14 @@ export class RecordRepository { orderBy: { createdAt: 'desc', }, + include: { + lectureProfessor: { + include: { + lecture: true, + professor: true, + }, + }, + }, }); } diff --git a/src/record/record.service.ts b/src/record/record.service.ts index bcfaa06..0e4d5f5 100644 --- a/src/record/record.service.ts +++ b/src/record/record.service.ts @@ -4,12 +4,15 @@ import { Record, 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 { ExpandedRecordType } from './types/ExpandedRecord.type'; @Injectable() export class RecordService { constructor(private readonly recordRepository: RecordRepository) {} - async getRecordList(query: GetAllRecordQueryDto): Promise { + async getRecordList( + query: GetAllRecordQueryDto, + ): Promise { if (query.type === 'recent') { return this.recordRepository.getRecentRecord(query); } diff --git a/src/record/types/ExpandedRecord.type.ts b/src/record/types/ExpandedRecord.type.ts new file mode 100644 index 0000000..716de33 --- /dev/null +++ b/src/record/types/ExpandedRecord.type.ts @@ -0,0 +1,12 @@ +import { Prisma } from '@prisma/client'; + +export type ExpandedRecordType = Prisma.RecordGetPayload<{ + include: { + lectureProfessor: { + include: { + lecture: true; + professor: true; + }; + }; + }; +}>;