Skip to content

Commit

Permalink
Merge pull request #1077 from mesg-foundation/feature/service-list
Browse files Browse the repository at this point in the history
 Implement List for Service
  • Loading branch information
antho1404 authored Jun 24, 2019
2 parents e3933eb + 8e73c14 commit 24bd85b
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 27 deletions.
158 changes: 133 additions & 25 deletions protobuf/api/service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions protobuf/api/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ service ServiceX {

// Get returns a single Service specified in a request.
rpc Get(GetServiceRequest) returns (definition.Service) {}

// List returns services specified in a request.
rpc List(ListServiceRequest) returns (ListServiceResponse) {}
}

message CreateServiceRequest {
Expand All @@ -34,3 +37,9 @@ message DeleteServiceResponse {
message GetServiceRequest {
string hash = 1;
}

message ListServiceRequest {}

message ListServiceResponse {
repeated definition.Service services = 1;
}
5 changes: 5 additions & 0 deletions sdk/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,8 @@ func (s *Service) Delete(hash hash.Hash) error {
func (s *Service) Get(hash hash.Hash) (*service.Service, error) {
return s.db.Get(hash)
}

// List returns all services.
func (s *Service) List() ([]*service.Service, error) {
return s.db.All()
}
19 changes: 17 additions & 2 deletions server/grpc/api/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,24 @@ func (s *ServiceServer) Get(ctx context.Context, req *protobuf_api.GetServiceReq
return nil, err
}

exec, err := s.sdk.Service.Get(hash)
service, err := s.sdk.Service.Get(hash)
if err != nil {
return nil, err
}
return ToProtoService(exec), nil
return ToProtoService(service), nil
}

// List returns all services.
func (s *ServiceServer) List(ctx context.Context, req *protobuf_api.ListServiceRequest) (*protobuf_api.ListServiceResponse, error) {
services, err := s.sdk.Service.List()
if err != nil {
return nil, err
}

resp := &protobuf_api.ListServiceResponse{}
for _, service := range services {
resp.Services = append(resp.Services, ToProtoService(service))
}

return resp, nil
}

0 comments on commit 24bd85b

Please sign in to comment.