竞赛接口调整

dev_sync_trustie
cxt 5 years ago
parent 12c05c262b
commit 803d9d5d7d

@ -3,22 +3,18 @@ class CompetitionModule < ApplicationRecord
belongs_to :competition
has_one :competition_module_md_content, dependent: :destroy
has_many :competition_module_md_contents, dependent: :destroy
def module_url
case module_type
result_url = url.present? ? url : case module_type
when "home"
"/competitions/#{competition.identifier}.json"
when "inform"
"/competitions/#{competition.identifier}/informs.json?status=1"
when "manual"
"/competitions/#{competition.identifier}/informs.json?status=2"
when "chart"
"/competitions/#{competition.identifier}/charts.json"
when "enroll"
"/competitions/#{competition.identifier}/competition_teams.json"
else
url || "/competitions/#{competition.identifier}/md_content.json?md_content_id=#{competition_module_md_content&.id}"
"/competitions/#{competition.identifier}/competition_modules/#{id}.json"
end
end
end

@ -1,7 +1,7 @@
json.extract! @module, :id, :name, :position, :url, :md_edit
json.extract! @module, :id, :name, :position, :url
md = @module.competition_module_md_content
if md.present?
mds = @module.competition_module_md_contents
json.md_contents mds.each do |md|
json.md_name md.name
json.md_content md.content
json.created_at md.created_at.strftime('%Y-%m-%d %H:%M:%S')

@ -0,0 +1,17 @@
class MigrateCompetitionModuleContent < ActiveRecord::Migration[5.2]
def change
Competition.all.each do |competition|
competition.informs.each do |inform|
if inform.status == 1
com_module = competition.competition_modules.find_by(module_type: "inform")
elsif inform.status == 2
com_module = competition.competition_modules.find_by(name: "参赛手册")
end
if com_module
new_md = CompetitionModuleMdContent.create!(competition_module_id: com_module.id, content: inform.description, name: inform.name)
Attachment.where(container_id: inform.id, container_type: "Inform").update_all(container_id: new_md.id, container_type: "CompetitionModuleMdContent")
end
end
end
end
end
Loading…
Cancel
Save