|
1 | | -import CourseRepository from '../domain/CourseRepository'; |
2 | | -import Course from '../domain/Course'; |
| 1 | +import { CourseRepository } from '../domain/CourseRepository'; |
| 2 | +import { Course } from '../domain/Course'; |
| 3 | +import { CreateCourseRequest } from './CreateCourseRequest'; |
| 4 | +import { CourseId } from '../../Shared/domain/Courses/CourseId'; |
| 5 | +import { CourseName } from '../domain/CourseName'; |
| 6 | +import { CourseDuration } from '../domain/CourseDuration'; |
| 7 | +import { EventBus } from '../../../Shared/domain/EventBus'; |
3 | 8 |
|
4 | | -export default class CourseCreator { |
| 9 | +export class CourseCreator { |
5 | 10 | private repository: CourseRepository; |
| 11 | + private eventBus: EventBus; |
6 | 12 |
|
7 | | - constructor(repository: CourseRepository) { |
| 13 | + constructor(repository: CourseRepository, eventBus: EventBus) { |
8 | 14 | this.repository = repository; |
| 15 | + this.eventBus = eventBus; |
9 | 16 | } |
10 | 17 |
|
11 | | - async run(id: string, name: string, duration: string): Promise<void> { |
12 | | - const course = new Course(id, name, duration); |
| 18 | + async run(request: CreateCourseRequest): Promise<void> { |
| 19 | + const course = new Course( |
| 20 | + new CourseId(request.id), |
| 21 | + new CourseName(request.name), |
| 22 | + new CourseDuration(request.duration) |
| 23 | + ); |
13 | 24 |
|
14 | | - return this.repository.save(course); |
| 25 | + await this.repository.save(course); |
| 26 | + |
| 27 | + this.eventBus.publish(course.pullDomainEvents()); |
15 | 28 | } |
16 | 29 | } |
0 commit comments