Class: UserPreferences::UpdateService

Inherits:
BaseService show all
Defined in:
app/services/user_preferences/update_service.rb

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

#initialize(user, params = {}) ⇒ UpdateService

Returns a new instance of UpdateService.


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

def initialize(user, params = {})
  @preferences = user.user_preference
  @params = params.to_h.dup.with_indifferent_access
end

Instance Method Details

#executeObject


10
11
12
13
14
15
16
17
18
# File 'app/services/user_preferences/update_service.rb', line 10

def execute
  if @preferences.update(@params)
    ServiceResponse.success(
      message: 'Preference was updated',
      payload: { preferences: @preferences })
  else
    ServiceResponse.error(message: 'Could not update preference')
  end
end