Class: Panda::Core::AttachAvatarService

Inherits:
Services::BaseService show all
Defined in:
app/services/panda/core/attach_avatar_service.rb

Constant Summary collapse

MAX_FILE_SIZE =
5.megabytes
MAX_DIMENSION =

Max width/height for optimization

800

Instance Method Summary collapse

Methods inherited from Services::BaseService

call

Constructor Details

#initialize(user:, avatar_url:) ⇒ AttachAvatarService



11
12
13
14
# File 'app/services/panda/core/attach_avatar_service.rb', line 11

def initialize(user:, avatar_url:)
  @user = user
  @avatar_url = avatar_url
end

Instance Method Details

#callObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/services/panda/core/attach_avatar_service.rb', line 16

def call
  return success if @avatar_url.blank?
  return success if @avatar_url == @user.oauth_avatar_url && @user.avatar.attached?

  begin
    download_and_attach_avatar
    @user.update_column(:oauth_avatar_url, @avatar_url)
    success(avatar_attached: true)
  rescue => e
    Rails.logger.error("Failed to attach avatar for user #{@user.id}: #{e.message}")
    failure(["Failed to attach avatar: #{e.message}"])
  end
end