forked from Trustie/forgeplus
57 lines
3.3 KiB
Ruby
57 lines
3.3 KiB
Ruby
class Api::V1::ResidentExpertsController < Api::V1::BaseController
|
||
before_action :require_login, except: [:index]
|
||
|
||
def index
|
||
all_resident_experts = ResidentExpert.approved.includes(:user)
|
||
@resident_experts = all_resident_experts.where(expert_category: params[:expert_category]) if params[:expert_category].present?
|
||
@resident_experts = @resident_experts.where("name like ? or department like ?", "%#{params[:keyword]}%", "%#{params[:keyword]}%") if params[:keyword].present?
|
||
@resident_expert_category_list = all_resident_experts.group(:expert_category).count
|
||
@resident_expert_memos_rank_list = all_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: "预计 1~3 个工作日内完成" )
|
||
@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 reset
|
||
@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: "预计 1~3 个工作日内完成" )
|
||
@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 |