frontend: integrate recommmendationservice
Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
parent
9889e4904d
commit
400d51a9fe
7 changed files with 99 additions and 17 deletions
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"google.golang.org/grpc/codes"
|
||||
|
||||
|
@ -74,3 +75,23 @@ func (fe *frontendServer) convertCurrency(ctx context.Context, money *pb.Money,
|
|||
From: money,
|
||||
ToCode: currency})
|
||||
}
|
||||
|
||||
func (fe *frontendServer) getRecommendations(ctx context.Context, userID string, productIDs []string) ([]*pb.Product, error) {
|
||||
resp, err := pb.NewRecommendationServiceClient(fe.recommendationSvcConn).ListRecommendations(ctx,
|
||||
&pb.ListRecommendationsRequest{UserId: userID, ProductIds: productIDs})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out := make([]*pb.Product, len(resp.GetProductIds()))
|
||||
for i, v := range resp.GetProductIds() {
|
||||
p, err := fe.getProduct(ctx, v)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get recommended product info (#%s): %+v", v, err)
|
||||
}
|
||||
out[i] = p
|
||||
}
|
||||
if len(out) > 4 {
|
||||
out = out[:4] // take only first four to fit the UI
|
||||
}
|
||||
return out, err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue