recommender now returns ids instead of products

This commit is contained in:
Dan Sanche 2018-06-14 16:10:11 -07:00
parent fd6b66faeb
commit 0cf418df99
3 changed files with 75 additions and 82 deletions

View file

@ -47,7 +47,7 @@ message ListRecommendationsRequest {
} }
message ListRecommendationsResponse { message ListRecommendationsResponse {
repeated Product products = 1; repeated string product_ids = 1;
} }
// ---------------Product Catalog---------------- // ---------------Product Catalog----------------

File diff suppressed because one or more lines are too long

View file

@ -4,22 +4,16 @@ import demo_pb2_grpc
from concurrent import futures from concurrent import futures
import time import time
import sys import sys
import random
class RecommendationService(demo_pb2_grpc.RecommendationServiceServicer): class RecommendationService(demo_pb2_grpc.RecommendationServiceServicer):
def ListRecommendations(self, request, context): def ListRecommendations(self, request, context):
print("handling request") print("handling request")
response = demo_pb2.ListRecommendationsResponse() response = demo_pb2.ListRecommendationsResponse()
prod_list = [] prod_list = []
for i in range(3): for i in range(5):
this_price = demo_pb2.MoneyAmount(decimal=i, prod_list.append(str(random.randint(1,100)))
fractional=i) response.product_ids.extend(prod_list)
this_prod = demo_pb2.Product(id=i,
name="test-"+str(i),
description="test product",
picture="test image",
price_usd=this_price)
prod_list.append(this_prod)
response.products.extend(prod_list)
return response return response
if __name__ == "__main__": if __name__ == "__main__":