diff --git a/app/controllers/home/platform_communicates_controller.rb b/app/controllers/home/platform_communicates_controller.rb new file mode 100644 index 00000000..1a8fab99 --- /dev/null +++ b/app/controllers/home/platform_communicates_controller.rb @@ -0,0 +1,7 @@ +class Home::PlatformCommunicatesController < ApplicationController + + def index + scope = PlatformCommunicate.order(created_at: :desc) + @communicates = kaminari_paginate(scope) + end +end \ No newline at end of file diff --git a/app/models/competition.rb b/app/models/competition.rb index 39529d39..aeed5cc3 100644 --- a/app/models/competition.rb +++ b/app/models/competition.rb @@ -1,4 +1,30 @@ +# == Schema Information +# +# Table name: competitions +# +# id :integer not null, primary key +# title :string(255) +# start_time :datetime +# end_time :datetime +# identifier :string(255) +# available :boolean default("0") +# online_time :datetime +# visits :integer default("0") +# competition_lists_count :integer default("0") +# min_num :integer default("1") +# max_num :integer default("1") +# enroll_end_time :datetime +# created_at :datetime not null +# updated_at :datetime not null +# status :integer default("0") +# subtitle :string(255) +# team_members_count :integer default("0") +# limit_type :integer default("0") +# show_top :integer default("0") +# content :text(65535) +# + class Competition < ApplicationRecord enum status: {archived: 0, active: 1} -end \ No newline at end of file +end diff --git a/app/models/platform_communicate.rb b/app/models/platform_communicate.rb new file mode 100644 index 00000000..35de9c02 --- /dev/null +++ b/app/models/platform_communicate.rb @@ -0,0 +1,15 @@ +# == Schema Information +# +# Table name: platform_communicates +# +# id :integer not null, primary key +# title :string(255) +# content :string(255) +# tag_field :text(65535) +# fake_id :integer +# created_at :datetime not null +# updated_at :datetime not null +# + +class PlatformCommunicate < ApplicationRecord +end diff --git a/app/views/home/platform_communicates/index.json.jbuilder b/app/views/home/platform_communicates/index.json.jbuilder new file mode 100644 index 00000000..2801c249 --- /dev/null +++ b/app/views/home/platform_communicates/index.json.jbuilder @@ -0,0 +1,8 @@ +json.total_count @communicates.total_count +json.communicates do + json.array! @communicates.each do |communicate| + json.(communicate, :id, :title, :content, :fake_id) + json.tag communicate.tag_field.include?(',') ? communicate.tag_field.split(",") : communicate.tag_field + json.created_time format_time(communicate.created_at) + end +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index c193dae8..81805b51 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -105,6 +105,7 @@ Rails.application.routes.draw do namespace :home do resources :platform_statistics, only: [:index] resources :competitions, only:[:index] + resources :platform_communicates, only: [:index] end get 'home/index' get 'home/search' diff --git a/db/migrate/20211202083700_create_platform_communicates.rb b/db/migrate/20211202083700_create_platform_communicates.rb new file mode 100644 index 00000000..315f745e --- /dev/null +++ b/db/migrate/20211202083700_create_platform_communicates.rb @@ -0,0 +1,12 @@ +class CreatePlatformCommunicates < ActiveRecord::Migration[5.2] + def change + create_table :platform_communicates do |t| + t.string :title + t.string :content + t.text :tag_field + t.integer :fake_id + + t.timestamps + end + end +end