Skip to content

Commit

Permalink
add professor
Browse files Browse the repository at this point in the history
  • Loading branch information
siwonpada committed Jun 18, 2024
1 parent f846111 commit 7f53b7e
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/professor/professor.controller.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
12 changes: 12 additions & 0 deletions src/professor/professor.module.ts
Original file line number Diff line number Diff line change
@@ -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 {}
27 changes: 27 additions & 0 deletions src/professor/professor.repository.ts
Original file line number Diff line number Diff line change
@@ -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');
});
}
}
11 changes: 11 additions & 0 deletions src/professor/professor.service.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 7f53b7e

Please sign in to comment.