add: competitions

This commit is contained in:
viletyy 2021-12-02 15:18:10 +08:00
parent b81d92af46
commit 0a00a4bc0e
6 changed files with 25 additions and 2 deletions

View File

@ -0,0 +1,9 @@
class Home::CompetitionsController < ApplicationController
def index
@competitions = Competition.active.order(start_time: :desc).limit(3)
if @competitions.size < 3
@competitions += Competition.archived.order(start_time: :desc).limit(3-@competitions.size)
end
end
end

View File

@ -1,4 +1,4 @@
class PlatformStatisticsController < ApplicationController class Home::PlatformStatisticsController < ApplicationController
def index def index
@platform_statistic = PlatformStatistic.data @platform_statistic = PlatformStatistic.data

View File

@ -0,0 +1,4 @@
class Competition < ApplicationRecord
enum status: {archived: 0, active: 1}
end

View File

@ -0,0 +1,7 @@
json.competitions do
json.array! @competitions.each do |competition|
json.(competition, :id, :title, :content)
json.start_time format_time(competition.start_time)
json.end_time format_time(competition.end_time)
end
end

View File

@ -102,7 +102,10 @@ Rails.application.routes.draw do
get :template_file get :template_file
end end
end end
resources :platform_statistics, only: [:index] namespace :home do
resources :platform_statistics, only: [:index]
resources :competitions, only:[:index]
end
get 'home/index' get 'home/index'
get 'home/search' get 'home/search'
get 'main/first_stamp' get 'main/first_stamp'