Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ services:

Mooc.coursesCounter.CoursesCounterFinder:
class: ../../../../../Contexts/Mooc/CoursesCounter/application/Find/CoursesCounterFinder
arguments: ["@Mooc.coursesCounter.CoursesCounterRepository"]
arguments: ['@Mooc.coursesCounter.CoursesCounterRepository']

Mooc.coursesCounter.CoursesCounterRepository:
class: ../../../../../Contexts/Mooc/CoursesCounter/infrastructure/persistence/mongo/MongoCoursesCounterRepository
arguments: ["@Mooc.shared.ConnectionManager"]
arguments: ['@Mooc.shared.ConnectionManager']

Mooc.shared.ConnectionManager:
factory:
Expand All @@ -34,8 +34,36 @@ services:

Apps.Backoffice.Frontend.controllers.CoursesGetController:
class: ../../controllers/CoursesGetController
arguments: ['@Mooc.coursesCounter.CoursesCounterFinder']
arguments: ['@Mooc.shared.QueryBus']

Apps.Backoffice.Frontend.controllers.CoursesPostController:
class: ../../controllers/CoursesPostController
arguments: ['@Mooc.shared.CommandBus']

Mooc.coursesCounter.FindCoursesCounterQueryHandler:
class: ../../../../../Contexts/Mooc/CoursesCounter/application/Find/FindCoursesCounterQueryHandler
arguments: ['@Mooc.coursesCounter.CoursesCounterFinder']
tags:
- { name: 'queryHandler' }

Mooc.courses.CreateCourseCommandHandler:
class: ../../../../../Contexts/Mooc/Courses/application/CreateCourseCommandHandler
arguments: ['@Mooc.courses.CourseCreator']
tags:
- { name: 'commandHandler' }

Mooc.shared.QueryBus:
class: ../../../../../Contexts/Shared/infrastructure/QueryBus/InMemoryQueryBus
arguments: ['@Mooc.shared.QueryHandlersInformation']

Mooc.shared.CommandBus:
class: ../../../../../Contexts/Shared/infrastructure/CommandBus/InMemoryCommandBus
arguments: ['@Mooc.shared.CommandHandlersInformation']

Mooc.shared.QueryHandlersInformation:
class: ../../../../../Contexts/Shared/infrastructure/QueryBus/QueryHandlersInformation
arguments: ['!tagged queryHandler']

Mooc.shared.CommandHandlersInformation:
class: ../../../../../Contexts/Shared/infrastructure/CommandBus/CommandHandlersInformation
arguments: ['!tagged commandHandler']
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Request, Response } from 'express';
import { CoursesCounterFinder } from '../../../../Contexts/Mooc/CoursesCounter/application/Find/CoursesCounterFinder';
import { Uuid } from '../../../../Contexts/Shared/domain/value-object/Uuid';
import { QueryBus } from '../../../../Contexts/Shared/domain/QueryBus';
import { FindCoursesCounterResponse } from '../../../../Contexts/Mooc/CoursesCounter/application/Find/FindCoursesCounterResponse';
import { FindCoursesCounterQuery } from '../../../../Contexts/Mooc/CoursesCounter/application/Find/FindCoursesCounterQuery';

export class CoursesGetController {
constructor(private coursesCounterFinder: CoursesCounterFinder) {}
constructor(private queryBus: QueryBus) {}

async run(req: Request, res: Response) {
const courses = await this.coursesCounterFinder.run();
const courses = await this.queryBus.ask<FindCoursesCounterResponse>(new FindCoursesCounterQuery());

res.render('pages/courses/courses', {
title: 'Welcome',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Request, Response } from 'express';
import { CreateCourseRequest } from '../../../../Contexts/Mooc/Courses/application/CreateCourseRequest';
import { CourseCreator } from '../../../../Contexts/Mooc/Courses/application/CourseCreator';
import { CommandBus } from '../../../../Contexts/Shared/domain/CommandBus';
import { CreateCourseCommand } from '../../../../Contexts/Mooc/Courses/application/CreateCourseCommand';

export class CoursesPostController {
constructor(private courseCreator: CourseCreator) {}
constructor(private commandBus: CommandBus) {}

async run(req: Request, res: Response) {
// TODO: validation
Expand All @@ -13,11 +13,13 @@ export class CoursesPostController {
}

private async createCourse(req: Request, res: Response) {
await this.courseCreator.run({
courseId: req.body.id,
courseName: req.body.name,
courseDuration: req.body.duration
const createCourseCommand = new CreateCourseCommand({
id: req.body.id,
name: req.body.name,
duration: req.body.duration
});
await this.commandBus.dispatch(createCourseCommand);

req.flash('message', `Felicidades, el curso ${req.body.name} ha sido creado!`);
res.redirect('/courses');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ services:
class: ../../../../../Contexts/Mooc/CoursesCounter/application/Find/CoursesCounterFinder
arguments: ["@Mooc.coursesCounter.CoursesCounterRepository"]


Mooc.coursesCounter.FindCoursesCounterQueryHandler:
class: ../../../../../Contexts/Mooc/CoursesCounter/application/Find/FindCoursesCounterQueryHandler
arguments: ["@Mooc.coursesCounter.CoursesCounterFinder"]
tags:
- { name: 'queryHandler' }