Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dorner committed Apr 4, 2024
1 parent 53a0756 commit 73d5737
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
5 changes: 0 additions & 5 deletions lib/grpc_rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ def assign_params(request, param_hash, body_string, params)
sub_record.public_send(:"#{key}=", parameters.delete(key))
end
end

# assign remaining parameters
parameters.each do |k, v|
assign_value(request, k, v)
end
end

def error_msg(error)
Expand Down
8 changes: 3 additions & 5 deletions protoc-gen-rails/internal/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ type FileResult struct {

type controller struct {
ControllerName string
ServiceFilePath string
Methods []method
ServiceName string
FullServiceName string
Expand All @@ -41,7 +40,6 @@ type Route struct {

var controllerTemplate = `
require 'grpc_rest'
require 'services/geo_admin/v1/test_services_pb'
class {{.ControllerName}}Controller < ActionController::Base
protect_from_forgery with: :null_session
Expand All @@ -60,8 +58,9 @@ class {{.ControllerName}}Controller < ActionController::Base
{{$fullServiceName := .FullServiceName -}}
{{range .Methods }}
def {{.Name}}
grpc_request = {{.RequestType}}.new
GrpcRest.assign_params(grpc_request, METHOD_PARAM_MAP["{{.Name}}"], "{{.Body}}", request.parameters)
fields = {{.RequestType}}.descriptor.to_a.map(&:name)
grpc_request = {{.RequestType}}.new(request.parameters.to_h.slice(*fields))
GrpcRest.assign_params(grpc_request, METHOD_PARAM_MAP["{{.Name}}"], "{{.Body}}", request.parameters)
render json: GrpcRest.send_request("{{$fullServiceName}}", "{{.Name}}", grpc_request)
end
{{end}}
Expand All @@ -74,7 +73,6 @@ func ProcessService(service *descriptorpb.ServiceDescriptorProto, pkg string) (F
Methods: []method{},
ServiceName: Classify(service.GetName()),
ControllerName: Demodulize(service.GetName()),
ServiceFilePath: FilePathify(pkg + "." + service.GetName()),
FullServiceName: Classify(pkg + "." + service.GetName()),
}
for _, m := range service.GetMethod() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

require 'grpc_rest'
require 'services/geo_admin/v1/test_services_pb'
class MyServiceController < ActionController::Base
protect_from_forgery with: :null_session

Expand All @@ -23,20 +22,23 @@ class MyServiceController < ActionController::Base
}.freeze

def test
grpc_request = Testdata::TestRequest.new
GrpcRest.assign_params(grpc_request, METHOD_PARAM_MAP["test"], "*", request.parameters)
fields = Testdata::TestRequest.descriptor.to_a.map(&:name)
grpc_request = Testdata::TestRequest.new(request.parameters.to_h.slice(*fields))
GrpcRest.assign_params(grpc_request, METHOD_PARAM_MAP["test"], "*", request.parameters)
render json: GrpcRest.send_request("Testdata::MyService", "test", grpc_request)
end

def test_2
grpc_request = Testdata::TestRequest.new
GrpcRest.assign_params(grpc_request, METHOD_PARAM_MAP["test_2"], "second_record", request.parameters)
fields = Testdata::TestRequest.descriptor.to_a.map(&:name)
grpc_request = Testdata::TestRequest.new(request.parameters.to_h.slice(*fields))
GrpcRest.assign_params(grpc_request, METHOD_PARAM_MAP["test_2"], "second_record", request.parameters)
render json: GrpcRest.send_request("Testdata::MyService", "test_2", grpc_request)
end

def test_3
grpc_request = Testdata::TestRequest.new
GrpcRest.assign_params(grpc_request, METHOD_PARAM_MAP["test_3"], "", request.parameters)
fields = Testdata::TestRequest.descriptor.to_a.map(&:name)
grpc_request = Testdata::TestRequest.new(request.parameters.to_h.slice(*fields))
GrpcRest.assign_params(grpc_request, METHOD_PARAM_MAP["test_3"], "", request.parameters)
render json: GrpcRest.send_request("Testdata::MyService", "test_3", grpc_request)
end

Expand Down

0 comments on commit 73d5737

Please sign in to comment.