コード例 #1
0
        public async Task <IActionResult> GetByUser(string user)
        {
            var basket = await _svc.GetUserBasketByUser(user);

            if (basket == null)
            {
                return(NotFound(new { Message = $"User {user} do not have any basket" }));
            }

            return(Ok(new BasketModel()
            {
                User = basket.UserName,
                Beers = basket.BeerIds.ToArray()
            }));
        }
コード例 #2
0
        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);
        }