public async Task <Coupon> GetCoupon(Guid couponId)
        {
            var id = Activity.Current.TraceId.ToString();

            try
            {
                GetCouponByIdRequest getCouponByIdRequest = new GetCouponByIdRequest {
                    CouponId = couponId.ToString()
                };

                GetCouponByIdResponse getCouponByIdResponse = await discountsService.GetCouponAsync(getCouponByIdRequest);

                var coupon = new Coupon
                {
                    Code        = getCouponByIdResponse.Coupon.Code,
                    Amount      = getCouponByIdResponse.Coupon.Amount,
                    AlreadyUsed = getCouponByIdResponse.Coupon.AlreadyUsed,
                    CouponId    = Guid.Parse(getCouponByIdResponse.Coupon.CouponId)
                };

                return(coupon);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
        public override async Task <GetCouponByIdResponse> GetCoupon(GetCouponByIdRequest request, ServerCallContext context)
        {
            using var scope = logger.BeginScope("Loading coupon {CouponId}", request.CouponId);

            var response = new GetCouponByIdResponse();
            var coupon   = await couponRepository.GetCouponById(Guid.Parse(request.CouponId));

            if (coupon is null)
            {
                logger.LogInformation("Coupon was not found");
                return(null);
            }

            response.Coupon = new Coupon
            {
                Code        = coupon.Code,
                AlreadyUsed = coupon.AlreadyUsed,
                Amount      = coupon.Amount,
                CouponId    = coupon.CouponId.ToString()
            };

            logger.LogDebug("Returning coupon with discount amount of {DiscountAmount}", coupon.Amount);

            return(response);
        }
Example #3
0
        public override async Task <GetCouponByIdResponse> GetCoupon(GetCouponByIdRequest request, ServerCallContext context)
        {
            var response = new GetCouponByIdResponse();
            var coupon   = await couponRepository.GetCouponById(Guid.Parse(request.CouponId));

            response.Coupon = new Coupon
            {
                Code        = coupon.Code,
                AlreadyUsed = coupon.AlreadyUsed,
                Amount      = coupon.Amount,
                CouponId    = coupon.CouponId.ToString()
            };
            return(response);
        }