Class: Timelogs::BaseService

Inherits:
Object
  • Object
show all
Includes:
BaseServiceUtility, Gitlab::Utils::StrongMemoize
Defined in:
app/services/timelogs/base_service.rb

Direct Known Subclasses

CreateService, DeleteService

Instance Attribute Summary collapse

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) ⇒ BaseService

Returns a new instance of BaseService.



10
11
12
# File 'app/services/timelogs/base_service.rb', line 10

def initialize(user)
  @current_user = user
end

Instance Attribute Details

#current_userObject

Returns the value of attribute current_user.



8
9
10
# File 'app/services/timelogs/base_service.rb', line 8

def current_user
  @current_user
end

Instance Method Details

#error(message, http_status = nil) ⇒ Object



20
21
22
# File 'app/services/timelogs/base_service.rb', line 20

def error(message, http_status = nil)
  ServiceResponse.error(message: message, http_status: http_status)
end

#error_in_save(timelog) ⇒ Object



24
25
26
27
28
# File 'app/services/timelogs/base_service.rb', line 24

def error_in_save(timelog)
  return error(_("Failed to save timelog"), 404) if timelog.errors.empty?

  error(timelog.errors.full_messages.to_sentence, 404)
end

#success(timelog) ⇒ Object



14
15
16
17
18
# File 'app/services/timelogs/base_service.rb', line 14

def success(timelog)
  ServiceResponse.success(payload: {
    timelog: timelog
  })
end