Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge :: (#11) create course api #12

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/domain/course/course.module.ts
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down
18 changes: 18 additions & 0 deletions src/domain/course/presentation/course.controller.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
34 changes: 34 additions & 0 deletions src/domain/course/presentation/course.dto.ts
Original file line number Diff line number Diff line change
@@ -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;
}
31 changes: 31 additions & 0 deletions src/domain/course/usecase/create-course.usecase.ts
Original file line number Diff line number Diff line change
@@ -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<CourseEntity>
) {
}

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
)
);
}
}