Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Inventory Feature

to make the inventory feature work, you need to run the Sidekiq server

bundle exec sidekiq

for any restaurant ID that you want to test, run this command

RESTAURANT_ID=816 bundle exec rake generate_restaurant_inventory

816 is the restaurant ID you can read the source code to see what’s behind


Our app previously is a Restaurant booking app, so to check the inventory, we just need to check the date, start time, end time, adult, and kids. After a few years, we have Package product, where a restaurant could have many packages, so we updated the code to check the date, start time, end time, adult, kids, and a package ID that’s why in the InvChecker class, there is a package slug parameter.

* * * In the first release, we only have 2 package types, which are All You Can Eat and Party Pack Package. A restaurant has many packages and a Package has many restaurants too. a package is reusable, usually, it’s used by another restaurant in the same group, for example: “Buy 5 get 2 items” package is used by Audrey restaurant that has a few branches, in Asok, Nana, etc. Due to this requirement, there are 4 models: 1. Restaurant 2. HhPackage::Package::Ayce 3. HhPackage::Package::PartyPack 4. RestaurantPackage The relation between a restaurant to a specific package is connected by the RestaurantPackage model. and the slug data is in the RestaurantPackage model. * * * Study case: find available seat of a restaurant
restaurant = Restaurant.find 816
inv_checker = InvChecker.new restaurant.id, restaurant.time_zone
inv_checker.seat_left Date.today, '19:00'

if has a package data

restaurant = Restaurant.find 816
package = restaurant.restaurant_packages.last
inv_checker = InvChecker.new restaurant.id, restaurant.time_zone
inv_checker.seat_left Date.today, '19:00', package.slug