Class: IncidentManagement::TimelineEventTags::CreateService

Inherits:
BaseService
  • Object
show all
Defined in:
app/services/incident_management/timeline_event_tags/create_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseService

#allowed?, #error, #error_in_save, #error_no_permissions, #success

Constructor Details

#initialize(project, user, params) ⇒ CreateService

Returns a new instance of CreateService.



8
9
10
11
12
# File 'app/services/incident_management/timeline_event_tags/create_service.rb', line 8

def initialize(project, user, params)
  @project = project
  @user = user
  @params = params
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



6
7
8
# File 'app/services/incident_management/timeline_event_tags/create_service.rb', line 6

def params
  @params
end

#projectObject (readonly)

Returns the value of attribute project.



6
7
8
# File 'app/services/incident_management/timeline_event_tags/create_service.rb', line 6

def project
  @project
end

#userObject (readonly)

Returns the value of attribute user.



6
7
8
# File 'app/services/incident_management/timeline_event_tags/create_service.rb', line 6

def user
  @user
end

Instance Method Details

#executeObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/services/incident_management/timeline_event_tags/create_service.rb', line 14

def execute
  return error_no_permissions unless allowed?

  timeline_event_tag_params = {
    project: project,
    name: params[:name]
  }

  timeline_event_tag = IncidentManagement::TimelineEventTag.new(timeline_event_tag_params)

  if timeline_event_tag.save
    success(timeline_event_tag)
  else
    error_in_save(timeline_event_tag)
  end
end