Skip to content

Commit 88b9fbf

Browse files
committed
Add the http verb to the name of the controllers
1 parent 7c052b9 commit 88b9fbf

File tree

7 files changed

+27
-20
lines changed

7 files changed

+27
-20
lines changed

src/apps/mooc_backend/config/dependency-injection/application.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ services:
77
class: ../../../../Contexts/Mooc/Courses/application/CreateCourse
88
arguments: ["@Mooc.courses.CourseRepository"]
99

10-
Apps.mooc.controllers.CreateCourseController:
11-
class: ../../controllers/CreateCourseController
10+
Apps.mooc.controllers.CoursePutController:
11+
class: ../../controllers/CoursePutController
1212
arguments: ["@Mooc.courses.CreateCourse"]
1313

14-
Apps.mooc.controllers.StatusController:
15-
class: ../../controllers/StatusController
14+
Apps.mooc.controllers.StatusGetController:
15+
class: ../../controllers/StatusGetController
1616
arguments: []
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import {Request, Response} from 'express';
2+
3+
export default interface Controller {
4+
run(req: Request, res: Response): Promise<void>;
5+
}

src/apps/mooc_backend/controllers/CreateCourseController.ts renamed to src/apps/mooc_backend/controllers/CoursePutController.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { Request, Response } from 'express';
22
import CreateCourse from '../../../Contexts/Mooc/Courses/application/CreateCourse';
33
import httpStatus from 'http-status';
4+
import Controller from './Controller';
45

5-
export default class CreateCourseController {
6+
export default class CoursePutController implements Controller {
67
constructor(private createCourse: CreateCourse) {}
78

8-
async create(req: Request, res: Response) {
9+
async run(req: Request, res: Response) {
910
const id: string = req.params.id;
1011
const name: string = req.body.name;
1112
const duration: string = req.body.duration;

src/apps/mooc_backend/controllers/StatusController.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Request, Response } from 'express';
2+
import httpStatus from 'http-status';
3+
import Controller from './Controller';
4+
5+
export default class StatusGetController implements Controller {
6+
async run(req: Request, res: Response) {
7+
res.status(httpStatus.OK).send();
8+
}
9+
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Express } from 'express';
22
import container from '../config/dependency-injection';
3-
import CreateCourseController from '../controllers/CreateCourseController';
3+
import CreateCourseController from '../controllers/CoursePutController';
44

55
export const register = (app: Express) => {
6-
const controller: CreateCourseController = container.get('Apps.mooc.controllers.CreateCourseController');
7-
app.put('/courses/:id', controller.create.bind(controller));
6+
const controller: CreateCourseController = container.get('Apps.mooc.controllers.CoursePutController');
7+
app.put('/courses/:id', controller.run.bind(controller));
88
};
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Express } from 'express';
22
import container from '../config/dependency-injection';
3-
import StatusController from '../controllers/StatusController';
3+
import StatusController from '../controllers/StatusGetController';
44

55
export const register = (app: Express) => {
6-
const controller: StatusController = container.get('Apps.mooc.controllers.StatusController');
7-
app.get('/status', controller.create.bind(controller));
6+
const controller: StatusController = container.get('Apps.mooc.controllers.StatusGetController');
7+
app.get('/status', controller.run.bind(controller));
88
};

0 commit comments

Comments
 (0)