Extending Groser iOS and Rails apps to support grocery delivery in multiple cities - Part 2
2 minute read
This is Part 2 of multi part series about how I re-architect Rails and iOS apps to support grocery delivery in multiple cities to enable our new business model of selling SaaS solution to independent entrepreneurs wanting to create their own grocery delivery service. To understand rationale behind my decisions please read Part 1
Upgrading Client app search API
I use pg_search with scopes to search products by name. With ProductVariant I will need to narrow down Product search to specific store by ProductVariant. I will add Product.search scope, cause it will be used in multiple places.
product.rb
I’m sure it can be optimized further, but I want to get it done in shortest time possible, so querying Product ids and then selecting ProductVariant will do for now.
searches_controller.rb
Upgrading Shopper app search API
Next I need to upgrade shopper API which can search by Product name or barcode.
Since barcode can be universal as well as store specific (for bulk products), I query both Product.barcode and ProductVariant.barcode
product.rbshoppers/products_controller.rb
Upgrading Order Dispatcher
Order dispatcher assigns incoming orders to available shoppers according to schedule set by shoppers. First, I need to query all active and available shoppers for the client’s city. I’ll delegate Order.city to associated User.
order.rb
Next, I’ll add city query into shopper scopes, extracted into mixin.
has_roles.rb
Now I can begin working on OrderDispatcher. First I’ll handle easy case of admin customer placing an order, and then general case.
order_dispatcher.rb
In Part 3 I will extend iOS app so that customers can change which city they are interested in and app will dynamically load Store with Shelves and Departments.
Thank you for purchasing my iOS control. If you have any questions that are beyond the scope of this help file, please feel free to email via my user page co...
Right now you can shop and order delivery only in Moscow from single chain of supermarkets. My goal in this post, is to allow customers to switch cities, and...