Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun
commit
533539c729
@ -0,0 +1,2 @@
|
||||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
@ -0,0 +1,3 @@
|
||||
// Place all the styles related to the trustie_hacks controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
@ -0,0 +1,71 @@
|
||||
class TrustieHacksController < ApplicationController
|
||||
before_action :require_admin, :except => [:index]
|
||||
before_action :require_login, :except => [:index]
|
||||
before_action :find_hackathon
|
||||
before_action :find_hack, :except => [:create, :index, :edit_hackathon, :update_hackathon]
|
||||
|
||||
def index
|
||||
## 分页参数
|
||||
page = params[:page] || 1
|
||||
limit = params[:limit] || 16
|
||||
search = params[:search]
|
||||
hacks = @hackathon.trustie_hacks
|
||||
|
||||
if search
|
||||
hacks = hacks.where("name like ?", "%#{search}%")
|
||||
end
|
||||
|
||||
@hackathon_users_count = hacks ? 0 : hacks.sum(:hack_users_count)
|
||||
|
||||
@hacks = hacks.page(page).per(limit)
|
||||
|
||||
end
|
||||
|
||||
def edit;end
|
||||
|
||||
def create
|
||||
@hackathon.trustie_hacks.create!(name: params[:name], description: params[:description])
|
||||
render_ok
|
||||
end
|
||||
|
||||
def update
|
||||
@hack.update_attributes(name: params[:name], description: params[:description])
|
||||
render_ok
|
||||
end
|
||||
|
||||
def destroy
|
||||
@hack.destroy
|
||||
render_ok
|
||||
end
|
||||
|
||||
def edit_hackathon
|
||||
end
|
||||
|
||||
def update_hackathon
|
||||
@hackathon.update_attributes(name: params[:name], description: params[:description])
|
||||
render_ok
|
||||
end
|
||||
|
||||
# 报名入口
|
||||
def entry
|
||||
if @hack.hack_users.exists?(user_id: current_user)
|
||||
render_error('已经报名,请勿重复操作')
|
||||
else
|
||||
@hack.hack_users.create(user_id: current_user)
|
||||
render_ok
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def find_hackathon
|
||||
@hackathon = TrustieHackathon.first ||
|
||||
TrustieHackathon.create!(name: params[:name], description: params[:description])
|
||||
end
|
||||
|
||||
def find_hack
|
||||
@hack = TrustieHack.find params[:id]
|
||||
end
|
||||
|
||||
end
|
@ -0,0 +1,2 @@
|
||||
module TrustieHacksHelper
|
||||
end
|
@ -0,0 +1,3 @@
|
||||
class HackUser < ApplicationRecord
|
||||
belongs_to :trustie_hack, counter_cache: true
|
||||
end
|
@ -0,0 +1,9 @@
|
||||
class TrustieHack < ApplicationRecord
|
||||
has_many :hack_users, :dependent => :destroy
|
||||
belongs_to :trustie_hackathon, counter_cache: true
|
||||
|
||||
|
||||
def entry_info(user_id)
|
||||
hack_users.exists?(user_id: user_id)
|
||||
end
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
class TrustieHackathon < ApplicationRecord
|
||||
|
||||
has_many :trustie_hacks, :dependent => :destroy
|
||||
|
||||
end
|
@ -0,0 +1 @@
|
||||
json.(@hack, :id, :name, :description)
|
@ -0,0 +1,2 @@
|
||||
json.name @hackathon&.name
|
||||
json.description @hackathon&.description
|
@ -0,0 +1,10 @@
|
||||
json.hackathon do
|
||||
json.(@hackathon, :id, :name, :description)
|
||||
json.hackathon_users_count @hackathon_users_count
|
||||
end
|
||||
|
||||
json.hacks @hacks do |hack|
|
||||
json.(hack, :id, :name, :description, :hack_users_count)
|
||||
json.entry_info hack.entry_info(current_user.id)
|
||||
end
|
||||
|
@ -0,0 +1,10 @@
|
||||
class CreateTrustieHackathons < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :trustie_hackathons do |t|
|
||||
t.string :name
|
||||
t.string :description
|
||||
t.integer :trustie_hacks_count, default: 0
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,11 @@
|
||||
class CreateTrustieHacks < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :trustie_hacks do |t|
|
||||
t.string :name
|
||||
t.string :description
|
||||
t.references :user
|
||||
t.integer :hack_users_count, default: 0
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,9 @@
|
||||
class CreateHackUsers < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :hack_users do |t|
|
||||
t.references :user
|
||||
t.references :trustie_hack
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,6 @@
|
||||
class AddTrustieHackathonIdForTrustieHacks < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :trustie_hacks, :trustie_hackathon_id, :integer
|
||||
add_index :trustie_hacks, :trustie_hackathon_id
|
||||
end
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
class AddUniqIndexForHackUsers < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_index :hack_users, [:user_id, :trustie_hack_id], unique: true
|
||||
end
|
||||
end
|
@ -0,0 +1,40 @@
|
||||
.registrationback{
|
||||
height: 368px;
|
||||
width: 1200px;
|
||||
-ms-flex-direction: column;
|
||||
flex-direction: column;
|
||||
}
|
||||
.textright{
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.Osshackathonfont{
|
||||
width: 80px;
|
||||
height: 28px;
|
||||
font-size: 20px;
|
||||
font-weight:600;
|
||||
color: rgba(5,16,26,1);
|
||||
line-height: 28px;
|
||||
}
|
||||
|
||||
.Osshackathonfontlist{
|
||||
width:1188px;
|
||||
font-size:14px;
|
||||
font-weight:400;
|
||||
color:rgba(102,102,102,1);
|
||||
line-height:24px;
|
||||
}
|
||||
.OsshackathonCard{
|
||||
width:1200px;
|
||||
height:150px;
|
||||
background:rgba(248,248,248,1);
|
||||
border:1px solid rgba(235,235,235,1);
|
||||
}
|
||||
|
||||
.OsshackathonCardtitle{
|
||||
height:24px;
|
||||
font-size:24px;
|
||||
font-weight:400;
|
||||
color:rgba(5,16,26,1);
|
||||
line-height:24px;
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe TrustieHacksController, type: :controller do
|
||||
|
||||
end
|
@ -0,0 +1,15 @@
|
||||
require 'rails_helper'
|
||||
|
||||
# Specs in this file have access to a helper object that includes
|
||||
# the TrustieHacksHelper. For example:
|
||||
#
|
||||
# describe TrustieHacksHelper do
|
||||
# describe "string concat" do
|
||||
# it "concats two strings with spaces" do
|
||||
# expect(helper.concat_strings("this","that")).to eq("this that")
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
RSpec.describe TrustieHacksHelper, type: :helper do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe HackUser, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe TrustieHack, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe TrustieHackathon, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
Loading…
Reference in new issue