Class: Api::ProposalsController
- Inherits:
-
ApplicationController
- Object
- ActionController::API
- ApplicationController
- Api::ProposalsController
- Defined in:
- app/controllers/api/proposals_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #index_answers ⇒ Object
- #my_proposals ⇒ Object
- #show ⇒ Object
-
#update ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity.
Methods included from Utils
#get_id_from_short_title, #is_member, #is_reviewer, #nickname_exist, #short_title_exist
Methods included from Resources
#add_resource, #index_resource, #remove_resource, #update_resource
Methods included from Relations
#clap, #clappers, #follow, #review, #reviewed_object, #save, #saved_objects
Methods included from Members
#get_current_role, #get_roles_list, #has_membership, #invite, #invite_as_admin, #join, #leave, #members_list, #remove_member, #update_member
Methods included from Response
Instance Method Details
#create ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/controllers/api/proposals_controller.rb', line 14 def create proposal = Proposal.new(proposal_params) if proposal.save proposal.update_interests(params[:proposal][:interests]) unless params[:proposal][:interests].nil? proposal.update_skills(params[:proposal][:skills]) unless params[:proposal][:skills].nil? current_user.add_role :owner, proposal current_user.add_role :admin, proposal current_user.add_role :member, proposal render json: proposal, status: :created else render json: proposal.errors., status: :unprocessable_entity end end |
#destroy ⇒ Object
31 32 33 34 35 36 37 |
# File 'app/controllers/api/proposals_controller.rb', line 31 def destroy render status: :method_not_allowed if @proposal.submitted? @proposal.destroy render status: :ok end |
#index_answers ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'app/controllers/api/proposals_controller.rb', line 39 def index_answers answers = Answer .where(proposal_id: @proposal.id) .order(id: :desc) @pagy, records = pagy(answers) render json: records, each_serializer: Api::AnswerSerializer, root: 'answers', adapter: :json end |
#my_proposals ⇒ Object
48 49 50 51 52 53 54 |
# File 'app/controllers/api/proposals_controller.rb', line 48 def my_proposals proposals = Proposal.with_role(:owner, current_user) proposals += Proposal.with_role(:admin, current_user) proposals += Proposal.with_role(:member, current_user) render json: proposals.uniq.sort_by(&:updated_at) end |
#show ⇒ Object
56 57 58 59 60 |
# File 'app/controllers/api/proposals_controller.rb', line 56 def show proposal = Proposal.find(params[:id]) render json: proposal, status: :ok, controller: true end |
#update ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/controllers/api/proposals_controller.rb', line 65 def update project = Project.find(@proposal.project_id) if proposal_params[:score] && @proposal.score && @proposal.peer_review.score_threshold if @proposal.score > @proposal.peer_review.score_threshold User.with_role(:reviewer).first.add_role(:reviewer, project) else User.with_role(:reviewer).first.remove_role(:reviewer, project) end end if @proposal.update(proposal_params) @proposal.update_interests(params[:proposal][:interests]) unless params[:proposal][:interests].nil? @proposal.update_skills(params[:proposal][:skills]) unless params[:proposal][:skills].nil? render json: @proposal.reload, status: :ok else render json: @proposal.errors., status: :unprocessable_entity end end |