Class: Api::V1::FileAssetsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/api/v1/file_assets_controller.rb

Instance Method Summary collapse

Instance Method Details

#destroyObject



30
31
32
33
34
35
36
# File 'app/controllers/api/v1/file_assets_controller.rb', line 30

def destroy
  file_asset = FileAsset.find(params[:id])

  file_asset.destroy

  render json: {success: true}
end

#indexObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/api/v1/file_assets_controller.rb', line 5

def index
  sort_hash = params[:sort].blank? ? {} : Hash.symbolize_keys(JSON.parse(params[:sort]).first)
  sort = sort_hash[:property] || 'description'
  dir = sort_hash[:direction] || 'ASC'
  limit = params[:limit] || 25
  start = params[:start] || 0
  query_filter = params[:query_filter].blank? ? {} : JSON.parse(params[:query_filter]).symbolize_keys

  # apply filters
  file_assets = FileAsset.apply_filters(query_filter)

  # if no file asset holder was passed we need to scope by dba_organization
  if !query_filter[:file_asset_holder_type].present? && !query_filter[:file_asset_holder_id].present?
    file_assets = file_assets.scope_by_dba_org(current_user.party.dba_organization)
  end

  total_count = file_assets.count
  file_assets = file_assets.limit(limit).offset(start)
  file_assets.order("#{sort} #{dir}")

  render json: {success: true,
                total_count: total_count,
                file_assets: file_assets.collect { |file| file.to_data_hash }}
end