新增:专家学历以及专家头像

This commit is contained in:
yystopf 2026-03-27 15:43:04 +08:00
parent 65a15cbc5d
commit b2d7c6a39f
5 changed files with 19 additions and 1 deletions

View File

@ -1,5 +1,6 @@
class Api::V1::ResidentExpertsController < Api::V1::BaseController
before_action :require_login, except: [:index]
before_action :convert_image!, only: [:update_image]
def index
@resident_experts = ResidentExpert.approved.includes(:user)
@ -53,6 +54,16 @@ class Api::V1::ResidentExpertsController < Api::V1::BaseController
@resident_expert_actions = @resident_expert.resident_expert_actions
end
def update_image
return render_not_found unless @resident_expert = ResidentExpert.find_by(user_id: current_user.id)
Util.write_file(@image, avatar_path(@resident_expert))
return render_ok({message: '头像修改成功'})
rescue Exception => e
uid_logger_error(e.message)
render_result(-1, '头像修改失败!')
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)

View File

@ -5,7 +5,7 @@ class ResidentExpert < ApplicationRecord
enum gender: { male: 0, female: 1, secret: 2 }
enum expert_category: { technological: 0, economic: 1, management: 2 }
enum academic_degree: { bachelor: 0, master: 1, doctor: 2 }
enum academic_degree: { bachelor: 0, master: 1, doctor: 2, college: 3, other: 4 }
enum status: { pending: 0, approved: 1, rejected: 2 }
validates :user_id, presence: true, uniqueness: true
@ -42,6 +42,10 @@ class ResidentExpert < ApplicationRecord
'硕士研究生'
when "doctor"
'博士研究生'
when "college"
'大专'
when "other"
'其他'
end
end

View File

@ -3,6 +3,7 @@ json.user do
end
json.id resident_expert.id
json.name resident_expert.name
json.image_url url_to_avatar(resident_expert)
json.gender resident_expert.gender
json.expert_category resident_expert.expert_category
json.academic_degree resident_expert.academic_degree

View File

@ -5,6 +5,7 @@ json.resident_experts @resident_experts do |resident_expert|
end
json.id resident_expert.id
json.name resident_expert.name
json.image_url url_to_avatar(resident_expert)
json.gender resident_expert.gender
json.expert_category resident_expert.expert_category
json.academic_degree resident_expert.academic_degree

View File

@ -75,6 +75,7 @@ defaults format: :json do
post :reset
get :current
get :actions
put :update_image
end
end