implementation of enrichment module on gateway

This commit is contained in:
rodrigo.zamboni
2022-01-19 15:08:47 -03:00
parent 79ed958b83
commit 07ab5048c2
11 changed files with 205 additions and 2 deletions
+17
View File
@@ -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:50053`,
package: 'enrichment',
protoPath: join(__dirname, '..', 'proto', 'enrichment.proto'),
loader: {
enums: String,
objects: true,
arrays: true,
},
},
};
@@ -0,0 +1,6 @@
export class CreateEnrichmentDto {
type:string;
columns:string[]
}
@@ -0,0 +1,6 @@
import { PartialType } from '@nestjs/mapped-types';
import { CreateEnrichmentDto } from './create-enrichment.dto';
export class UpdateEnrichmentDto extends PartialType(CreateEnrichmentDto) {
}
@@ -0,0 +1,20 @@
import { Test, TestingModule } from '@nestjs/testing';
import { EnrichmentController } from './enrichment.controller';
import { EnrichmentGrpcClientService } from './enrichment.service';
describe('EnrichmentController', () => {
let controller: EnrichmentController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [EnrichmentController],
providers: [EnrichmentGrpcClientService],
}).compile();
controller = module.get<EnrichmentController>(EnrichmentController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
});
+49
View File
@@ -0,0 +1,49 @@
import { Controller, Delete, Get, 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';
import { UpdateEnrichmentDto } from './dto/update-enrichment.dto';
import { ApiTags } from '@nestjs/swagger';
import { GrpcClientConfiguration } from './config/grpc-client';
@ApiTags('enrichments')
@Controller('enrichment')
export class EnrichmentController {
@Client(GrpcClientConfiguration)
private enrichmentServiceClient: ClientGrpc;
private enrichmentService: EnrichmentGrpcClientService;
onModuleInit() {
this.enrichmentService =
this.enrichmentServiceClient.getService<EnrichmentGrpcClientService>('EnrichmentService');
}
@Post()
create(@Payload() createEnrichmentDto: CreateEnrichmentDto) {
return this.enrichmentService.create(createEnrichmentDto);
}
@Get()
list() {
return this.enrichmentService.list();
}
@Get(':id')
show(@Param() id: string) {
return this.enrichmentService.show(id);
}
@Put(':id')
update(@Param() id:string,@Payload() updateEnrichmentDto: UpdateEnrichmentDto) {
return this.enrichmentService.update(id, updateEnrichmentDto);
}
@Delete(':id')
remove(@Param() id: string) {
return this.enrichmentService.remove(id);
}
}
+9
View File
@@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { EnrichmentGrpcClientService } from './enrichment.service';
import { EnrichmentController } from './enrichment.controller';
@Module({
controllers: [EnrichmentController],
providers: [EnrichmentGrpcClientService]
})
export class EnrichmentModule {}
+18
View File
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { EnrichmentService } from './enrichment.service';
describe('EnrichmentService', () => {
let service: EnrichmentService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [EnrichmentService],
}).compile();
service = module.get<EnrichmentService>(EnrichmentService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});
+26
View File
@@ -0,0 +1,26 @@
import { Injectable } from '@nestjs/common';
import { CreateEnrichmentDto } from './dto/create-enrichment.dto';
import { UpdateEnrichmentDto } from './dto/update-enrichment.dto';
@Injectable()
export class EnrichmentGrpcClientService {
create(createEnrichmentDto: CreateEnrichmentDto) {
return 'This action adds a new enrichment';
}
list() {
return `This action returns all enrichment`;
}
show(id: string) {
return `This action returns a #${id} enrichment`;
}
update(id: string, updateEnrichmentDto: UpdateEnrichmentDto) {
return `This action updates a #${id} enrichment`;
}
remove(id: string) {
return `This action removes a #${id} enrichment`;
}
}
@@ -0,0 +1,8 @@
export class Enrichment {
id:string;
type:string;
columns:string[]
}
+44
View File
@@ -0,0 +1,44 @@
syntax = "proto3";
package enrichment;
import "google/protobuf/timestamp.proto";
service EnrichmentService {
rpc Create(CreateEnrichmentRequest) returns (Enrichment) {}
rpc Show(IdRequest) returns (Enrichment) {}
rpc List(Empty) returns (ListResponse){}
rpc Update(UpdateEnrichmentRequest) returns (Enrichment){}
rpc Remove(IdRequest) returns (Empty){}
}
message Empty {}
message IdRequest{
string id = 1;
}
message UpdateEnrichmentRequest{
string id = 1;
string type = 2;
repeated string columns = 3;
}
message Enrichment {
string id = 1;
string type = 2;
repeated string columns = 3;
}
message CreateEnrichmentRequest {
string type = 1;
repeated string columns = 2;
}
message ListResponse {
repeated Enrichment enrichments = 2;
}
+2 -2
View File
@@ -29,8 +29,8 @@ export class OutputsController implements OnModuleInit{
return this.outputService.list();
}
@Get()
show(@Payload() id: string) {
@Get(':id')
show(@Param() id: string) {
return this.outputService.show(id);
}