报名接口

issues25489
daiao 5 years ago
parent 15d7164b09
commit a36cb003ba

@ -36,6 +36,15 @@ class TrustieHacksController < ApplicationController
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

@ -1,4 +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

@ -5,5 +5,6 @@ end
json.hacks @hacks do |hack|
json.(hack, :id, :name, :description, :hack_users_count)
json.entry_info hack.entry_info(current_user.id)
end

@ -880,7 +880,9 @@ Rails.application.routes.draw do
get :edit_hackathon
post :update_hackathon
end
member do
post :entry
end
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
Loading…
Cancel
Save