Пример #1
0
        public async Task <IActionResult> Checkout([FromBody] BasketCheckout basketCheckout, [FromHeader(Name = "x-requestid")] string requestId)
        {
            var userId = _identitySvc.GetUserIdentity();


            basketCheckout.RequestId = (Guid.TryParse(requestId, out Guid guid) && guid != Guid.Empty) ?
                                       guid : basketCheckout.RequestId;

            var basket = await _repository.GetBasketAsync(userId);

            if (basket == null)
            {
                return(BadRequest());
            }

            var userName = User.FindFirst(x => x.Type == "unique_name").Value;

            //var eventMessage = new UserCheckoutAcceptedIntegrationEvent(userId, userName, basketCheckout.City, basketCheckout.Street,
            //    basketCheckout.State, basketCheckout.Country, basketCheckout.ZipCode, basketCheckout.CardNumber, basketCheckout.CardHolderName,
            //    basketCheckout.CardExpiration, basketCheckout.CardSecurityNumber, basketCheckout.CardTypeId, basketCheckout.Buyer, basketCheckout.RequestId, basket);

            // Once basket is checkout, sends an integration event to
            // ordering.api to convert basket to order and proceeds with
            // order creation process
            //_eventBus.Publish(eventMessage);

            return(Accepted());
        }
Пример #2
0
        public async Task <IActionResult> Checkout([FromBody] BasketCheckout basketCheckout)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var basket = await _basketRepository.GetBasket(basketCheckout.UserName);

                    if (basket == null)
                    {
                        _logger.LogInformation($"Basket with username: {basketCheckout.UserName}, not found");
                        return(NotFound($"Basket with username: {basketCheckout.UserName}, not found"));
                    }

                    var eventMessage = _mapper.Map <BasketCheckoutEvent>(basketCheckout);
                    eventMessage.EmailAddress = "*****@*****.**";
                    eventMessage.TotalPrice   = basket.TotalPrice;

                    await _publishEndpoint.Publish(eventMessage);

                    await _basketRepository.DeleteBasket(basketCheckout.UserName);

                    return(Accepted());
                }
                catch (Exception ex)
                {
                    _logger.LogError($"Error getting basket", ex);
                    throw new Exception($"Error getting basket", ex);
                }
            }

            return(BadRequest());
        }
Пример #3
0
        public async Task <IActionResult> Checkout([FromBody] BasketCheckout basketCheckout)
        {
            try
            {
                //get the existing basket with total price
                var basket = await _basketRepository.GetBasket(basketCheckout.UserName);

                if (basket == null)
                {
                    return(BadRequest());
                }

                //Create basket checkout event
                var basketCheckoutEvent = _mapper.Map <BasketCheckoutEvent>(basketCheckout);

                //Set the total price on checkout event
                basketCheckoutEvent.TotalPrice = basket.TotalPrice;
                // Send the event to the Rabbit MQ
                await _publishEndpoint.Publish <BasketCheckoutEvent>(basketCheckoutEvent);

                // remove the basket from redis cache
                await _basketRepository.DeleteBasket(basketCheckout.UserName);

                return(Accepted());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(StatusCode(StatusCodes.Status500InternalServerError, "Error updating data in the database"));
            }
        }
        public async Task <ActionResult> Checkout([FromBody] BasketCheckout basketCheckout)
        {
            var basket = _basketRepository.GetBasketCart(basketCheckout.UserName);

            if (basket == null)
            {
                return(BadRequest());
            }

            var eventBasketCheckout = _mapper.Map <BasketCheckoutEvent>(basketCheckout);

            eventBasketCheckout.RequestId  = Guid.NewGuid();
            eventBasketCheckout.TotalPrice = basketCheckout.TotalPrice;

            try
            {
                _eventBus.PublishBaskCheckout(EventBusConstants.BasketCheckoutQueueName, eventBasketCheckout);
            }
            catch (Exception ex)
            {
                throw;
            }

            return(Accepted());
        }
