diff --git a/src/app.module.ts b/src/app.module.ts index 39d34ec..e0649c2 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -3,11 +3,12 @@ import { InputGrpcClientModule } from './inputs/input-grpc-client.module'; import { UsersGrpcClientModule } from './users-grpc-client/users-grpc-client.module'; import { OutputsModule } from './outputs/outputs.module'; import { EnrichmentModule } from './enrichment/enrichment.module'; +import { TransformationsModule } from './transformations/transformations.module'; @Module({ imports: [ InputGrpcClientModule, - OutputsModule, EnrichmentModule + OutputsModule, EnrichmentModule, TransformationsModule ], controllers: [], providers: [], diff --git a/src/enrichment/enrichment.controller.ts b/src/enrichment/enrichment.controller.ts index 53d4c31..dc1ab55 100644 --- a/src/enrichment/enrichment.controller.ts +++ b/src/enrichment/enrichment.controller.ts @@ -1,4 +1,4 @@ -import { Controller, Delete, Get, Param, Post, Put } from '@nestjs/common'; +import { Controller, Delete, Get, OnModuleInit, Param, Post, Put } from '@nestjs/common'; import { Client, ClientGrpc, Payload } from '@nestjs/microservices'; import { EnrichmentGrpcClientService } from './enrichment.service'; import { CreateEnrichmentDto } from './dto/create-enrichment.dto'; @@ -8,7 +8,7 @@ import { GrpcClientConfiguration } from './config/grpc-client'; @ApiTags('enrichments') @Controller('enrichment') -export class EnrichmentController { +export class EnrichmentController implements OnModuleInit { diff --git a/src/transformations/config/grpc-client.ts b/src/transformations/config/grpc-client.ts new file mode 100644 index 0000000..f918bed --- /dev/null +++ b/src/transformations/config/grpc-client.ts @@ -0,0 +1,17 @@ +import { join } from 'path'; +import { ClientOptions, Transport } from '@nestjs/microservices'; + +export const GrpcClientConfiguration: ClientOptions = { + transport: Transport.GRPC, + options: { + //url: `${process.env.USERS_SVC_URL}:${process.env.USERS_SVC_PORT}`, + url: `127.0.0.1:50054`, + package: 'transformation', + protoPath: join(__dirname, '..', 'proto', 'transformation.proto'), + loader: { + enums: String, + objects: true, + arrays: true, + }, + }, +}; diff --git a/src/transformations/dto/create-transformation.dto.ts b/src/transformations/dto/create-transformation.dto.ts new file mode 100644 index 0000000..ec9cea1 --- /dev/null +++ b/src/transformations/dto/create-transformation.dto.ts @@ -0,0 +1,11 @@ + + +export class CreateTransformationDto { + inputSource:string; + + table:string; + + type:string; + + params:string; +} diff --git a/src/transformations/dto/update-transformation.dto.ts b/src/transformations/dto/update-transformation.dto.ts new file mode 100644 index 0000000..b9fcab6 --- /dev/null +++ b/src/transformations/dto/update-transformation.dto.ts @@ -0,0 +1,5 @@ +import { PartialType } from '@nestjs/mapped-types'; +import { CreateTransformationDto } from './create-transformation.dto'; + +export class UpdateTransformationDto extends PartialType(CreateTransformationDto) { +} diff --git a/src/transformations/entities/transformation.entity.ts b/src/transformations/entities/transformation.entity.ts new file mode 100644 index 0000000..9ac2de3 --- /dev/null +++ b/src/transformations/entities/transformation.entity.ts @@ -0,0 +1,14 @@ +export class Transformation { + + id:string; + + inputSource:string; + + table:string; + + type:string; + + params:string; + + +} diff --git a/src/transformations/proto/transformation.proto b/src/transformations/proto/transformation.proto new file mode 100644 index 0000000..e4658be --- /dev/null +++ b/src/transformations/proto/transformation.proto @@ -0,0 +1,50 @@ +syntax = "proto3"; + +package transformation; + + +import "google/protobuf/timestamp.proto"; + + + +service TransformationService { + rpc Create(CreateTransformationRequest) returns (Transformation) {} + rpc Show(IdRequest) returns (Transformation) {} + rpc List(Empty) returns (ListResponse){} + rpc Update(UpdateTransformationRequest) returns (Transformation){} + rpc Remove(IdRequest) returns (Empty){} +} + +message Empty {} + +message IdRequest{ + string id = 1; +} + +message UpdateTransformationRequest{ + string id = 1; + string inputSource = 2; + string table = 3; + string type = 4; + string params = 5; +} + +message Transformation { + string id = 1; + string inputSource = 2; + string table = 3; + string type = 4; + string params = 5; +} + +message CreateTransformationRequest { + string inputSource = 1; + string table = 2; + string type = 3; + string params = 4; +} + +message ListResponse { + repeated Transformation transformations = 2; +} + diff --git a/src/transformations/transformations.controller.spec.ts b/src/transformations/transformations.controller.spec.ts new file mode 100644 index 0000000..3808377 --- /dev/null +++ b/src/transformations/transformations.controller.spec.ts @@ -0,0 +1,20 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { TransformationsController } from './transformations.controller'; +import { TransformationGrpcClientService } from './transformations.service'; + +describe('TransformationsController', () => { + let controller: TransformationsController; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + controllers: [TransformationsController], + providers: [TransformationGrpcClientService], + }).compile(); + + controller = module.get(TransformationsController); + }); + + it('should be defined', () => { + expect(controller).toBeDefined(); + }); +}); diff --git a/src/transformations/transformations.controller.ts b/src/transformations/transformations.controller.ts new file mode 100644 index 0000000..714f5aa --- /dev/null +++ b/src/transformations/transformations.controller.ts @@ -0,0 +1,48 @@ +import { Controller, Delete, Get, OnModuleInit, Param, Post, Put } from '@nestjs/common'; +import { Client, ClientGrpc, MessagePattern, Payload } from '@nestjs/microservices'; +import { TransformationGrpcClientService } from './transformations.service'; +import { CreateTransformationDto } from './dto/create-transformation.dto'; +import { UpdateTransformationDto } from './dto/update-transformation.dto'; +import { ApiTags } from '@nestjs/swagger'; +import { GrpcClientConfiguration } from './config/grpc-client'; + +@ApiTags('transformations') +@Controller('transformation') +export class TransformationsController implements OnModuleInit { + + @Client(GrpcClientConfiguration) + private transformationServiceClient: ClientGrpc; + + private transformationService: TransformationGrpcClientService; + + onModuleInit() { + this.transformationService = + this.transformationServiceClient.getService('TransformationService'); + } + + @Post() + create(@Payload() createTransformationDto: CreateTransformationDto[]) { + + return createTransformationDto.map( transf => this.transformationService.create(transf)) + } + + @Get() + list() { + return this.transformationService.list(); + } + + @Get(':id') + show(@Payload() id: string) { + return this.transformationService.show(id); + } + + @Put(':id') + update(@Param() id:string,@Payload() updateTransformationDto: UpdateTransformationDto) { + return this.transformationService.update(id, updateTransformationDto); + } + + @Delete(':id') + remove(@Param() id: string) { + return this.transformationService.remove(id); + } +} diff --git a/src/transformations/transformations.module.ts b/src/transformations/transformations.module.ts new file mode 100644 index 0000000..5114394 --- /dev/null +++ b/src/transformations/transformations.module.ts @@ -0,0 +1,9 @@ +import { Module } from '@nestjs/common'; +import { TransformationGrpcClientService } from './transformations.service'; +import { TransformationsController } from './transformations.controller'; + +@Module({ + controllers: [TransformationsController], + providers: [TransformationGrpcClientService] +}) +export class TransformationsModule {} diff --git a/src/transformations/transformations.service.spec.ts b/src/transformations/transformations.service.spec.ts new file mode 100644 index 0000000..1c78677 --- /dev/null +++ b/src/transformations/transformations.service.spec.ts @@ -0,0 +1,18 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { TransformationsService } from './transformations.service'; + +describe('TransformationsService', () => { + let service: TransformationsService; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + providers: [TransformationsService], + }).compile(); + + service = module.get(TransformationsService); + }); + + it('should be defined', () => { + expect(service).toBeDefined(); + }); +}); diff --git a/src/transformations/transformations.service.ts b/src/transformations/transformations.service.ts new file mode 100644 index 0000000..2191c1e --- /dev/null +++ b/src/transformations/transformations.service.ts @@ -0,0 +1,26 @@ +import { Injectable } from '@nestjs/common'; +import { CreateTransformationDto } from './dto/create-transformation.dto'; +import { UpdateTransformationDto } from './dto/update-transformation.dto'; + +@Injectable() +export class TransformationGrpcClientService { + create(createTransformationDto: CreateTransformationDto) { + return 'This action adds a new transformation'; + } + + list() { + return `This action returns all transformations`; + } + + show(id: string) { + return `This action returns a #${id} transformation`; + } + + update(id: string, updateTransformationDto: UpdateTransformationDto) { + return `This action updates a #${id} transformation`; + } + + remove(id: string) { + return `This action removes a #${id} transformation`; + } +} diff --git a/swagger.json b/swagger.json index 5753d1f..63768f9 100644 --- a/swagger.json +++ b/swagger.json @@ -1 +1 @@ -{"openapi":"3.0.0","paths":{"/input":{"post":{"operationId":"InputGrpcClientController_create","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateInputGrpcClientDto"}}}},"responses":{"201":{"description":""}},"tags":["inputs"]},"get":{"operationId":"InputGrpcClientController_list","parameters":[],"responses":{"200":{"description":""}},"tags":["inputs"]}},"/input/{id}":{"get":{"operationId":"InputGrpcClientController_show","parameters":[],"responses":{"200":{"description":""}},"tags":["inputs"]},"put":{"operationId":"InputGrpcClientController_update","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpdateInputGrpcClientDto"}}}},"responses":{"200":{"description":""}},"tags":["inputs"]},"delete":{"operationId":"InputGrpcClientController_remove","parameters":[],"responses":{"200":{"description":""}},"tags":["inputs"]}},"/input/test-connection":{"get":{"operationId":"InputGrpcClientController_testConnection","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/TestConnectionDTO"}}}},"responses":{"200":{"description":""}},"tags":["inputs"]}},"/output":{"post":{"operationId":"OutputsController_create","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateOutputDto"}}}},"responses":{"201":{"description":""}},"tags":["outputs"]},"get":{"operationId":"OutputsController_show","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"string"}}}},"responses":{"200":{"description":""}},"tags":["outputs"]}},"/output/{id}":{"put":{"operationId":"OutputsController_update","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpdateOutputDto"}}}},"responses":{"200":{"description":""}},"tags":["outputs"]},"delete":{"operationId":"OutputsController_remove","parameters":[],"responses":{"200":{"description":""}},"tags":["outputs"]}}},"info":{"title":"Maestro Grpc Documentation","description":"Documentation for Maestro gateway","version":"1.0","contact":{}},"tags":[{"name":"inputs","description":""}],"servers":[],"components":{"schemas":{"CreateInputGrpcClientDto":{"type":"object","properties":{"cron":{"type":"string"},"name":{"type":"string","description":"Name of the input","example":"Test Name"},"plugin":{"type":"string"},"values":{"type":"string"},"operation":{"type":"string"}},"required":["cron","name","plugin","values","operation"]},"UpdateInputGrpcClientDto":{"type":"object","properties":{}},"TestConnectionDTO":{"type":"object","properties":{}},"CreateOutputDto":{"type":"object","properties":{}},"UpdateOutputDto":{"type":"object","properties":{}}}}} \ No newline at end of file +{"openapi":"3.0.0","paths":{"/input":{"post":{"operationId":"InputGrpcClientController_create","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateInputGrpcClientDto"}}}},"responses":{"201":{"description":""}},"tags":["inputs"]},"get":{"operationId":"InputGrpcClientController_list","parameters":[],"responses":{"200":{"description":""}},"tags":["inputs"]}},"/input/{id}":{"get":{"operationId":"InputGrpcClientController_show","parameters":[],"responses":{"200":{"description":""}},"tags":["inputs"]},"put":{"operationId":"InputGrpcClientController_update","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpdateInputGrpcClientDto"}}}},"responses":{"200":{"description":""}},"tags":["inputs"]},"delete":{"operationId":"InputGrpcClientController_remove","parameters":[],"responses":{"200":{"description":""}},"tags":["inputs"]}},"/input/test-connection":{"get":{"operationId":"InputGrpcClientController_testConnection","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/TestConnectionDTO"}}}},"responses":{"200":{"description":""}},"tags":["inputs"]}},"/output":{"post":{"operationId":"OutputsController_create","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateOutputDto"}}}},"responses":{"201":{"description":""}},"tags":["outputs"]},"get":{"operationId":"OutputsController_list","parameters":[],"responses":{"200":{"description":""}},"tags":["outputs"]}},"/output/{id}":{"get":{"operationId":"OutputsController_show","parameters":[],"responses":{"200":{"description":""}},"tags":["outputs"]},"put":{"operationId":"OutputsController_update","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpdateOutputDto"}}}},"responses":{"200":{"description":""}},"tags":["outputs"]},"delete":{"operationId":"OutputsController_remove","parameters":[],"responses":{"200":{"description":""}},"tags":["outputs"]}},"/enrichment":{"post":{"operationId":"EnrichmentController_create","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateEnrichmentDto"}}}},"responses":{"201":{"description":""}},"tags":["enrichments"]},"get":{"operationId":"EnrichmentController_list","parameters":[],"responses":{"200":{"description":""}},"tags":["enrichments"]}},"/enrichment/{id}":{"get":{"operationId":"EnrichmentController_show","parameters":[],"responses":{"200":{"description":""}},"tags":["enrichments"]},"put":{"operationId":"EnrichmentController_update","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpdateEnrichmentDto"}}}},"responses":{"200":{"description":""}},"tags":["enrichments"]},"delete":{"operationId":"EnrichmentController_remove","parameters":[],"responses":{"200":{"description":""}},"tags":["enrichments"]}},"/transformation":{"post":{"operationId":"TransformationsController_create","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"array","items":{"type":"string"}}}}},"responses":{"201":{"description":""}},"tags":["transformations"]},"get":{"operationId":"TransformationsController_list","parameters":[],"responses":{"200":{"description":""}},"tags":["transformations"]}},"/transformation/{id}":{"get":{"operationId":"TransformationsController_show","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"string"}}}},"responses":{"200":{"description":""}},"tags":["transformations"]},"put":{"operationId":"TransformationsController_update","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpdateTransformationDto"}}}},"responses":{"200":{"description":""}},"tags":["transformations"]},"delete":{"operationId":"TransformationsController_remove","parameters":[],"responses":{"200":{"description":""}},"tags":["transformations"]}}},"info":{"title":"Maestro Grpc Documentation","description":"Documentation for Maestro gateway","version":"1.0","contact":{}},"tags":[{"name":"inputs","description":""}],"servers":[],"components":{"schemas":{"CreateInputGrpcClientDto":{"type":"object","properties":{"cron":{"type":"string"},"name":{"type":"string","description":"Name of the input","example":"Test Name"},"plugin":{"type":"string"},"values":{"type":"string"},"operation":{"type":"string"}},"required":["cron","name","plugin","values","operation"]},"UpdateInputGrpcClientDto":{"type":"object","properties":{}},"TestConnectionDTO":{"type":"object","properties":{}},"CreateOutputDto":{"type":"object","properties":{}},"UpdateOutputDto":{"type":"object","properties":{}},"CreateEnrichmentDto":{"type":"object","properties":{}},"UpdateEnrichmentDto":{"type":"object","properties":{}},"UpdateTransformationDto":{"type":"object","properties":{}}}}} \ No newline at end of file