Class: Achievements::UpdateService

Inherits:
Object
  • Object
show all
Defined in:
app/services/achievements/update_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current_user, achievement, params) ⇒ UpdateService

Returns a new instance of UpdateService.



7
8
9
10
11
# File 'app/services/achievements/update_service.rb', line 7

def initialize(current_user, achievement, params)
  @current_user = current_user
  @achievement = achievement
  @params = params
end

Instance Attribute Details

#achievementObject (readonly)

Returns the value of attribute achievement.



5
6
7
# File 'app/services/achievements/update_service.rb', line 5

def achievement
  @achievement
end

#current_userObject (readonly)

Returns the value of attribute current_user.



5
6
7
# File 'app/services/achievements/update_service.rb', line 5

def current_user
  @current_user
end

#paramsObject (readonly)

Returns the value of attribute params.



5
6
7
# File 'app/services/achievements/update_service.rb', line 5

def params
  @params
end

Instance Method Details

#executeObject



13
14
15
16
17
18
19
20
21
# File 'app/services/achievements/update_service.rb', line 13

def execute
  return error_no_permissions unless allowed?

  if achievement.update(params)
    ServiceResponse.success(payload: achievement)
  else
    error_updating
  end
end