Пример #5
0
        public async Task <ActionResult> CheckoutAsync([FromBody] BasketCheckout basketCheckout)
        {
            //Publish UserCheckoutIntegrationEvent and dispatch it throught eventbus

            //var userIdentity = User.FindFirstValue(ClaimTypes.NameIdentifier); // will give the user's userId
            //basketCheckout.UserId is the key generated on client side and is the key to customer basket
            // basketCheckout.UserIdentity is the identity ID
            CustomerBasket basket = await repository.GetBasketAsync(basketCheckout.UserId);

            if (basket == null)
            {
                return(BadRequest());
            }
            var message = new UserCheckoutIntegrationEvent(basketCheckout.UserIdentity,
                                                           basketCheckout.UserId,
                                                           basketCheckout.UserName,
                                                           basketCheckout.Street, basketCheckout.Country,
                                                           basketCheckout.City, basketCheckout.State, basketCheckout.ZipCode,
                                                           basket);

            message.Id = new Guid();
            eventBus.Publish(message);

            //Here I am assuming everything goes fine and the order will be created inside Ordering service, so I empty the basket
            //But it might not be true, so probably I should handle the real scenario later.
            //await repository.DeleteBasketAsync(basketCheckout.UserId);

            //Response.Headers.Add("lookupUrl", "LatestOrder/BuyerId/{buyerId}");
            return(Accepted());
        }
Пример #6
0
        public async Task <IActionResult> Checkout([FromBody] BasketCheckout basketCheckout)
        {
            // get existing basket with total price
            // Set TotalPrice on basketCheckout eventMessage
            // send checkout event to rabbitmq
            // remove the basket

            // get existing basket with total price
            var basket = await _repository.GetBasket(basketCheckout.UserName);

            if (basket == null)
            {
                return(BadRequest());
            }

            // send checkout event to rabbitmq
            var eventMessage = _mapper.Map <BasketCheckoutEvent>(basketCheckout);

            eventMessage.TotalPrice = basket.TotalPrice;
            await _publishEndpoint.Publish <BasketCheckoutEvent>(eventMessage);

            // remove the basket
            await _repository.DeleteBasket(basket.UserName);

            return(Accepted());
        }
Пример #7
0
        public async Task <IActionResult> CheckoutBasket([FromBody] BasketCheckout basketCheckout)
        {
            try
            {
                var basket = await _basketRepository.GetBasket(basketCheckout.UserName);

                if (basket == null)
                {
                    return(BadRequest());
                }

                var isDeleted = await _basketRepository.DeleteBasket(basketCheckout.UserName);

                if (!isDeleted)
                {
                    return(BadRequest());
                }

                var eventMessage = _mapper.Map <BasketCheckoutEvent>(basketCheckout);
                eventMessage.RequestId  = Guid.NewGuid();
                eventMessage.TotalPrice = basket.TotalPrice;

                _eventBus.PublishBasketCheckout(EventBusConstants.BasketCheckoutQueue, eventMessage);

                return(Accepted());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message, ex);
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
        }
        public async Task <ActionResult <BasketCart> > Checkout([FromBody] BasketCheckout basketCheckout)
        {
            var basket = await _repository.GetBasketAsync(basketCheckout.UserName);

            if (basket == null)
            {
                return(NotFound());
            }

            var basketRemoved = await _repository.DeleteBasketAsync(basketCheckout.UserName);

            if (!basketRemoved)
            {
                return(NotFound());
            }

            var eventMessage = _mapper.Map <BasketCheckoutEvent>(basketCheckout);

            try
            {
                _eventBus.PublishBasketCheckout(EventBusConstants.BasketCheckoutQueue, eventMessage);
            }
            catch (Exception e)
            {
                throw;
            }
            return(Accepted());
        }
Пример #9
0
        public async Task <IActionResult> Checkout([FromBody] BasketCheckout basketCheckout)
        {
            BasketCart basketCart = await _repository.GetBasket(basketCheckout.UserName);

            if (basketCart == null)
            {
                return(BadRequest());
            }

            bool deleteWasSuccessful = await _repository.DeleteBasket(basketCart.UserName);

            if (deleteWasSuccessful == false)
            {
                return(BadRequest());
            }

            BasketCheckoutEvent basketCheckoutEvent = _mapper.Map <BasketCheckoutEvent>(basketCheckout);

            basketCheckoutEvent.RequestId  = Guid.NewGuid();
            basketCheckoutEvent.TotalPrice = basketCart.TotalPrice;

            try
            {
                _eventBusProducer.PublishBasketCheckout(EventBusConstants.BasketCheckoutQueue, basketCheckoutEvent);
            }
            catch (Exception)
            {
                throw;
            }

            return(Accepted());
        }
