class DigitalAssetsController < ApplicationController include DigitalAssetsHelper respond_to :json skip_filter(*_process_action_callbacks.map(&:filter)) rescue_from 'Mongoid::Errors::DocumentNotFound' do |exception| render json: {errors: [exception.message]}, status: 404 end # GET /digital_assets # GET /digital_assets.json #/digital_assets/search/sami_code=92023 #/digital_assets/search/sami_code=NE00192&title=Fund%20Prospectus&fund_code=20293 def index @digital_assets = request.query_parameters.present? ? search_da(request.query_parameters) : DigitalAsset.all respond_with(@digital_assets) end alias :search :index # GET /digital_assets/1 # GET /digital_assets/1.json def show @digital_asset = /\w{4,8}\.\d{0,3}/ =~ params[:id] ? DigitalAsset.sami_is(params[:id]).desc(:changed_at).first : DigitalAsset.find(params[:id]) respond_with(@digital_asset) end def update da_passed = params[:digital_asset] da = DigitalAsset.find_or_initialize_by(digital_asset_id: da_passed[:digital_asset_id]) da.update_attributes! da_passed head :ok end alias :create :update def destroy da = DigitalAsset.find(params[:id]) da.delete head :ok end def updated_time ids = params[:ids] updated_time = Hash.new ids.each do |id| da = DigitalAsset.where(:digital_asset_id => id) updated_time[id] = da[0].doc_changed_at if da.present? end # render json: updated_time.to_json, status: :ok respond_with(updated_time) end def fund_docs @digital_assets = [] fund_doctypes = {:doctype => [ DigitalAsset::ContentType::PROSPECTUS, DigitalAsset::ContentType::SUMMARY_PROSPECTUS, DigitalAsset::ContentType::SAI, DigitalAsset::ContentType::ANNUAL_REPORT, DigitalAsset::ContentType::SEMIANNUAL_REPORT, DigitalAsset::ContentType::FACTSHEET, DigitalAsset::ContentType::COMMENTARY ]} @digital_assets = search_da(fund_doctypes) # remove anything that doesn't have a fundcode @digital_assets = @digital_assets.reject {|da| da.fund_code.nil?} respond_with(@digital_assets) end end