diff --git a/app/models/competition.rb b/app/models/competition.rb index d8a8318b3..39e4f4dfe 100644 --- a/app/models/competition.rb +++ b/app/models/competition.rb @@ -40,6 +40,17 @@ class Competition < ApplicationRecord end end + def competition_status + if !status + com_status = "nearly_published" + elsif end_time > Time.now + com_status = "progressing" + else + com_status = "ended" + end + com_status + end + def teacher_staff_num teacher_staff ? "#{teacher_staff.minimum}~#{teacher_staff.maximum}" : "--" end diff --git a/app/views/competitions/competitions/index.json.jbuilder b/app/views/competitions/competitions/index.json.jbuilder index 8e99d754d..810cbfd18 100644 --- a/app/views/competitions/competitions/index.json.jbuilder +++ b/app/views/competitions/competitions/index.json.jbuilder @@ -3,6 +3,7 @@ json.competitions do json.array! @competitions.each do |competition| json.extract! competition, :id, :identifier, :name, :sub_title, :bonus, :description, :mode + json.competition_status competition.competition_status json.visits_count competition.visits member_count = @member_count_map&.fetch(competition.id, 0) || competition.team_members.count json.member_count member_count.zero? ? 268 : member_count