From 260f1150080224c6335d8517c122d81460e5c065 Mon Sep 17 00:00:00 2001 From: Supan Adit Pratama Date: Sat, 2 Nov 2024 11:08:35 +0700 Subject: [PATCH] feat: separate each skeleton controller --- .../skeleton-crud.controller.interface.ts | 18 +++-- libs/skeleton/src/skeleton-crud.controller.ts | 72 ++++++++++++++++++- 2 files changed, 85 insertions(+), 5 deletions(-) diff --git a/libs/skeleton/src/interfaces/controller/skeleton-crud.controller.interface.ts b/libs/skeleton/src/interfaces/controller/skeleton-crud.controller.interface.ts index fa4fb85..215186d 100644 --- a/libs/skeleton/src/interfaces/controller/skeleton-crud.controller.interface.ts +++ b/libs/skeleton/src/interfaces/controller/skeleton-crud.controller.interface.ts @@ -1,17 +1,25 @@ import { IPaginationParam } from '../pagination-param.interface'; -export interface ISkeletonReadController { - list(); - read(id); +export interface ISkeletonPaginationController { pagination(params: IPaginationParam); } +export interface ISkeletonListController { + list(); +} + +export interface ISkeletonReadController { + read(id); +} + export interface ISkeletonDeleteController { delete(id); } + export interface ISkeletonCreateController { create(body); } + export interface ISkeletonUpdateController { update(id, body); } @@ -20,4 +28,6 @@ export interface ISkeletonCRUDController extends ISkeletonCreateController, ISkeletonReadController, ISkeletonDeleteController, - ISkeletonUpdateController {} + ISkeletonUpdateController, + ISkeletonListController, + ISkeletonPaginationController {} diff --git a/libs/skeleton/src/skeleton-crud.controller.ts b/libs/skeleton/src/skeleton-crud.controller.ts index 9369349..0ef2cc5 100644 --- a/libs/skeleton/src/skeleton-crud.controller.ts +++ b/libs/skeleton/src/skeleton-crud.controller.ts @@ -26,7 +26,77 @@ import { ListExecutor } from './executors/list.executor'; import { ReadExecutor } from './executors/read.executor'; import { UpdateExecutor } from './executors/update.executor'; import { ControllerOption } from './interfaces/controller/controller.option'; -import { ISkeletonCRUDController } from './interfaces/controller/skeleton-crud.controller.interface'; +import { + ISkeletonCreateController, + ISkeletonCRUDController, + ISkeletonListController, + ISkeletonPaginationController, + ISkeletonReadController, + ISkeletonUpdateController, +} from './interfaces/controller/skeleton-crud.controller.interface'; + +export class SkeletonReadController implements ISkeletonReadController { + constructor( + @Inject(READ_PROCESS) + public readonly readProcess, + ) {} + + @Get(':id') + async read(@Param('id') identity) { + return await ReadExecutor.bootstrap(this.readProcess, identity); + } +} + +export class SkeletonCreateController implements ISkeletonCreateController { + constructor( + @Inject(CREATE_PROCESS) + public readonly createProcess, + ) {} + + @Post() + async create(@Body() body) { + return await CreateExcutor.bootstrap(this.createProcess, body); + } +} + +export class SkeletonListController implements ISkeletonListController { + constructor( + @Inject(LIST_PROCESS) + public readonly listProcess, + ) {} + + @Get('list') + async list() { + return await ListExecutor.bootstrap(this.listProcess); + } +} + +export class SkeletonPaginationController + implements ISkeletonPaginationController +{ + constructor( + @Inject(PAGINATION_PROCESS) + public readonly paginationProcess, + ) {} + + @Get() + @UsePipes(new ValidationPipe({ transform: true })) + async pagination(@Query() params: PaginationParamDTO) { + return await PaginationExecutor.bootstrap(this.paginationProcess, params); + } +} + +export class SkeletonUpdateController implements ISkeletonUpdateController { + constructor( + @Inject(UPDATE_PROCESS) + public readonly updateProcess, + ) {} + + @Patch(':id') + async update(@Param('id') identity, @Body() body) { + return await UpdateExecutor.bootstrap(this.updateProcess, identity, body); + } +} export class SkeletonCRUDController implements ISkeletonCRUDController { constructor(