Skip to content

Commit 82898d9

Browse files
committed
Merge remote-tracking branch 'origin/part-two' into part_three
2 parents 853bd27 + 228f704 commit 82898d9

34 files changed

+336
-105
lines changed

package-lock.json

Lines changed: 16 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
"@types/express": "^4.17.2",
2626
"@types/glob": "^7.1.1",
2727
"@types/helmet": "0.0.44",
28-
"@types/node": "~11.13.0",
28+
"@types/node": "~13.1.1",
2929
"@types/uuid": "^3.4.6",
30+
"@types/uuid-validate": "0.0.1",
3031
"body-parser": "^1.19.0",
3132
"bson": "^4.0.2",
3233
"compression": "^1.7.4",
@@ -36,12 +37,13 @@
3637
"express": "^4.17.1",
3738
"glob": "^7.1.6",
3839
"helmet": "^3.21.2",
39-
"http-status": "^1.3.2",
40+
"http-status": "^1.4.2",
4041
"mandrill-api": "^1.0.45",
4142
"node-dependency-injection": "^2.4.2",
4243
"ts-node": "^8.3.0",
4344
"typescript": "^3.7.2",
4445
"uuid": "^3.3.3",
46+
"uuid-validate": "0.0.3",
4547
"winston": "^3.2.1"
4648
},
4749
"devDependencies": {

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import CourseRepository from '../domain/CourseRepository';
2-
import Course from '../domain/Course';
3-
import { CourseId } from '../domain/CourseId';
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';
45
import { CourseName } from '../domain/CourseName';
56
import { CourseDuration } from '../domain/CourseDuration';
67
import { EventBus } from '../../../Shared/domain/EventBus';
78

8-
export default class CourseCreator {
9+
export class CourseCreator {
910
private repository: CourseRepository;
1011
private eventBus: EventBus;
1112

@@ -14,8 +15,12 @@ export default class CourseCreator {
1415
this.eventBus = eventBus;
1516
}
1617

17-
async run(id: CourseId, name: CourseName, duration: CourseDuration): Promise<void> {
18-
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+
);
1924

2025
await this.repository.save(course);
2126

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export type CreateCourseRequest = {
2+
id: string;
3+
name: string;
4+
duration: string;
5+
};

src/Contexts/Mooc/Courses/domain/Course.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { AggregateRoot } from './AggregateRoot';
22
import { CourseCreatedDomainEvent } from './CourseCreatedDomainEvent';
3-
import { CourseId } from './CourseId';
43
import { CourseName } from './CourseName';
54
import { CourseDuration } from './CourseDuration';
5+
import { CourseId } from '../../Shared/domain/Courses/CourseId';
66

7-
export default class Course extends AggregateRoot {
7+
export class Course extends AggregateRoot {
88
readonly id: CourseId;
99
readonly name: CourseName;
1010
readonly duration: CourseDuration;
@@ -21,9 +21,9 @@ export default class Course extends AggregateRoot {
2121

2222
course.record(
2323
new CourseCreatedDomainEvent({
24-
id: course.id.value(),
25-
duration: course.duration.value(),
26-
name: course.name.value()
24+
id: course.id.value,
25+
duration: course.duration.value,
26+
name: course.name.value
2727
})
2828
);
2929

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export default class CourseAlreadyExists extends Error {
2-
constructor(courseId: string) {
3-
super(`Course ${courseId} already exists`);
1+
export class CourseAlreadyExists extends Error {
2+
constructor(id: string) {
3+
super(`Course ${id} already exists`);
44
}
55
}

src/Contexts/Mooc/Courses/domain/CourseCreatedDomainEvent.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { DomainEvent } from '../../../Shared/domain/DomainEvent';
22

33
type CreateCourseDomainEventBody = {
4-
readonly duration: number;
4+
readonly duration: string;
55
readonly name: string;
66
};
77

88
export class CourseCreatedDomainEvent extends DomainEvent {
99
static readonly EVENT_NAME = 'course.created';
1010

11-
readonly duration: number;
11+
readonly duration: string;
1212
readonly name: string;
1313

1414
constructor({
@@ -20,7 +20,7 @@ export class CourseCreatedDomainEvent extends DomainEvent {
2020
}: {
2121
id: string;
2222
eventId?: string;
23-
duration: number;
23+
duration: string;
2424
name: string;
2525
occurredOn?: Date;
2626
}) {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import { ValueObject } from '../../../Shared/domain/ValueObject';
1+
import { StringValueObject } from '../../../Shared/domain/value-object/StringValueObject';
22

3-
export class CourseDuration extends ValueObject<number> {}
3+
export class CourseDuration extends StringValueObject {}

src/Contexts/Mooc/Courses/domain/CourseId.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1-
import { ValueObject } from '../../../Shared/domain/ValueObject';
1+
import { StringValueObject } from '../../../Shared/domain/value-object/StringValueObject';
2+
import { InvalidArgumentError } from '../../../Shared/domain/value-object/InvalidArgumentError';
23

3-
export class CourseName extends ValueObject<string> {}
4+
export class CourseName extends StringValueObject {
5+
constructor(value: string) {
6+
super(value);
7+
this.ensureLengthIsLessThan30Characters(value);
8+
}
9+
10+
private ensureLengthIsLessThan30Characters(value: string): void {
11+
if (value.length > 30) {
12+
throw new InvalidArgumentError(`The Course Name <${value}> has more than 30 characters`);
13+
}
14+
}
15+
}

0 commit comments

Comments
 (0)