Class: Panda::Core::AttachAvatarService

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

Instance Method Summary collapse

Methods inherited from Services::BaseService

call

Constructor Details

#initialize(user:, avatar_url:) ⇒ AttachAvatarService

Returns a new instance of AttachAvatarService.



8
9
10
11
# File 'app/services/panda/core/attach_avatar_service.rb', line 8

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

Instance Method Details

#callObject



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/services/panda/core/attach_avatar_service.rb', line 13

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