Skip to content

Commit

Permalink
refactor: remove BaseController inheritance and adjusting method sign…
Browse files Browse the repository at this point in the history
…atures
  • Loading branch information
rsaz committed Nov 19, 2024
1 parent 9a29024 commit 6d99bc3
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 83 deletions.
20 changes: 6 additions & 14 deletions src/generate/templates/opinionated/controller-service-delete.tpl
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
import { BaseController, StatusCode } from "@expressots/core";
import { controller, Delete, param, response } from "@expressots/adapter-express";
import { Response } from "express";
import { controller, Delete, param } from "@expressots/adapter-express";
import { inject } from "@expressots/core";
import { {{className}}UseCase } from "./{{fileName}}.usecase";
import { I{{className}}RequestDTO, I{{className}}ResponseDTO } from "./{{fileName}}.dto";

@controller("/{{{route}}}")
export class {{className}}Controller extends BaseController {
constructor(private {{useCase}}UseCase: {{className}}UseCase) {
super();
}
export class {{className}}Controller {
@inject({{className}}UseCase) private {{useCase}}UseCase: {{className}}UseCase;

@Delete("/:id")
execute(@param("id") id: string, @response() res: Response): I{{className}}ResponseDTO {
return this.callUseCase(
this.{{useCase}}UseCase.execute(id),
res,
StatusCode.OK,
);
execute(@param("id") id: string) {
return this.{{useCase}}UseCase.execute(id);
}
}
22 changes: 7 additions & 15 deletions src/generate/templates/opinionated/controller-service-get.tpl
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
import { BaseController, StatusCode } from "@expressots/core";
import { controller, Get, response } from "@expressots/adapter-express";
import { Response } from "express";
import { controller, Get } from "@expressots/adapter-express";
import { inject } from "@expressots/core";
import { {{className}}UseCase } from "./{{fileName}}.usecase";
import { I{{className}}ResponseDTO } from "./{{fileName}}.dto";

@controller("/{{{route}}}")
export class {{className}}Controller extends BaseController {
constructor(private {{useCase}}UseCase: {{className}}UseCase) {
super();
}

export class {{className}}Controller {
@inject({{className}}UseCase) private {{useCase}}UseCase: {{className}}UseCase;

@Get("/")
execute(@response() res: Response): I{{className}}ResponseDTO {
return this.callUseCase(
this.{{useCase}}UseCase.execute(),
res,
StatusCode.OK,
);
execute() {
return this.{{useCase}}UseCase.execute();
}
}
24 changes: 7 additions & 17 deletions src/generate/templates/opinionated/controller-service-patch.tpl
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
import { BaseController, StatusCode } from "@expressots/core";
import { controller, Patch, body, param, response } from "@expressots/adapter-express";
import { Response } from "express";
import { controller, Patch, body } from "@expressots/adapter-express";
import { inject } from "@expressots/core";
import { {{className}}UseCase } from "./{{fileName}}.usecase";
import { I{{className}}RequestDTO, I{{className}}ResponseDTO } from "./{{fileName}}.dto";
import { I{{className}}RequestDTO } from "./{{fileName}}.dto";

@controller("/{{{route}}}")
export class {{className}}Controller extends BaseController {
constructor(private {{useCase}}UseCase: {{className}}UseCase) {
super();
}
export class {{className}}Controller {
@inject({{className}}UseCase) private {{useCase}}UseCase: {{className}}UseCase;

@Patch("/")
execute(
@body() payload: I{{className}}RequestDTO,
@response() res: Response,
): I{{className}}ResponseDTO {
return this.callUseCase(
this.{{useCase}}UseCase.execute(payload),
res,
StatusCode.OK,
);
execute(@body() payload: I{{className}}RequestDTO) {
return this.{{useCase}}UseCase.execute(payload);
}
}
21 changes: 7 additions & 14 deletions src/generate/templates/opinionated/controller-service-post.tpl
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
import { BaseController, StatusCode } from "@expressots/core";
import { controller, Post, body, response } from "@expressots/adapter-express";
import { Response } from "express";
import { body, controller, Post } from "@expressots/adapter-express";
import { inject } from "@expressots/core";
import { {{className}}UseCase } from "./{{fileName}}.usecase";
import { I{{className}}RequestDTO, I{{className}}ResponseDTO } from "./{{fileName}}.dto";
import { I{{className}}RequestDTO } from "./{{fileName}}.dto";

@controller("/{{{route}}}")
export class {{className}}Controller extends BaseController {
constructor(private {{useCase}}UseCase: {{className}}UseCase) {
super();
}
export class {{className}}Controller {
@inject({{className}}UseCase) private {{useCase}}UseCase: {{className}}UseCase;

@Post("/")
execute(@body() payload: I{{className}}RequestDTO, @response() res: Response): I{{className}}ResponseDTO {
return this.callUseCase(
this.{{useCase}}UseCase.execute(payload),
res,
StatusCode.Created,
);
execute(@body() payload: I{{className}}RequestDTO) {
return this.{{useCase}}UseCase.execute(payload);
}
}
24 changes: 7 additions & 17 deletions src/generate/templates/opinionated/controller-service-put.tpl
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
import { BaseController, StatusCode } from "@expressots/core";
import { controller, Put, body, param, response } from "@expressots/adapter-express";
import { Response } from "express";
import { body, controller, Put } from "@expressots/adapter-express";
import { inject } from "@expressots/core";
import { {{className}}UseCase } from "./{{fileName}}.usecase";
import { I{{className}}RequestDTO, I{{className}}ResponseDTO } from "./{{fileName}}.dto";
import { I{{className}}RequestDTO } from "./{{fileName}}.dto";

@controller("/{{{route}}}")
export class {{className}}Controller extends BaseController {
constructor(private {{useCase}}UseCase: {{className}}UseCase) {
super();
}
export class {{className}}Controller {
@inject({{className}}UseCase) private {{useCase}}UseCase: {{className}}UseCase;

@Put("/")
execute(
@body() payload: I{{className}}RequestDTO,
@response() res: Response,
): I{{className}}ResponseDTO {
return this.callUseCase(
this.{{useCase}}UseCase.execute(payload),
res,
StatusCode.OK,
);
execute(@body() payload: I{{className}}RequestDTO) {
return this.{{useCase}}UseCase.execute(payload);
}
}
3 changes: 1 addition & 2 deletions src/generate/templates/opinionated/controller-service.tpl
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { BaseController } from "@expressots/core";
import { controller, {{method}} } from "@expressots/adapter-express";

@controller("/{{{route}}}")
export class {{className}}Controller extends BaseController {
export class {{className}}Controller {
@{{method}}("/")
execute() {
return "Ok";
Expand Down
3 changes: 1 addition & 2 deletions src/generate/templates/opinionated/module-service.tpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ContainerModule } from "inversify";
import { CreateModule } from "@expressots/core";
import { CreateModule, ContainerModule } from "@expressots/core";
import { {{className}}Controller } from "{{{path}}}";

export const {{moduleName}}Module: ContainerModule = CreateModule([{{className}}Controller]);
3 changes: 1 addition & 2 deletions src/generate/templates/opinionated/module.tpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ContainerModule } from "inversify";
import { CreateModule } from "@expressots/core";
import { CreateModule, ContainerModule } from "@expressots/core";

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

0 comments on commit 6d99bc3

Please sign in to comment.