public async Task <BasketModel> GetBasket(string user) { _logger.LogInformation($">>> Begin gRPC to call for get basket of user {user}. Base url is {_url}"); var channel = GrpcChannel.ForAddress(_url); var client = new BasketClient(channel); var request = new UserBasketRequest() { User = user }; var model = new BasketModel() { User = user, Beers = Array.Empty <int>() }; try { var response = await client.GetByUserAsync(request); model.User = response.User; model.Beers = response.Beers.ToArray(); } catch (RpcException ex) { _logger.LogError(ex, "!!! Error returned from gRPC service -> Returning empty basket"); } _logger.LogInformation($"<<< Ended gRPC call for get basket of user {user}"); return(model); }
public override async Task <BasketDeletedResponse> DeleteByUser(UserBasketRequest request, ServerCallContext context) { _logger.LogInformation(">>> Begin BasketService.DeleteByUser gRPC method."); var found = await _svc.DeleteFromUser(request.User); var response = new BasketDeletedResponse() { Deleted = found }; _logger.LogInformation("<<< Ended BasketService.DeleteByUser gRPC method."); return(response); }
public override async Task <BasketResponse> GetByUser(UserBasketRequest request, ServerCallContext context) { _logger.LogInformation(">>> Begin BasketService.GetByUser gRPC method."); var user = request.User; var basket = await _svc.GetUserBasketByUser(user); if (basket == null) { throw new Exception($"User {user} do not have any basket"); } var response = new BasketResponse(); response.User = basket.UserName; response.Beers.AddRange(basket.BeerIds); _logger.LogInformation("<<< Ended BasketService.GetByUser gRPC method."); return(response); }