diff options
| author | mo khan <mo@mokhan.ca> | 2014-10-16 20:54:04 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2014-10-16 20:54:04 -0600 |
| commit | c04042f8bffa790d2ee7850bb2d4358c14afecf2 (patch) | |
| tree | ca5a344e613bc0c990210b252f37444735cb4cb9 /app/controllers/my | |
| parent | 4eb7dd4fb2ed71006aee665ae7f666ee88d44c22 (diff) | |
remove extra service object and fix broken spec.
Diffstat (limited to 'app/controllers/my')
| -rw-r--r-- | app/controllers/my/avatars_controller.rb | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/app/controllers/my/avatars_controller.rb b/app/controllers/my/avatars_controller.rb index 76e387b2..01bccd36 100644 --- a/app/controllers/my/avatars_controller.rb +++ b/app/controllers/my/avatars_controller.rb @@ -1,12 +1,43 @@ module My class AvatarsController < BaseController + def initialize(bus = Spank::IOC.resolve(:command_bus)) + @bus = bus + end + def new @avatar = current_user.avatar || Photo.new end def create - UploadAvatar.new.run(current_user, params[:photo][:image]) + publish(params[:photo][:image]) redirect_to new_my_avatar_path, notice: t(:avatar_uploaded) end + + private + + def publish(image) + @bus.publish(:upload_avatar, create_message_from(image)) + end + + def create_message_from(image) + { + user_id: current_user.id, + file_path: move_to_temporary_storage(image), + original_filename: image.original_filename, + content_type: image.content_type, + } + end + + def move_to_temporary_storage(image) + "#{create_tmp_dir}/#{image.original_filename}".tap do |new_path| + FileUtils.mv(image.path, new_path) + end + end + + def create_tmp_dir + Rails.root.join("tmp/uploads/#{SecureRandom.uuid}").tap do |directory| + system "mkdir -p #{directory}" + end + end end end |
