diff --git a/src/professor/professor.controller.ts b/src/professor/professor.controller.ts new file mode 100644 index 0000000..03d04b4 --- /dev/null +++ b/src/professor/professor.controller.ts @@ -0,0 +1,15 @@ +import { Controller, Get, Param, ParseIntPipe } from '@nestjs/common'; +import { ApiOperation, ApiTags } from '@nestjs/swagger'; +import { ProfessorService } from './professor.service'; + +@ApiTags('professor') +@Controller('professor') +export class ProfessorController { + constructor(private readonly professorService: ProfessorService) {} + + @ApiOperation({ summary: '교수별 개설 강좌 조회 API' }) + @Get(':id') + async getProfessorInfo(@Param('id', new ParseIntPipe()) id: number) { + return this.professorService.getProfessorInfo(id); + } +} diff --git a/src/professor/professor.module.ts b/src/professor/professor.module.ts new file mode 100644 index 0000000..ee8a1b5 --- /dev/null +++ b/src/professor/professor.module.ts @@ -0,0 +1,12 @@ +import { Module } from '@nestjs/common'; +import { ProfessorController } from './professor.controller'; +import { ProfessorService } from './professor.service'; +import { ProfessorRepository } from './professor.repository'; +import { PrismaModule } from 'src/prisma/prisma.module'; + +@Module({ + imports: [PrismaModule], + controllers: [ProfessorController], + providers: [ProfessorService, ProfessorRepository], +}) +export class ProfessorModule {} diff --git a/src/professor/professor.repository.ts b/src/professor/professor.repository.ts new file mode 100644 index 0000000..a76b499 --- /dev/null +++ b/src/professor/professor.repository.ts @@ -0,0 +1,27 @@ +import { Injectable, InternalServerErrorException } from '@nestjs/common'; +import { PrismaClientKnownRequestError } from '@prisma/client/runtime/library'; +import { PrismaService } from 'src/prisma/prisma.service'; + +@Injectable() +export class ProfessorRepository { + constructor(private readonly prismaService: PrismaService) {} + + async findProfessorLecture(id: number) { + return this.prismaService.lecture + .findMany({ + where: { + LectureProfessor: { + some: { + professorId: id, + }, + }, + }, + }) + .catch((error) => { + if (error instanceof PrismaClientKnownRequestError) { + throw new InternalServerErrorException(error.message); + } + throw new InternalServerErrorException('Unexpected error occurred'); + }); + } +} diff --git a/src/professor/professor.service.ts b/src/professor/professor.service.ts new file mode 100644 index 0000000..f7a211f --- /dev/null +++ b/src/professor/professor.service.ts @@ -0,0 +1,11 @@ +import { Injectable } from '@nestjs/common'; +import { ProfessorRepository } from './professor.repository'; + +@Injectable() +export class ProfessorService { + constructor(private readonly professorRepository: ProfessorRepository) {} + + async getProfessorInfo(id: number) { + return this.professorRepository.findProfessorLecture(id); + } +}