forgeplus/app/controllers/api/v1/resident_experts_controller.rb

55 lines
3.2 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class Api::V1::ResidentExpertsController < Api::V1::BaseController
def index
@resident_experts = ResidentExpert.approved.includes(:user)
@resident_experts = @resident_experts.where(expert_category: params[:expert_category]) if params[:expert_category].present?
@resident_experts = @resident_experts.where("name like ? or department like ?", "%#{params[:search]}%", "%#{params[:search]}%") if params[:keyword].present?
@resident_expert_category_list = @resident_experts.group(:expert_category).count
@resident_expert_memos_rank_list = @resident_experts.order("users.memos_count desc").limit(5)
@resident_experts = @resident_experts.order(created_at: :desc)
@resident_experts = kaminari_paginate(@resident_experts)
end
def current
@resident_expert = ResidentExpert.find_by(user_id: current_user.id)
end
def create
@resident_expert = ResidentExpert.new(resident_expert_params)
@resident_expert.user = current_user
if @resident_expert.save
@resident_expert.resident_expert_actions.create(action_type: ResidentExpertAction::action_types[:approved], action_name: '提交申请' )
@resident_expert.resident_expert_actions.create(action_type: ResidentExpertAction::action_types[:approved], action_name: '进入审核队列' )
@resident_expert.resident_expert_actions.create(action_type: ResidentExpertAction::action_types[:pending], action_name: '管理员审核中', action_description: "预计 13 个工作日内完成" )
@resident_expert.resident_expert_actions.create(action_type: ResidentExpertAction::action_types[:todo], action_name: '展示上线', action_description: "待审核通过后自动上线" )
render_ok
else
render_error(@resident_expert.errors.full_messages)
end
end
def update
@resident_expert = ResidentExpert.find_by(user_id: current_user.id)
@resident_expert.attributes = resident_expert_params
@resident_expert.status = ResidentExpert::statuses[:pending]
if @resident_expert.save
@resident_expert.resident_expert_actions.destroy_all
@resident_expert.resident_expert_actions.create(action_type: ResidentExpertAction::action_types[:approved], action_name: '提交申请' )
@resident_expert.resident_expert_actions.create(action_type: ResidentExpertAction::action_types[:approved], action_name: '进入审核队列' )
@resident_expert.resident_expert_actions.create(action_type: ResidentExpertAction::action_types[:pending], action_name: '管理员审核中', action_description: "预计 13 个工作日内完成" )
@resident_expert.resident_expert_actions.create(action_type: ResidentExpertAction::action_types[:todo], action_name: '展示上线', action_description: "待审核通过后自动上线" )
render_ok
else
render_error(@resident_expert.errors.full_messages)
end
end
def actions
@resident_expert = ResidentExpert.find_by(user_id: current_user.id)
@resident_expert_actions = @resident_expert.resident_expert_actions
end
private
def resident_expert_params
params.require(:resident_expert).permit(:name, :gender, :expert_category, :academic_degree, :department, :title, :territory_area1, :territory_area2, :territory_area3, :introduction)
end
end