RailsEventStore / ecommerce

Application with CQRS and Event Sourcing built on Rails and Rails Event Store
MIT License
425 stars 72 forks source link

Better error when submitting order with out of stock product #387

Closed marlena-b closed 2 months ago

marlena-b commented 3 months ago

Issue: https://github.com/RailsEventStore/ecommerce/issues/375

Before when a product was added to an order and subsequently went out of stock before submission, the system incorrectly showed a success message "Your order is being submitted" while leaving the order in draft status. Now it shows "Order can not be submitted! Product not available in requested quantity!".

Zrzut ekranu 2024-08-26 o 10 48 44

I don't like my solution but I didn't know how to do it better. I see a few problems here:

  1. There is no information which product is out stock, and it will be hard to get.
  2. We assume that if order is not submitted then it is becasue of out of stock products. This assumption might not work in the future when e.g., an order is not submitted because it cannot be shipped to a certain location.
  3. It feels weird to fetch a read model to check the result of a command

I didn't know how to do it better because the error InventoryNotAvailable" is rescued in the ReservationProcess event handler and I would have to delete a lot of code to rescue this error in the controller and show this flash, which I think would break the intended original design.

I'm happy to close this PR if it doesn't fit the architecture, no hard feelings 😄

netlify[bot] commented 3 months ago

Deploy Preview for ecommerce-events failed.

Name Link
Latest commit ca1bd168fbc440fd1fe0c7e1d58b75c7499114d9
Latest deploy log https://app.netlify.com/sites/ecommerce-events/deploys/66d4ae20d4754f00091de78b