dev_sync_trustie
parent
380f2a62d7
commit
178d70924f
@ -0,0 +1,29 @@
|
|||||||
|
class Admins::CompetitionStageCreateService < ApplicationService
|
||||||
|
attr_reader :competition, :params
|
||||||
|
|
||||||
|
def initialize(competition, params)
|
||||||
|
@params = params
|
||||||
|
@competition = competition
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
stage = CompetitionStage.create!(competition_id: competition.id, name: params[:stage_name], score_rate: (params[:score_rate].to_i / 100).round(2))
|
||||||
|
|
||||||
|
stage.competition_stage_sections.destroy_all
|
||||||
|
|
||||||
|
params[:stage].each do |section|
|
||||||
|
stage_section = CompetitionStageSection.create!(competition_id: competition.id, competition_stage_id: stage.id,
|
||||||
|
start_time: section["start_time"], end_time: section["end_time"],
|
||||||
|
mission_count: section["mission_count"], entry: section["entry"],
|
||||||
|
score_source: section["score_source"])
|
||||||
|
section["identifiers"].each do |identifier|
|
||||||
|
CompetitionEntry.create!(competition_stage_section_id: stage_section.id, competition_stage_id: stage.id,
|
||||||
|
shixun_identifier: identifier)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
stage
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,30 @@
|
|||||||
|
class Admins::CompetitionStageUpdateService < ApplicationService
|
||||||
|
attr_reader :competition, :params, :stage
|
||||||
|
|
||||||
|
def initialize(competition, params, stage)
|
||||||
|
@params = params
|
||||||
|
@competition = competition
|
||||||
|
@stage = stage
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
stage.update_attributes!(name: params[:stage_name], score_rate: (params[:score_rate].to_i / 100).round(2))
|
||||||
|
|
||||||
|
stage.competition_stage_sections.destroy_all
|
||||||
|
|
||||||
|
params[:stage].each do |section|
|
||||||
|
stage_section = CompetitionStageSection.create!(competition_id: competition.id, competition_stage_id: stage.id,
|
||||||
|
start_time: section["start_time"], end_time: section["end_time"],
|
||||||
|
mission_count: section["mission_count"], entry: section["entry"],
|
||||||
|
score_source: section["score_source"])
|
||||||
|
section["identifiers"].each do |identifier|
|
||||||
|
CompetitionEntry.create!(competition_stage_section_id: stage_section.id, competition_stage_id: stage.id,
|
||||||
|
shixun_identifier: identifier)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
stage
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in new issue