Пример #10
0
        public async Task <ActionResult <BasketCart> > Checkout([FromBody] BasketCheckout basketCheckout)
        {
            //get total price of basket
            //remove basket
            //send checkout event to rabbit mq

            var basket = await _repository.GetBasket(basketCheckout.UserName);

            if (basket == null)
            {
                return(BadRequest());
            }

            var basketRemoved = await _repository.DeleteBasket(basketCheckout.UserName);

            if (!basketRemoved)
            {
                return(BadRequest());
            }
            var eventMessage = _mapper.Map <BasketCheckoutEvent>(basketCheckout);

            eventMessage.RequestId  = Guid.NewGuid();
            eventMessage.TotalPrice = basket.Totalprice;
            try
            {
                _eventBus.PubliishBasketCheckout(EventBusConstants.BasketCheckoutQueue, eventMessage);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(Accepted());
        }
        public async Task <IActionResult> Checkout([FromBody] BasketCheckout basketCheckout)
        {
            var basket = await _repository.GetBasketAsync(basketCheckout.UserName);

            if (basket == null)
            {
                return(BadRequest());
            }

            var basketToRemove = await _repository.DeleteBasketAsync(basket.UserName);

            if (!basketToRemove)
            {
                return(BadRequest());
            }

            var eventMessage = _mapper.Map <BasketCheckoutEvent>(basketCheckout);

            eventMessage.RequestId  = Guid.NewGuid();
            eventMessage.TotalPrice = basket.TotalPrice;

            try
            {
                _eventBus.PublishBasketCheckout(EventBusConstants.BasketCheckoutQueue, eventMessage);
            }
            catch (Exception)
            {
                throw;
            }

            return(Accepted());
        }
        public async Task <IActionResult> Checkout([FromBody] BasketCheckout checkout)
        {
            var basket = await _repos.GetCart(checkout.Username);

            if (basket == null)
            {
                _logger.LogError("Basket is not found for username: "******"Basket can't be removed for username: "******"Message can't be published for user " + checkout.Username + ": " + e.Message);
                throw;
            }
            return(Accepted());
        }
        public async Task <ActionResult> Checkout([FromBody] BasketCheckout checkout)
        {
            var findBasket = await _repository.GetBasketCart(checkout.UserName);

            if (findBasket == null)
            {
                return(BadRequest());
            }

            var removeBasket = await _repository.DeleteBasket(checkout.UserName);

            if (!removeBasket)
            {
                return(BadRequest());
            }

            var eventMessage = _mapper.Map <BasketCheckoutEvent>(checkout);

            eventMessage.RequestId  = Guid.NewGuid();
            eventMessage.TotalPrice = findBasket.TotalPrice;

            try
            {
                _rabbitMQProducer.PublishBasketCheckout(EventBusConstants.BasketCheckoutQueue, eventMessage);
            }
            catch (Exception ex)
            {
                throw;
            }
            return(Accepted());
        }
Пример #14
0
        public async Task <IActionResult> Update(Guid id, BasketCheckout checkout)
        {
            if (id != checkout.BuyerId)
            {
                return(BadRequest());
            }

            try
            {
                var payload = await _context.BasketCheckouts
                              .FirstOrDefaultAsync(x => x.BuyerId == id);

                if (payload == null)
                {
                    return(NotFound("Item not found."));
                }

                _context.BasketCheckouts.Update(checkout);
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            return(NoContent());
        }
Пример #15
0
        public async Task <IActionResult> Checkout([FromBody] BasketCheckout basketCheckout)
        {
            // get total price
            var basket = await _basketRepository.GetBasket(basketCheckout.UserName);

            if (basket == null)
            {
                return(BadRequest());
            }
            // remove basket
            var basketRemoved = await _basketRepository.DeleteBasket(basketCheckout.UserName);

            if (!basketRemoved)
            {
                return(BadRequest());
            }
            // send message to RabbitMQ
            var eventMessage = _mapper.Map <BasketCheckoutEvent>(basketCheckout);

            eventMessage.RequestId  = Guid.NewGuid();
            eventMessage.TotalPrice = basket.TotalPrice;

            try
            {
                _producer.PublishBasketCheckout(EventBusConstants.BasketCheckoutQueue, eventMessage);
            }
            catch (Exception)
            {
                throw;
            }
            return(Accepted());
        }
Пример #16
0
        public async Task <ActionResult> Checkout([FromBody] BasketCheckout basketCheckout)
        {
            var basket = await _repo.GetBasket(basketCheckout.UserName);

            if (basket == null)
            {
                return(BadRequest());
            }
            var basketRemoved = await _repo.DeleteBasket(basket.UserName);

            if (!basketRemoved)
            {
                return(BadRequest());
            }
            var eventMessage = _mapper.Map <BasketCheckoutEvent>(basketCheckout);

            eventMessage.RequestId  = Guid.NewGuid();
            eventMessage.TotalPrice = basket.TotalPrice;

            try
            {
                _eventBus.PublishBasketCheckout(EventBusConstants.BasketCheckoutQueue, eventMessage);
            }
            catch (Exception)
            {
                _logger.LogError($"eventMessage couldnt send");
                throw;
            }
            return(Accepted());
        }
        public async Task <ActionResult> CheckoutBasket([FromBody] BasketCheckout basketCheckout)
        {
            var basket = await _basketRepository.GetBasket(basketCheckout.UserName);

            if (basket == null)
            {
                return(BadRequest());
            }

            var basketRemoved = await _basketRepository.DeleteBasket(basketCheckout.UserName);

            if (!basketRemoved)
            {
                return(BadRequest());
            }

            var eventMessage = _mapper.Map <BasketCheckoutEvent>(basketCheckout);

            eventMessage.RequestId  = Guid.NewGuid();
            eventMessage.TotalPrice = basket.TotalPrice;

            try
            {
                _eventBusRabbitMqProducer.PublishBasketCheckout(EventBusConstants.BasketCheckoutQueue, eventMessage);
            }
            catch (Exception e)
            {
                Console.WriteLine($"error sending eventbus message message: {e.Message}");
                throw;
            }

            return(Accepted());
        }
        public async Task <IActionResult> Checkout([FromBody] BasketCheckout basketCheckout)
        {
            var basket = await _repository.Get(basketCheckout.UserName);

            if (basket is null)
            {
                return(BadRequest("The basket was not found"));
            }

            var basketRemoved = await _repository.Delete(basket.UserName);

            if (!basketRemoved)
            {
                return(BadRequest("It was not possible to checkot the basket"));
            }

            try
            {
                var eventMessage = _mapper.Map <BasketCheckoutEvent>(basketCheckout);
                eventMessage.RequestId  = Guid.NewGuid();
                eventMessage.TotalPrice = basket.TotalPrice;

                _basketCheckoutPublisher.Publish(eventMessage);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                await _repository.Update(basket);
            }

            return(Accepted(basketCheckout));
        }
Пример #19
0
        public async Task <IActionResult> Checkout([FromBody] BasketCheckout basketCheckout)
        {
            var basket = await _repository.GetBasket(basketCheckout.Username);

            if (basket == null)
            {
                _logger.LogError("Basket could not be found for user: "******"Basket could not be removed for user: "******"Error: Message cannot be published for user: "******", " + e.Message);
                throw;
            }

            return(Accepted());
        }
Пример #20
0
        public async Task <ActionResult> CheckoutAsync(
            [FromBody] BasketCheckout basketCheckout)
        {
            var basket = await _basketRespository.GetBasketAsync(basketCheckout.Buyer);

            if (basket == null)
            {
                return(BadRequest());
            }

            var eventMessage = new UserCheckoutAcceptedIntegrationEvent(
                basketCheckout.Buyer, "", basketCheckout.City, basketCheckout.Street,
                basketCheckout.State, basketCheckout.Country, basketCheckout.ZipCode,
                basketCheckout.CardNumber, basketCheckout.CardHolderName,
                basketCheckout.CardExpiration, basketCheckout.CardSecurityNumber,
                basketCheckout.CardTypeId, basketCheckout.Buyer, basketCheckout.RequestId, basket);

            // Once basket is checkout, sends an integration event to
            // ordering.api to convert basket to order and proceeds with
            // order creation process
            try
            {
                _eventBus.Publish(eventMessage);
            }
            catch (Exception ex)
            {
                Log.Error(ex, "ERROR Publishing integration event: {IntegrationEventId} from {AppName}",
                          eventMessage.Id, Program.AppName);

                throw;
            }

            return(Accepted());
        }
Пример #21
0
        public async Task <IActionResult> Checkout([FromBody] BasketCheckout basketCheckout)
        {
            var basket = await _repository.GetBasket(basketCheckout.Username);

            if (basket == null)
            {
            }
            return(await Accepted());
        }
Пример #22
0
        public async Task <IActionResult> Checkout(BasketCheckout checkout)
        {
            BasketCart basket = await _basketRepository.GetBasket(checkout.userName);

            if (basket == null)
            {
                return(BadRequest());
            }


            var basketRemoved = await _basketRepository.DeleteBasket(basket.UserName);

            if (!basketRemoved)
            {
                return(BadRequest());
            }

            //var eventMessage = _mapper.Map <BasketCheckoutEvent>(basket);
            var eventMessage = new BasketCheckoutEvent {
                AddressLine   = checkout.AddressLine,
                CardName      = checkout.CardName,
                CardNumber    = checkout.CardNumber,
                Country       = checkout.Country,
                CVV           = checkout.CVV,
                EmailAddress  = checkout.EmailAddress,
                Expiration    = checkout.Expiration,
                FirstName     = checkout.FirstName,
                LastName      = checkout.LastName,
                PaymentMethod = checkout.PaymentMethod,
                State         = checkout.State,
                TotalPrice    = checkout.TotalPrice,
                userName      = checkout.userName,
                ZipCode       = checkout.ZipCode
            };


            eventMessage.RequestId  = Guid.NewGuid();
            eventMessage.TotalPrice = basket.TotalPrice;

            try
            {
                _eventBus.PublishBasketCheckout(EventBusConstants.BasketCheckoutQueue, eventMessage);
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }

            return(Accepted(basket));
        }
Пример #23
0
        public async Task <IActionResult> Create(BasketCheckout checkout)
        {
            try
            {
                await _context.BasketCheckouts.AddAsync(checkout);

                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            return(Ok(checkout.BuyerId));
        }
Пример #24
0
        public async Task <IActionResult> Checkout([FromBody] BasketCheckout basketCheckout)
        {
            var basket = await _repo.GetBasket(basketCheckout.UserName);

            if (basket == null)
            {
                return(BadRequest());
            }

            var eventMessage = _mapper.Map <BasketCheckoutEvent>(basketCheckout);

            await _publishEndpoint.Publish(eventMessage);

            await _repo.DeleteBasket(basketCheckout.UserName);

            return(Accepted());
        }
Пример #25
0
        public async Task <IActionResult> Checkout([FromBody] BasketCheckout basketCheckout)
        {
            var basket = await _repository.GetBasket(basketCheckout.Username);

            if (basket == null)
            {
                return(BadRequest());
            }

            var eventMessage = _mapper.Map <BasketCheckoutEvent>(basketCheckout);

            eventMessage.TotalPrice = basket.TotalPrice;
            await _eventBus.Publish(eventMessage);

            await _repository.DeleteBasket(basketCheckout.Username);

            return(Accepted());
        }
        public async Task <ActionResult> CheckoutAsync([FromBody] BasketCheckout basketCheckout)
        {
            // remove the basket
            // send checkout event to rabbitMq

            var userId = "swn"; // _identityService.GetUserIdentity();

            var basketRemoved = await _repository.DeleteBasketAsync(userId);

            if (!basketRemoved)
            {
                return(BadRequest());
            }

            basketCheckout.RequestId = Guid.NewGuid();
            basketCheckout.Buyer     = userId;
            basketCheckout.City      = "asd";
            basketCheckout.Country   = "asd";

            _eventBus.PublishBasketCheckout("basketCheckoutQueue", basketCheckout);

            // TODO : burayı alttaki gibi yapılacak -- rabbitMQ kısmı ayrı bir class library yapılıp BasketCheckoutAcceptedIntegrationEvent class ı yapılıp 2 tarafta onu kullanacak

            //var userName = this.HttpContext.User.FindFirst(x => x.Type == ClaimTypes.Name).Value;

            //var eventMessage = new UserCheckoutAcceptedIntegrationEvent(userId, userName, basketCheckout.City, basketCheckout.Street,
            //    basketCheckout.State, basketCheckout.Country, basketCheckout.ZipCode, basketCheckout.CardNumber, basketCheckout.CardHolderName,
            //    basketCheckout.CardExpiration, basketCheckout.CardSecurityNumber, basketCheckout.CardTypeId, basketCheckout.Buyer, basketCheckout.RequestId, basket);

            //// Once basket is checkout, sends an integration event to
            //// ordering.api to convert basket to order and proceeds with
            //// order creation process
            //try
            //{
            //    _eventBus.Publish(eventMessage);
            //}
            //catch (Exception ex)
            //{
            //    _logger.LogError(ex, "ERROR Publishing integration event: {IntegrationEventId} from {AppName}", eventMessage.Id, "asd");
            //    throw;
            //}

            return(Accepted());
        }
Пример #27
0
        public async Task <ActionResult> Checkout([FromBody] BasketCheckout basketCheckout)
        {
            // get total price of the basket
            // remove the basket
            // send checkout event to rabbitMq

            var basket = await _repository.GetBasket(basketCheckout.UserName);

            if (basket == null)
            {
                _logger.LogError("Basket not exist with this user : {EventId}", basketCheckout.UserName);
                return(BadRequest());
            }

            var basketRemoved = await _repository.DeleteBasket(basketCheckout.UserName);

            if (!basketRemoved)
            {
                _logger.LogError("Basket can not deleted");
                return(BadRequest());
            }

            // Once basket is checkout, sends an integration event to
            // ordering.api to convert basket to order and proceeds with
            // order creation process

            var eventMessage = _mapper.Map <BasketCheckoutEvent>(basketCheckout);

            eventMessage.RequestId  = Guid.NewGuid();
            eventMessage.TotalPrice = basket.TotalPrice;

            try
            {
                _eventBus.PublishBasketCheckout(EventBusConstants.BasketCheckoutQueue, eventMessage);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "ERROR Publishing integration event: {EventId} from {AppName}", eventMessage.RequestId, "Basket");
                throw;
            }

            return(Accepted());
        }
Пример #28
0
        public async Task <ActionResult> CheckoutAsync([FromBody] BasketCheckout basketCheckout, [FromHeader(Name = "x-requestid")] string requestId)
        {
            // var userId = _identityService.GetUserIdentity();
            var userId = "5d87b0b19281994590e08551";

            basketCheckout.RequestId = (Guid.TryParse(requestId, out Guid guid) && guid != Guid.Empty) ?
                                       guid : basketCheckout.RequestId;

            var basket = await _repository.GetBasketAsync(userId);

            if (basket == null)
            {
                return(BadRequest());
            }

            var userName = User.FindFirst(x => x.Type == "unique_name").Value;

            return(Accepted());
        }
Пример #29
0
        public async Task <ActionResult> Checkout([FromBody] BasketCheckout basketCheckout)
        {
            // get total price of basket
            // remove basket, because the queue properties include NONautodelete
            // send checkout event to rabbitmq

            var basket = await _repository.GetBasket(basketCheckout.UserName);

            if (basket == null)
            {
                _logger.LogError($"Basket does not exist with the user: {basketCheckout.UserName}");
                return(BadRequest());
            }

            // Remove the json string from redis
            bool basketRemoved = await _repository.DeleteBasket(basketCheckout.UserName);

            if (!basketRemoved)
            {
                _logger.LogError($"Basket cannot be deleted!");
                return(BadRequest());
            }

            // Once basket is checked out, send an integration event to
            // ordering.api to convert basket to order and proceeds with
            // order creation process
            var eventMessage = _mapper.Map <BasketCheckoutEvent>(basketCheckout);

            eventMessage.RequestId  = Guid.NewGuid();
            eventMessage.TotalPrice = basket.TotalPrice;

            try
            {
                _eventBus.PublishBasketCheckout(EventBusConstants.BasketCheckoutQueue, eventMessage);
                return(Accepted());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "ERROR Publishing integration event: {EventId} from {AppName}", eventMessage.RequestId, "Basket.API");
                throw;
            }
        }
Пример #30
0
        public async Task <ActionResult <BasketCheckout> > Checkout(BasketCheckout b)
        {
            var en = await _repository.GetBasketAsync(b.UserName);

            if (en is null)
            {
                return(NotFound("There is no such basket for this user."));
            }
            var isDeleted = await _repository.DeleteAsync(b.UserName);

            if (!isDeleted)
            {
                return(BadRequest("Deletion is unsuccessful."));
            }
            var p = _mapper.Map <BasketCheckoutEvent>(b);

            p.RequestId  = Guid.NewGuid();
            p.TotalPrice = b.TotalPrice;
            _eventBus.PublishBasketCheckout(EventBusEnum.BASKET_CHECKOUT_QUEUE, p);
            return(Accepted());
        }