Skip to content

Commit 6d99bc3

Browse files
committed
refactor: remove BaseController inheritance and adjusting method signatures
1 parent 9a29024 commit 6d99bc3

8 files changed

+37
-83
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
1-
import { BaseController, StatusCode } from "@expressots/core";
2-
import { controller, Delete, param, response } from "@expressots/adapter-express";
3-
import { Response } from "express";
1+
import { controller, Delete, param } from "@expressots/adapter-express";
2+
import { inject } from "@expressots/core";
43
import { {{className}}UseCase } from "./{{fileName}}.usecase";
5-
import { I{{className}}RequestDTO, I{{className}}ResponseDTO } from "./{{fileName}}.dto";
64

75
@controller("/{{{route}}}")
8-
export class {{className}}Controller extends BaseController {
9-
constructor(private {{useCase}}UseCase: {{className}}UseCase) {
10-
super();
11-
}
6+
export class {{className}}Controller {
7+
@inject({{className}}UseCase) private {{useCase}}UseCase: {{className}}UseCase;
128

139
@Delete("/:id")
14-
execute(@param("id") id: string, @response() res: Response): I{{className}}ResponseDTO {
15-
return this.callUseCase(
16-
this.{{useCase}}UseCase.execute(id),
17-
res,
18-
StatusCode.OK,
19-
);
10+
execute(@param("id") id: string) {
11+
return this.{{useCase}}UseCase.execute(id);
2012
}
2113
}
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
1-
import { BaseController, StatusCode } from "@expressots/core";
2-
import { controller, Get, response } from "@expressots/adapter-express";
3-
import { Response } from "express";
1+
import { controller, Get } from "@expressots/adapter-express";
2+
import { inject } from "@expressots/core";
43
import { {{className}}UseCase } from "./{{fileName}}.usecase";
5-
import { I{{className}}ResponseDTO } from "./{{fileName}}.dto";
64

75
@controller("/{{{route}}}")
8-
export class {{className}}Controller extends BaseController {
9-
constructor(private {{useCase}}UseCase: {{className}}UseCase) {
10-
super();
11-
}
12-
6+
export class {{className}}Controller {
7+
@inject({{className}}UseCase) private {{useCase}}UseCase: {{className}}UseCase;
8+
139
@Get("/")
14-
execute(@response() res: Response): I{{className}}ResponseDTO {
15-
return this.callUseCase(
16-
this.{{useCase}}UseCase.execute(),
17-
res,
18-
StatusCode.OK,
19-
);
10+
execute() {
11+
return this.{{useCase}}UseCase.execute();
2012
}
2113
}
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,14 @@
1-
import { BaseController, StatusCode } from "@expressots/core";
2-
import { controller, Patch, body, param, response } from "@expressots/adapter-express";
3-
import { Response } from "express";
1+
import { controller, Patch, body } from "@expressots/adapter-express";
2+
import { inject } from "@expressots/core";
43
import { {{className}}UseCase } from "./{{fileName}}.usecase";
5-
import { I{{className}}RequestDTO, I{{className}}ResponseDTO } from "./{{fileName}}.dto";
4+
import { I{{className}}RequestDTO } from "./{{fileName}}.dto";
65

76
@controller("/{{{route}}}")
8-
export class {{className}}Controller extends BaseController {
9-
constructor(private {{useCase}}UseCase: {{className}}UseCase) {
10-
super();
11-
}
7+
export class {{className}}Controller {
8+
@inject({{className}}UseCase) private {{useCase}}UseCase: {{className}}UseCase;
129

1310
@Patch("/")
14-
execute(
15-
@body() payload: I{{className}}RequestDTO,
16-
@response() res: Response,
17-
): I{{className}}ResponseDTO {
18-
return this.callUseCase(
19-
this.{{useCase}}UseCase.execute(payload),
20-
res,
21-
StatusCode.OK,
22-
);
11+
execute(@body() payload: I{{className}}RequestDTO) {
12+
return this.{{useCase}}UseCase.execute(payload);
2313
}
2414
}
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
1-
import { BaseController, StatusCode } from "@expressots/core";
2-
import { controller, Post, body, response } from "@expressots/adapter-express";
3-
import { Response } from "express";
1+
import { body, controller, Post } from "@expressots/adapter-express";
2+
import { inject } from "@expressots/core";
43
import { {{className}}UseCase } from "./{{fileName}}.usecase";
5-
import { I{{className}}RequestDTO, I{{className}}ResponseDTO } from "./{{fileName}}.dto";
4+
import { I{{className}}RequestDTO } from "./{{fileName}}.dto";
65

76
@controller("/{{{route}}}")
8-
export class {{className}}Controller extends BaseController {
9-
constructor(private {{useCase}}UseCase: {{className}}UseCase) {
10-
super();
11-
}
7+
export class {{className}}Controller {
8+
@inject({{className}}UseCase) private {{useCase}}UseCase: {{className}}UseCase;
129

1310
@Post("/")
14-
execute(@body() payload: I{{className}}RequestDTO, @response() res: Response): I{{className}}ResponseDTO {
15-
return this.callUseCase(
16-
this.{{useCase}}UseCase.execute(payload),
17-
res,
18-
StatusCode.Created,
19-
);
11+
execute(@body() payload: I{{className}}RequestDTO) {
12+
return this.{{useCase}}UseCase.execute(payload);
2013
}
2114
}
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,14 @@
1-
import { BaseController, StatusCode } from "@expressots/core";
2-
import { controller, Put, body, param, response } from "@expressots/adapter-express";
3-
import { Response } from "express";
1+
import { body, controller, Put } from "@expressots/adapter-express";
2+
import { inject } from "@expressots/core";
43
import { {{className}}UseCase } from "./{{fileName}}.usecase";
5-
import { I{{className}}RequestDTO, I{{className}}ResponseDTO } from "./{{fileName}}.dto";
4+
import { I{{className}}RequestDTO } from "./{{fileName}}.dto";
65

76
@controller("/{{{route}}}")
8-
export class {{className}}Controller extends BaseController {
9-
constructor(private {{useCase}}UseCase: {{className}}UseCase) {
10-
super();
11-
}
7+
export class {{className}}Controller {
8+
@inject({{className}}UseCase) private {{useCase}}UseCase: {{className}}UseCase;
129

1310
@Put("/")
14-
execute(
15-
@body() payload: I{{className}}RequestDTO,
16-
@response() res: Response,
17-
): I{{className}}ResponseDTO {
18-
return this.callUseCase(
19-
this.{{useCase}}UseCase.execute(payload),
20-
res,
21-
StatusCode.OK,
22-
);
11+
execute(@body() payload: I{{className}}RequestDTO) {
12+
return this.{{useCase}}UseCase.execute(payload);
2313
}
2414
}

src/generate/templates/opinionated/controller-service.tpl

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { BaseController } from "@expressots/core";
21
import { controller, {{method}} } from "@expressots/adapter-express";
32

43
@controller("/{{{route}}}")
5-
export class {{className}}Controller extends BaseController {
4+
export class {{className}}Controller {
65
@{{method}}("/")
76
execute() {
87
return "Ok";
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { ContainerModule } from "inversify";
2-
import { CreateModule } from "@expressots/core";
1+
import { CreateModule, ContainerModule } from "@expressots/core";
32
import { {{className}}Controller } from "{{{path}}}";
43

54
export const {{moduleName}}Module: ContainerModule = CreateModule([{{className}}Controller]);
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { ContainerModule } from "inversify";
2-
import { CreateModule } from "@expressots/core";
1+
import { CreateModule, ContainerModule } from "@expressots/core";
32

43
export const {{moduleName}}Module: ContainerModule = CreateModule([]);

0 commit comments

Comments
 (0)