summaryrefslogtreecommitdiff
path: root/app/controllers/favorites_controller.rb
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2014-10-16 20:35:28 -0600
committermo khan <mo@mokhan.ca>2014-10-16 20:35:28 -0600
commitf2eef36abce2148fe044b6dbda85fadf77754019 (patch)
tree33f25a21fd7487cafbad6578e057d71668bb1797 /app/controllers/favorites_controller.rb
parentf3e8563c45ee3a11211428acda1b8305e077545b (diff)
publish a command to add a favorites to a users collection as a background job.
Diffstat (limited to 'app/controllers/favorites_controller.rb')
-rw-r--r--app/controllers/favorites_controller.rb17
1 files changed, 10 insertions, 7 deletions
diff --git a/app/controllers/favorites_controller.rb b/app/controllers/favorites_controller.rb
index d284a8b2..b3986845 100644
--- a/app/controllers/favorites_controller.rb
+++ b/app/controllers/favorites_controller.rb
@@ -1,20 +1,23 @@
class FavoritesController < ApplicationController
before_action :authenticate!
+ def initialize(command_bus = Spank::IOC.resolve(:command_bus))
+ @bus = command_bus
+ super()
+ end
+
def index
@creation = FindCreationQuery.new.fetch(params[:creation_id])
@favorites = @creation.favorites
end
def create
- AddToFavorites.new(self).run(params[:creation_id])
+ cake = Creation.find(params[:creation_id])
+ bus.publish(:add_cake_to_favorites, { user_id: current_user.id, cake_id: cake.id })
+ redirect_to cake, notice: "This has been added to your favorites"
end
- def favorite_created(cake, message)
- redirect_to cake, notice: message
- end
+ private
- def create_favorite_failed(cake)
- redirect_to cake
- end
+ attr_reader :bus
end