sponsor tiers增删改查

This commit is contained in:
qyzh 2020-09-19 09:59:05 +08:00
parent 5433920724
commit faf2302b8e
10 changed files with 45 additions and 43 deletions

View File

@ -4,7 +4,9 @@ class SponsorTiersController < ApplicationController
# GET /sponsor_tiers
# GET /sponsor_tiers.json
def index
@sponsor_tiers = SponsorTier.all
# @sponsor_tiers = SponsorTier.all
user = User.find_by_login(params[:login])
@sponsor_tiers = user.sponsor_tier
end
# GET /sponsor_tiers/1
@ -14,7 +16,8 @@ class SponsorTiersController < ApplicationController
# GET /sponsor_tiers/new
def new
@sponsor_tier = SponsorTier.new
# @sponsor_tier = SponsorTier.new
# User.current.create
end
# GET /sponsor_tiers/1/edit
@ -24,6 +27,7 @@ class SponsorTiersController < ApplicationController
# POST /sponsor_tiers
# POST /sponsor_tiers.json
def create
# print("------------\n", sponsor_tier_params, "\n------------\n")
@sponsor_tier = SponsorTier.new(sponsor_tier_params)
respond_to do |format|
@ -41,12 +45,13 @@ class SponsorTiersController < ApplicationController
# PATCH/PUT /sponsor_tiers/1.json
def update
respond_to do |format|
if @sponsor_tier.update(sponsor_tier_params)
if User.current.id == @sponsor_tier.user_id && @sponsor_tier.update(sponsor_tier_params)
format.html { redirect_to @sponsor_tier, notice: 'Sponsor tier was successfully updated.' }
format.json { render :show, status: :ok, location: @sponsor_tier }
else
format.html { render :edit }
format.json { render json: @sponsor_tier.errors, status: :unprocessable_entity }
# format.json { render status: :unprocessable_entity }
end
end
end
@ -54,10 +59,14 @@ class SponsorTiersController < ApplicationController
# DELETE /sponsor_tiers/1
# DELETE /sponsor_tiers/1.json
def destroy
@sponsor_tier.destroy
respond_to do |format|
format.html { redirect_to sponsor_tiers_url, notice: 'Sponsor tier was successfully destroyed.' }
format.json { head :no_content }
if User.current.id == @sponsor_tier.user_id
@sponsor_tier.destroy
respond_to do |format|
format.html { redirect_to sponsor_tiers_url, notice: 'Sponsor tier was successfully destroyed.' }
format.json { head :no_content }
end
else
format.json { render json: @sponsor_tier.errors, status: :unprocessable_entity }
end
end
@ -69,6 +78,6 @@ class SponsorTiersController < ApplicationController
# Only allow a list of trusted parameters through.
def sponsor_tier_params
params.require(:sponsor_tier).permit(:tier)
params.require(:sponsor_tier).permit(:tier, :user_id, :description)
end
end

View File

@ -209,6 +209,15 @@ class UsersController < ApplicationController
render_ok
end
def update_description
@user = User.find params[:id]
if @user.id == User.current.id && @user.update(description: params[:description])
render_ok
else
render_error
end
end
private
def load_user
@user = User.find_by_login(params[:id]) || User.find_by(id: params[:id])

View File

@ -1,3 +1,4 @@
class SponsorTier < ApplicationRecord
belongs_to :user
end

View File

@ -99,10 +99,10 @@ class User < ApplicationRecord
has_many :stopped_sponsored, class_name: 'StoppedSponsorship', foreign_key: 'developer_id', dependent: :destroy
has_many :sponsor_tier, dependent: :destroy
has_one :wallet, dependent: :destroy
has_many :waitlist, class_name: 'Waitlist', foreign_key: 'reviewer_id', optional: true
has_many :passed_waitlist, class_name: 'PassedWaitlist', foreign_key: 'reviewer_id', optional: true #as reviewer
has_one :application, class_name: 'Waitlist', foreign_key: 'applicant_id', optional: true
has_one :passed_application, class_name: 'PassedWaitlist', foreign_key: 'applicant_id', optional: true
has_many :waitlist, class_name: 'Waitlist', foreign_key: 'reviewer_id'
has_many :passed_waitlist, class_name: 'PassedWaitlist', foreign_key: 'reviewer_id' #as reviewer
has_one :application, class_name: 'Waitlist', foreign_key: 'applicant_id'
has_one :passed_application, class_name: 'PassedWaitlist', foreign_key: 'applicant_id'
# Groups and active users

View File

@ -1,2 +1,2 @@
json.extract! sponsor_tier, :id, :tier, :created_at, :updated_at
json.extract! sponsor_tier, :id, :tier, :description, :created_at, :updated_at
json.url sponsor_tier_url(sponsor_tier, format: :json)

View File

@ -1,27 +0,0 @@
<p id="notice"><%= notice %></p>
<h1>Sponsor Tiers</h1>
<table>
<thead>
<tr>
<th>Tier</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @sponsor_tiers.each do |sponsor_tier| %>
<tr>
<td><%= sponsor_tier.tier %></td>
<td><%= link_to 'Show', sponsor_tier %></td>
<td><%= link_to 'Edit', edit_sponsor_tier_path(sponsor_tier) %></td>
<td><%= link_to 'Destroy', sponsor_tier, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New Sponsor Tier', new_sponsor_tier_path %>

View File

@ -12,5 +12,6 @@ json.user_phone_binded @user.phone.present?
# json.email @user.mail
json.profile_completed @user.profile_completed?
json.professional_certification @user.professional_certification
json.description @user.description

View File

@ -14,4 +14,5 @@ json.undo_events @undo_events
json.user_composes_count @user_composes_count
json.common_projects_count @projects_common_count
json.mirror_projects_count @projects_mirrior_count
json.sync_mirror_projects_count @projects_sync_mirrior_count
json.sync_mirror_projects_count @projects_sync_mirrior_count
json.description @user.description

View File

@ -1,7 +1,5 @@
Rails.application.routes.draw do
resources :sponsor_tiers
resources :sponsorships
require 'sidekiq/web'
require 'admin_constraint'
@ -18,6 +16,10 @@ Rails.application.routes.draw do
resources :edu_settings
scope '/api' do
resources :sponsor_tiers
resources :sponsorships
resources :sync_forge, only: [:create] do
collection do
post :sync_users
@ -154,6 +156,7 @@ Rails.application.routes.draw do
get :projects
get :watch_users
get :fan_users
put :update_description
end
collection do
post :following

View File

@ -0,0 +1,5 @@
class AddColumnToStoppedSponsorship < ActiveRecord::Migration[5.2]
def change
add_column :stopped_sponsorships, :start_time, :datetime
end
end