Sha256: ff1fbdefbbfff4598ee7da26700a1d1162ea93af47da7dcaf70da1db6abc8cca
Contents?: true
Size: 1.65 KB
Versions: 2
Compression:
Stored size: 1.65 KB
Contents
module Dune::Api module V1 class InvestmentsController < BaseController include PaginatedController before_action :require_admin! has_scope :pg_search, as: :query has_scope :by_project_id, as: :project_id has_scope :between_values, using: %i(initial final), type: :hash def index respond_with_pagination collection end def show respond_with Dune::Api::Investment.find(params[:id]) end def update @investment = ::Investment.find(params[:id]) authorize @investment respond_with ::Investment.update(params[:id], permitted_params) end def destroy investment = ::Investment.find(params[:id]) authorize investment investment.push_to_trash! head :no_content end [:confirm, :pendent, :refund, :hide, :cancel].each do |name| define_method name do investment = ::Investment.find(params[:id]) authorize investment investment.send("#{name.to_s}!") head :no_content end end private def permitted_params params.permit(policy(@investment || ::Investment).permitted_attributes)[:investment] end def collection @collection ||= begin apply_scopes( scoped_by_state(Dune::Api::Investment) ).order('created_at desc').all end end def scoped_by_state(scope) state_scopes = params.slice(*Investment.state_names).keys if state_scopes.any? scope.with_state(state_scopes) else scope end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
dune-api-1.0.2 | app/controllers/dune/api/v1/investments_controller.rb |
dune-api-1.0.1 | app/controllers/dune/api/v1/investments_controller.rb |