diff --git a/src/domain/course/course.module.ts b/src/domain/course/course.module.ts index 56111ac..c5f6b88 100644 --- a/src/domain/course/course.module.ts +++ b/src/domain/course/course.module.ts @@ -1,13 +1,17 @@ import { Global, Module } from '@nestjs/common'; import { TypeOrmModule } from '@nestjs/typeorm'; import { CourseEntity } from './course.entity'; +import { CreateCourseUseCase } from './usecase/create-course.usecase'; +import { CourseController } from './presentation/course.controller'; const COURSE_REPOSITORY = TypeOrmModule.forFeature([CourseEntity]); @Global() @Module({ imports: [COURSE_REPOSITORY], - exports: [COURSE_REPOSITORY] + exports: [COURSE_REPOSITORY], + providers: [CreateCourseUseCase], + controllers: [CourseController] }) export class CourseModule { diff --git a/src/domain/course/presentation/course.controller.ts b/src/domain/course/presentation/course.controller.ts new file mode 100644 index 0000000..aee1f7a --- /dev/null +++ b/src/domain/course/presentation/course.controller.ts @@ -0,0 +1,18 @@ +import { Body, Controller, Post } from '@nestjs/common'; +import { CreateCourseUseCase } from '../usecase/create-course.usecase'; +import { CreateCourseRequest } from './course.dto'; + +@Controller('courses') +export class CourseController { + constructor( + private readonly createCourseUseCase: CreateCourseUseCase + ) { + } + + @Post() + async createCourse( + @Body() request: CreateCourseRequest + ) { + await this.createCourseUseCase.execute(request); + } +} \ No newline at end of file diff --git a/src/domain/course/presentation/course.dto.ts b/src/domain/course/presentation/course.dto.ts new file mode 100644 index 0000000..e7919b0 --- /dev/null +++ b/src/domain/course/presentation/course.dto.ts @@ -0,0 +1,34 @@ +import { ApiProperty } from '@nestjs/swagger'; + +export class CreateCourseRequest { + + @ApiProperty() + title: string; + + @ApiProperty() + firstGrade: boolean; + + @ApiProperty() + secondGrade: boolean; + + @ApiProperty() + thirdGrade: boolean; + + @ApiProperty() + man: boolean; + + @ApiProperty() + woman: boolean; + + @ApiProperty() + applyStartDate: Date; + + @ApiProperty() + applyEndDate: Date; + + @ApiProperty() + lectureStartDate: Date; + + @ApiProperty() + lectureEndDate: Date; +} \ No newline at end of file diff --git a/src/domain/course/usecase/create-course.usecase.ts b/src/domain/course/usecase/create-course.usecase.ts new file mode 100644 index 0000000..c510f42 --- /dev/null +++ b/src/domain/course/usecase/create-course.usecase.ts @@ -0,0 +1,31 @@ +import { Injectable } from '@nestjs/common'; +import { CourseEntity } from '../course.entity'; +import { Repository } from 'typeorm'; +import { InjectRepository } from '@nestjs/typeorm'; +import { CreateCourseRequest } from '../presentation/course.dto'; + +@Injectable() +export class CreateCourseUseCase { + constructor( + @InjectRepository(CourseEntity) + private readonly courseRepository: Repository + ) { + } + + async execute(request: CreateCourseRequest) { + await this.courseRepository.save( + new CourseEntity( + request.title, + request.firstGrade, + request.secondGrade, + request.thirdGrade, + request.man, + request.woman, + request.applyStartDate, + request.applyEndDate, + request.lectureStartDate, + request.lectureEndDate + ) + ); + } +} \ No newline at end of file