Skip to content

Commit

Permalink
Fix university_remark
Browse files Browse the repository at this point in the history
  • Loading branch information
zw963 committed May 29, 2024
1 parent 96d377e commit c6895ed
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/components/universities/form_fields.cr
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class Universities::FormFields < BaseComponent
br

div class: "row" do
mount Shared::Field, op.description, "附加信息", &.textarea(rows: 10, cols: 50, style: "min-width: 600px; min-height: 300px;", placeholder: "随便输入点啥, 可以方便的在首页模糊搜索", replace_class: "materialize-textarea")
mount Shared::Field, op.university_remark, "学校附加信息", &.textarea(rows: 10, cols: 50, style: "min-width: 600px; min-height: 300px;", placeholder: "随便输入点啥, 可以方便的在首页模糊搜索", replace_class: "materialize-textarea")
end

br
Expand Down
2 changes: 1 addition & 1 deletion src/components/universities/main.cr
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ then set (next <input/>).value to my.value2
end
td university.batch_level.display_name
td style: "max-width: 100px;", class: "double-line" do
text university.description.to_s
text university.remark(current_user)
end
mount(
ClickEditTD,
Expand Down
12 changes: 12 additions & 0 deletions src/models/university.cr
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,16 @@ class University < BaseModel

has_many chong_wen_baos : ChongWenBao
end

def remark(user)
cwb = chong_wen_baos.find do |x|
x.user_id == user.id
end

if cwb.nil?
""
else
cwb.university_remark.to_s
end
end
end
42 changes: 20 additions & 22 deletions src/operations/save_university.cr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class SaveUniversity < University::SaveOperation
upsert_lookup_columns code, batch_level

permit_columns name, description, code,
permit_columns name, code,
is_211, is_985, is_good, batch_level,
score_2023_min, ranking_2023_min,
score_2022_min, ranking_2022_min,
Expand All @@ -28,6 +28,8 @@ class SaveUniversity < University::SaveOperation
attribute bao_2021 : Bool
attribute bao_2020 : Bool

attribute university_remark : String

attribute current_user_id : Int64

before_save do
Expand Down Expand Up @@ -70,26 +72,22 @@ class SaveUniversity < University::SaveOperation

private def update_chong_wen_bao_options(saved_record : University)
user_id = current_user_id.value.not_nil!

ChongWenBaoQuery.new
.university_id(saved_record.id)
.user_id(user_id)
.first?.try do |chong_wen_bao|
SaveChongWenBao.update!(
chong_wen_bao,
chong_2023: chong_2023.value.not_nil!,
chong_2022: chong_2022.value.not_nil!,
chong_2021: chong_2021.value.not_nil!,
chong_2020: chong_2020.value.not_nil!,
wen_2023: wen_2023.value.not_nil!,
wen_2022: wen_2022.value.not_nil!,
wen_2021: wen_2021.value.not_nil!,
wen_2020: wen_2020.value.not_nil!,
bao_2023: bao_2023.value.not_nil!,
bao_2022: bao_2022.value.not_nil!,
bao_2021: bao_2021.value.not_nil!,
bao_2020: bao_2020.value.not_nil!,
)
end
SaveChongWenBao.upsert!(
university_id: saved_record.id,
user_id: user_id,
university_remark: university_remark.value,
chong_2023: chong_2023.value.not_nil!,
chong_2022: chong_2022.value.not_nil!,
chong_2021: chong_2021.value.not_nil!,
chong_2020: chong_2020.value.not_nil!,
wen_2023: wen_2023.value.not_nil!,
wen_2022: wen_2022.value.not_nil!,
wen_2021: wen_2021.value.not_nil!,
wen_2020: wen_2020.value.not_nil!,
bao_2023: bao_2023.value.not_nil!,
bao_2022: bao_2022.value.not_nil!,
bao_2021: bao_2021.value.not_nil!,
bao_2020: bao_2020.value.not_nil!,
)
end
end

0 comments on commit c6895ed

Please sign in to comment.