Class: BulkImports::CreateService

Inherits:
Object
  • Object
show all
Defined in:
app/services/bulk_imports/create_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current_user, params, credentials) ⇒ CreateService

Returns a new instance of CreateService.


32
33
34
35
36
# File 'app/services/bulk_imports/create_service.rb', line 32

def initialize(current_user, params, credentials)
  @current_user = current_user
  @params = params
  @credentials = credentials
end

Instance Attribute Details

#credentialsObject (readonly)

Returns the value of attribute credentials.


30
31
32
# File 'app/services/bulk_imports/create_service.rb', line 30

def credentials
  @credentials
end

#current_userObject (readonly)

Returns the value of attribute current_user.


30
31
32
# File 'app/services/bulk_imports/create_service.rb', line 30

def current_user
  @current_user
end

#paramsObject (readonly)

Returns the value of attribute params.


30
31
32
# File 'app/services/bulk_imports/create_service.rb', line 30

def params
  @params
end

Instance Method Details

#executeObject


38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/services/bulk_imports/create_service.rb', line 38

def execute
  bulk_import = create_bulk_import

  BulkImportWorker.perform_async(bulk_import.id)

  ServiceResponse.success(payload: bulk_import)
rescue ActiveRecord::RecordInvalid => e
  ServiceResponse.error(
    message: e.message,
    http_status: :unprocessable_entity
  )
end