Class: Dscf::Banking::DocumentsController

Inherits:
ApplicationController show all
Includes:
DemoPermissionBypass, Core::Common
Defined in:
app/controllers/dscf/banking/documents_controller.rb

Instance Method Summary collapse

Methods included from DemoPermissionBypass

#authorize_review_action!, #bypass_permissions_for_demo?, #pundit_user

Methods inherited from ApplicationController

#bypass_permissions_for_demo?, #pundit_user

Instance Method Details

#createObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/dscf/banking/documents_controller.rb', line 24

def create
  document = @application.documents.build(model_params)
  
  if document.save
    # Attach file if provided
    document.files.attach(params[:document][:file]) if params[:document][:file].present?
    
    render json: {
      success: true,
      data: DocumentSerializer.new(document).as_json
    }, status: :created
  else
    render json: {
      success: false,
      error: "Failed to create document",
      errors: document.errors.full_messages
    }, status: :unprocessable_entity
  end
end

#indexObject



8
9
10
11
12
13
14
# File 'app/controllers/dscf/banking/documents_controller.rb', line 8

def index
  super do
    documents = @application.documents
    options = { each_serializer: DocumentSerializer }
    [documents, options]
  end
end

#showObject



16
17
18
19
20
21
22
# File 'app/controllers/dscf/banking/documents_controller.rb', line 16

def show
  super do
    document = @application.documents.find(params[:id])
    options = { serializer: DocumentSerializer }
    [document, options]
  end
end