Skip to content

Commit 85e6769

Browse files
authored
Merge pull request #66 from CodelyTV/part_four_query_bus
Part four query bus
2 parents bda1674 + 9c16582 commit 85e6769

39 files changed

+406
-65
lines changed

.github/workflows/nodejs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
run: |
2626
npm install
2727
npm run build --if-present
28+
npm run lint
2829
npm test
2930
env:
3031
CI: true

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"test": "npm run test:unit && npm run test:features",
1717
"test:unit": "NODE_ENV=test jest",
1818
"test:features": "NODE_ENV=test cucumber-js -p default",
19+
"lint": "tslint src/**/*.ts{,x}",
1920
"start": "NODE_ENV=production node dist/src/apps/mooc_backend/server",
2021
"start:backoffice:frontend": "NODE_ENV=production node dist/src/apps/backoffice/frontend/server",
2122
"build": "npm run build:clean && npm run build:tsc && npm run build:di",

src/Contexts/Mooc/Courses/application/CourseCreator.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ import { CourseName } from '../domain/CourseName';
66
import { CourseDuration } from '../domain/CourseDuration';
77
import { EventBus } from '../../../Shared/domain/EventBus';
88

9+
type Params = {
10+
courseId: CourseId;
11+
courseName: CourseName;
12+
courseDuration: CourseDuration;
13+
};
14+
915
export class CourseCreator {
1016
private repository: CourseRepository;
1117
private eventBus: EventBus;
@@ -15,11 +21,11 @@ export class CourseCreator {
1521
this.eventBus = eventBus;
1622
}
1723

18-
async run(request: CreateCourseRequest): Promise<void> {
24+
async run({ courseId, courseName, courseDuration }: Params): Promise<void> {
1925
const course = Course.create(
20-
new CourseId(request.id),
21-
new CourseName(request.name),
22-
new CourseDuration(request.duration)
26+
courseId,
27+
courseName,
28+
courseDuration
2329
);
2430

2531
await this.repository.save(course);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Command } from '../../../Shared/domain/Command';
2+
3+
type Params = {
4+
id: string;
5+
name: string;
6+
duration: string;
7+
};
8+
9+
export class CreateCourseCommand extends Command {
10+
id: string;
11+
name: string;
12+
duration: string;
13+
14+
constructor({ id, name, duration }: Params) {
15+
super();
16+
this.id = id;
17+
this.name = name;
18+
this.duration = duration;
19+
}
20+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { CreateCourseCommand } from './CreateCourseCommand';
2+
import { CommandHandler } from '../../../Shared/domain/CommandHandler';
3+
import { CourseCreator } from './CourseCreator';
4+
import { Command } from '../../../Shared/domain/Command';
5+
import { CourseId } from '../../Shared/domain/Courses/CourseId';
6+
import { CourseName } from '../domain/CourseName';
7+
import { CourseDuration } from '../domain/CourseDuration';
8+
9+
export class CreateCourseCommandHandler implements CommandHandler<CreateCourseCommand> {
10+
constructor(private courseCreator: CourseCreator) {}
11+
12+
subscribedTo(): Command {
13+
return CreateCourseCommand;
14+
}
15+
16+
async handle(command: CreateCourseCommand): Promise<void> {
17+
const courseId = new CourseId(command.id);
18+
const courseName = new CourseName(command.name);
19+
const courseDuration = new CourseDuration(command.duration);
20+
await this.courseCreator.run({ courseId, courseName, courseDuration });
21+
}
22+
}

src/Contexts/Mooc/CoursesCounter/application/Find/CoursesCounterFinder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CoursesCounterRepository } from '../../domain/CoursesCounterRepository';
22
import { CoursesCounterNotExist } from '../../domain/CoursesCounterNotExist';
3-
import { CoursesCounterResponse } from './CoursesCounterResponse';
3+
import { FindCoursesCounterResponse } from './FindCoursesCounterResponse';
44

55
export class CoursesCounterFinder {
66
constructor(private repository: CoursesCounterRepository) {}
@@ -11,6 +11,6 @@ export class CoursesCounterFinder {
1111
throw new CoursesCounterNotExist();
1212
}
1313

14-
return new CoursesCounterResponse(counter.total.value);
14+
return new FindCoursesCounterResponse(counter.total.value);
1515
}
1616
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { Query } from '../../../../Shared/domain/Query';
2+
3+
export class FindCoursesCounterQuery implements Query {}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { QueryHandler } from '../../../../Shared/domain/QueryHandler';
2+
import { FindCoursesCounterQuery } from './FindCoursesCounterQuery';
3+
import { FindCoursesCounterResponse } from './FindCoursesCounterResponse';
4+
import { Query } from '../../../../Shared/domain/Query';
5+
import { CoursesCounterFinder } from './CoursesCounterFinder';
6+
7+
export class FindCoursesCounterQueryHandler
8+
implements QueryHandler<FindCoursesCounterQuery, FindCoursesCounterResponse> {
9+
constructor(private finder: CoursesCounterFinder) {}
10+
11+
subscribedTo(): Query {
12+
return FindCoursesCounterQuery;
13+
}
14+
handle(_query: FindCoursesCounterQuery): Promise<FindCoursesCounterResponse> {
15+
return this.finder.run();
16+
}
17+
}

src/Contexts/Mooc/CoursesCounter/application/Find/CoursesCounterResponse.ts renamed to src/Contexts/Mooc/CoursesCounter/application/Find/FindCoursesCounterResponse.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export class CoursesCounterResponse {
1+
export class FindCoursesCounterResponse {
22
readonly total: number;
33

44
constructor(total: number) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export abstract class Command {}

0 commit comments

Comments
 (0)