Merge branch 'dev_aliyun' of http://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun
commit
8de2fec21e
@ -0,0 +1,27 @@
|
|||||||
|
class Competitions::CreatePersonalTeamService < ApplicationService
|
||||||
|
Error = Class.new(StandardError)
|
||||||
|
|
||||||
|
attr_reader :competition, :user
|
||||||
|
|
||||||
|
def initialize(competition, user)
|
||||||
|
@competition = competition
|
||||||
|
@user = user
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
raise Error, '个人赛才能报名' unless competition.personal?
|
||||||
|
|
||||||
|
is_teacher = user.is_teacher?
|
||||||
|
raise Error, '本竞赛的参赛者限定为:学生' if is_teacher && competition.teacher_enroll_forbidden?
|
||||||
|
raise Error, '本竞赛的参赛者限定为:教师' if !is_teacher && competition.member_enroll_forbidden?
|
||||||
|
|
||||||
|
enrolled = competition.competition_teams.exists?(user_id: user.id)
|
||||||
|
multiple_limited = (is_teacher && competition.teacher_multiple_limited?) || (!is_teacher && competition.member_multiple_limited?)
|
||||||
|
raise Error, '您已报名该竞赛' if enrolled && multiple_limited
|
||||||
|
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
team = competition.competition_teams.create!(name: user.show_name, user_id: user.id)
|
||||||
|
team.team_members.create!(competition_id: competition, user_id: user.id, role: 1, is_teacher: is_teacher)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -1,4 +1,4 @@
|
|||||||
json.(@base_date, :grade, :gold, :experience, :status, :had_done, :position, :port, :record_consume_time, :mirror_name,
|
json.(@base_date, :grade, :gold, :experience, :status, :had_done, :position, :port, :record_consume_time, :mirror_name,
|
||||||
:picture, :web_route, :star, :next_game, :prev_game)
|
:picture, :web_route, :star, :next_game, :prev_game, :max_mem)
|
||||||
# # 测试集相关
|
# # 测试集相关
|
||||||
json.partial! 'games/testset_list'
|
json.partial! 'games/testset_list'
|
@ -1,13 +0,0 @@
|
|||||||
defaults: &defaults
|
|
||||||
url: http://localhost:9200
|
|
||||||
|
|
||||||
development:
|
|
||||||
<<: *defaults
|
|
||||||
|
|
||||||
test:
|
|
||||||
<<: *defaults
|
|
||||||
|
|
||||||
production:
|
|
||||||
<<: *defaults
|
|
||||||
url: 'http://elastic:Elas+ucloud123@106.75.27.125:59200/'
|
|
||||||
# url: 'http://elastic:TEST_elastickibana321@es-cn-0pp174wsj000iubdx.public.elasticsearch.aliyuncs.com'
|
|
Loading…
Reference in new issue