Browse Source

add: competitions

pull/278/head
viletyy 4 years ago
parent
commit
0a00a4bc0e
6 changed files with 25 additions and 2 deletions
  1. +9
    -0
      app/controllers/home/competitions_controller.rb
  2. +1
    -1
      app/controllers/home/platform_statistics_controller.rb
  3. +4
    -0
      app/models/competition.rb
  4. +7
    -0
      app/views/home/competitions/index.json.jbuilder
  5. +0
    -0
      app/views/home/platform_statistics/index.json.jbuilder
  6. +4
    -1
      config/routes.rb

+ 9
- 0
app/controllers/home/competitions_controller.rb 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

app/controllers/platform_statistics_controller.rb → app/controllers/home/platform_statistics_controller.rb 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

+ 4
- 0
app/models/competition.rb View File

@@ -0,0 +1,4 @@
class Competition < ApplicationRecord

enum status: {archived: 0, active: 1}
end

+ 7
- 0
app/views/home/competitions/index.json.jbuilder 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

app/views/platform_statistics/index.json.jbuilder → app/views/home/platform_statistics/index.json.jbuilder View File


+ 4
- 1
config/routes.rb 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'


Loading…
Cancel
Save