Class: AwardEmojis::AddService

Inherits:
BaseService show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
app/services/award_emojis/add_service.rb

Instance Attribute Summary

Attributes inherited from BaseService

#awardable, #name

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Methods inherited from BaseService

#initialize

Methods inherited from BaseService

#initialize

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

This class inherits a constructor from AwardEmojis::BaseService

Instance Method Details

#executeObject


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/services/award_emojis/add_service.rb', line 7

def execute
  unless awardable.user_can_award?(current_user)
    return error('User cannot award emoji to awardable', status: :forbidden)
  end

  unless awardable.emoji_awardable?
    return error('Awardable cannot be awarded emoji', status: :unprocessable_entity)
  end

  award = awardable.award_emoji.create(name: name, user: current_user)

  if award.persisted?
    after_create(award)
    success(award: award)
  else
    error(award.errors.full_messages, award: award)
  end
end