Class: Services::ServicesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/services/services_controller.rb

Constant Summary

Constants inherited from ApplicationController

ApplicationController::MAX_LIST_LENGTH

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#serviceObject (readonly)

Returns the value of attribute service.



4
5
6
# File 'app/controllers/services/services_controller.rb', line 4

def service
  @service
end

Instance Method Details

#createObject



17
18
19
20
21
22
23
24
# File 'app/controllers/services/services_controller.rb', line 17

def create
  svc = CreateServiceContext.call(safe_params)
  if svc.errors.empty?
    render json: { id: svc.id }
  else
    render json: { validation_error: svc.errors.full_messages }, status: 403
  end
end

#indexObject



10
11
12
# File 'app/controllers/services/services_controller.rb', line 10

def index
  @services = Service.limit(MAX_LIST_LENGTH)
end

#invokeObject



35
36
37
38
39
40
41
# File 'app/controllers/services/services_controller.rb', line 35

def invoke
  InvokeServiceContext.call(service)

  render json: { message: "Service '#{service.name}' invoked in the background" }
rescue Exception => ex
  render json: { error: "Error invoking Service '#{service.name}': #{ex.message}" }
end

#showObject



14
15
# File 'app/controllers/services/services_controller.rb', line 14

def show
end

#updateObject



26
27
28
29
30
31
32
33
# File 'app/controllers/services/services_controller.rb', line 26

def update
  UpdateServiceContext.call(service, safe_params)
  if service.errors.empty?
    render json: { id: service.id }
  else
    render json: { validation_error: service.errors.full_messages }, status: 403
  end
end