Skip to content

Commit 8b30b45

Browse files
committed
Merge commit '6335583169ef685f9425ed8c95e07151e77a03c9' into part-two
2 parents 82898d9 + 6335583 commit 8b30b45

File tree

25 files changed

+409
-62
lines changed

25 files changed

+409
-62
lines changed

.github/workflows/nodejs.yml

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,27 @@ on: [push]
44

55
jobs:
66
build:
7-
87
runs-on: ubuntu-latest
98

109
strategy:
1110
matrix:
1211
node-version: [8.x, 10.x, 12.x]
12+
mongodb-version: [4.0, 4.2]
1313

1414
steps:
15-
- uses: actions/checkout@v1
16-
- name: Use Node.js ${{ matrix.node-version }}
17-
uses: actions/setup-node@v1
18-
with:
19-
node-version: ${{ matrix.node-version }}
20-
- name: npm install, build, and test
21-
run: |
22-
npm install
23-
npm run build --if-present
24-
npm test
25-
env:
26-
CI: true
15+
- uses: actions/checkout@v1
16+
- name: Use Node.js ${{ matrix.node-version }}
17+
uses: actions/setup-node@v1
18+
with:
19+
node-version: ${{ matrix.node-version }}
20+
- name: Launch MongoDB
21+
uses: wbari/[email protected]
22+
with:
23+
mongoDBVersion: ${{ matrix.mongodb-version }}
24+
- name: npm install, build, and test
25+
run: |
26+
npm install
27+
npm run build --if-present
28+
npm test
29+
env:
30+
CI: true

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ node_modules/
22
dist/
33
.tmp
44
logs/
5-
src/Contexts/Mooc/Courses/infrastructure/courses.*
5+
src/Contexts/Mooc/Courses/infrastructure/persistence/courses.*

package-lock.json

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

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"@types/express": "^4.17.2",
2626
"@types/glob": "^7.1.1",
2727
"@types/helmet": "0.0.44",
28+
"@types/mongodb": "^3.3.15",
2829
"@types/node": "~13.1.1",
2930
"@types/uuid": "^3.4.6",
3031
"@types/uuid-validate": "0.0.1",
@@ -39,6 +40,7 @@
3940
"helmet": "^3.21.2",
4041
"http-status": "^1.4.2",
4142
"mandrill-api": "^1.0.45",
43+
"mongodb": "^3.5.2",
4244
"node-dependency-injection": "^2.4.2",
4345
"ts-node": "^8.3.0",
4446
"typescript": "^3.7.2",

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ export abstract class AggregateRoot {
1414
record(event: DomainEvent): void {
1515
this.domainEvents.push(event);
1616
}
17+
18+
abstract toPrimitives(): any;
1719
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,20 @@ export class Course extends AggregateRoot {
2929

3030
return course;
3131
}
32+
33+
static fromPrimitives(plainData: any): Course {
34+
return new Course(
35+
new CourseId(plainData.id),
36+
new CourseName(plainData.name),
37+
new CourseDuration(plainData.duration)
38+
);
39+
}
40+
41+
toPrimitives(): any {
42+
return {
43+
id: this.id.value,
44+
name: this.name.value,
45+
duration: this.duration.value
46+
};
47+
}
3248
}

src/Contexts/Mooc/Courses/infrastructure/FileCourseRepository.ts renamed to src/Contexts/Mooc/Courses/infrastructure/persistence/FileCourseRepository.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { CourseRepository } from '../domain/CourseRepository';
2-
import { Course } from '../domain/Course';
1+
import { CourseRepository } from '../../domain/CourseRepository';
2+
import { Course } from '../../domain/Course';
33
import fs from 'fs';
44
import BSON from 'bson';
5-
import { Nullable } from '../../../Shared/domain/Nullable';
6-
import { CourseId } from '../../Shared/domain/Courses/CourseId';
5+
import { Nullable } from '../../../../Shared/domain/Nullable';
6+
import { CourseId } from '../../../Shared/domain/Courses/CourseId';
77

88
export class FileCourseRepository implements CourseRepository {
99
private FILE_PATH = `${__dirname}/courses`;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Nullable } from '../../../../Shared/domain/Nullable';
2+
import { MongoRepository } from '../../../../Shared/infrastructure/persistence/mongo/MongoRepository';
3+
import { CourseId } from '../../../Shared/domain/Courses/CourseId';
4+
import { Course } from '../../domain/Course';
5+
import { CourseRepository } from '../../domain/CourseRepository';
6+
7+
export class MongoCourseRepository extends MongoRepository<Course> implements CourseRepository {
8+
public save(course: Course): Promise<void> {
9+
return this.persist(course.id.value, course);
10+
}
11+
12+
public async search(id: CourseId): Promise<Nullable<Course>> {
13+
const collection = await this.collection();
14+
15+
const document = await collection.findOne({ _id: id.value });
16+
17+
return document ? Course.fromPrimitives({ ...document, id: id.value }) : null;
18+
}
19+
20+
protected moduleName(): string {
21+
return 'courses';
22+
}
23+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { MongoDocument } from '../../../../../Shared/infrastructure/persistence/mongo/MongoDocument';
2+
3+
export type CourseDocument = MongoDocument & {
4+
name: string;
5+
duration: string;
6+
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface ConnectionManager {
2+
connect(): Promise<void>;
3+
close(): Promise<void>;
4+
}

0 commit comments

Comments
 (0)