mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-25 06:00:06 +00:00
Initial Commit/ gateway-input-microservice-implementation
This commit is contained in:
@@ -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:50051`,
|
||||
package: 'user',
|
||||
protoPath: join(__dirname, '..', 'proto', 'user.proto'),
|
||||
loader: {
|
||||
enums: String,
|
||||
objects: true,
|
||||
arrays: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
export class CreateUsersGrpcClientDto {}
|
||||
@@ -0,0 +1,8 @@
|
||||
import { PartialType } from '@nestjs/mapped-types';
|
||||
import { CreateUsersGrpcClientDto } from './create-users-grpc-client.dto';
|
||||
|
||||
export class UpdateUsersGrpcClientDto extends PartialType(
|
||||
CreateUsersGrpcClientDto,
|
||||
) {
|
||||
id: number;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export class UsersGrpcClient {}
|
||||
@@ -0,0 +1,37 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package user;
|
||||
|
||||
|
||||
import "google/protobuf/timestamp.proto";
|
||||
|
||||
|
||||
|
||||
service UserService {
|
||||
rpc Create(UserRequest) returns (UserResponse) {}
|
||||
rpc Show(Empty) returns (ShowResponse) {}
|
||||
}
|
||||
|
||||
message Empty {}
|
||||
|
||||
message User {
|
||||
int32 id = 1;
|
||||
string name = 2;
|
||||
string email = 3;
|
||||
uint64 created_at = 4;
|
||||
string updated_at = 5;
|
||||
}
|
||||
|
||||
message UserRequest {
|
||||
string name = 1;
|
||||
string email = 2;
|
||||
|
||||
}
|
||||
|
||||
message UserResponse {
|
||||
User user = 1;
|
||||
}
|
||||
|
||||
message ShowResponse {
|
||||
repeated UserResponse users = 1;
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import {
|
||||
Get,
|
||||
Post,
|
||||
Controller,
|
||||
Delete,
|
||||
OnModuleInit,
|
||||
Put,
|
||||
Query,
|
||||
} from '@nestjs/common';
|
||||
import { Client, ClientGrpc, Payload } from '@nestjs/microservices';
|
||||
import { CreateUsersGrpcClientDto } from './dto/create-users-grpc-client.dto';
|
||||
import { UpdateUsersGrpcClientDto } from './dto/update-users-grpc-client.dto';
|
||||
import { UsersGrpcClientService } from './users-grpc-client.service';
|
||||
import { GrpcClientConfiguration } from './config/grpc-client';
|
||||
|
||||
@Controller('users-grpc-client')
|
||||
export class UsersGrpcClientController implements OnModuleInit {
|
||||
@Client(GrpcClientConfiguration)
|
||||
private usersServiceClient: ClientGrpc;
|
||||
|
||||
private usersService: UsersGrpcClientService;
|
||||
|
||||
onModuleInit() {
|
||||
this.usersService =
|
||||
this.usersServiceClient.getService<UsersGrpcClientService>('UserService');
|
||||
}
|
||||
|
||||
@Post()
|
||||
async create(@Payload() createUserDto: CreateUsersGrpcClientDto) {
|
||||
return this.usersService.create(createUserDto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.usersService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Query() id: string) {
|
||||
return this.usersService.findOne(id);
|
||||
}
|
||||
|
||||
@Put()
|
||||
update(
|
||||
@Payload() updateUserDto: UpdateUsersGrpcClientDto,
|
||||
@Query() id: string,
|
||||
) {
|
||||
return this.usersService.update(id, updateUserDto);
|
||||
}
|
||||
|
||||
@Delete()
|
||||
remove(@Query() id: string) {
|
||||
return this.usersService.remove(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { UsersGrpcClientService } from './users-grpc-client.service';
|
||||
import { UsersGrpcClientController } from './users-grpc-client.controller';
|
||||
|
||||
@Module({
|
||||
controllers: [UsersGrpcClientController],
|
||||
providers: [UsersGrpcClientService],
|
||||
})
|
||||
export class UsersGrpcClientModule {}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { UsersGrpcClientService } from './users-grpc-client.service';
|
||||
|
||||
describe('UsersGrcpClientService', () => {
|
||||
let service: UsersGrpcClientService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [UsersGrpcClientService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<UsersGrpcClientService>(UsersGrpcClientService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,26 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { CreateUsersGrpcClientDto } from './dto/create-users-grpc-client.dto';
|
||||
import { UpdateUsersGrpcClientDto } from './dto/update-users-grpc-client.dto';
|
||||
|
||||
@Injectable()
|
||||
export class UsersGrpcClientService {
|
||||
create(createUsersGrcpClientDto: CreateUsersGrpcClientDto) {
|
||||
return 'This action adds a new usersGrcpClient';
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return `This action returns all usersGrcpClient`;
|
||||
}
|
||||
|
||||
findOne(id: string) {
|
||||
return `This action returns a #${id} usersGrcpClient`;
|
||||
}
|
||||
|
||||
update(id: string, updateUsersGrcpClientDto: UpdateUsersGrpcClientDto) {
|
||||
return `This action updates a #${id} usersGrcpClient`;
|
||||
}
|
||||
|
||||
remove(id: string) {
|
||||
return `This action removes a #${id} usersGrcpClient`;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user