From a6af66476b6e022417540be248aadcb7734f1657 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 24 Oct 2019 09:32:51 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AB=9E=E8=B5=9B=E5=88=97=E8=A1=A8=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/competition.rb | 11 +++++++++++ .../competitions/competitions/index.json.jbuilder | 1 + 2 files changed, 12 insertions(+) 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