Skip to content

Commit

Permalink
Tarefa prática aserg-ufmg#1 - Microservices
Browse files Browse the repository at this point in the history
  • Loading branch information
filipe-vitorino committed Mar 4, 2021
1 parent 03bb870 commit 340621d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion proto/inventory.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ syntax = "proto3";

service InventoryService {
rpc SearchAllProducts(Empty) returns (ProductsResponse) {}
rpc SearchProductByID(Payload) returns (ProductResponse) {}
}

message Empty{}
Expand All @@ -14,7 +15,9 @@ message ProductResponse {
string photo = 5;
string author = 6;
}

message ProductsResponse {
repeated ProductResponse products = 1;
}
message Payload {
int32 id = 1;
}
6 changes: 6 additions & 0 deletions services/inventory/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ server.addService(inventoryProto.InventoryService.service, {
products: products,
});
},
SearchProductByID: (payload, callback) => {
callback(
null,
products.find((product) => product.id == payload.request.id)
);
},
});

server.bindAsync('127.0.0.1:3002', grpc.ServerCredentials.createInsecure(), () => {
Expand Down

0 comments on commit 340621d

Please sign in to comment.