temp commit project controller
This commit is contained in:
parent
c946352470
commit
ff7959fdc9
|
@ -7,30 +7,74 @@ class ProjectsController < ApplicationController
|
|||
|
||||
def index
|
||||
#Todo
|
||||
|
||||
uid = session[:user_id]
|
||||
pid = Project_user.find(uid)
|
||||
mc = Mission.where(:project_id => pid).size
|
||||
uc = Project_user.where(:project_id => pid).size
|
||||
sc = Share.where(:project_id => pid).size
|
||||
data = []
|
||||
Project.find(pid) do |i|
|
||||
data += [{
|
||||
:id => i.id,
|
||||
:name => i.name,
|
||||
:content => i.content,
|
||||
:mission_count => mc,
|
||||
:users_count => uc,
|
||||
:shares_count => sc
|
||||
}]
|
||||
end
|
||||
render :json => {
|
||||
:code => 0,
|
||||
:data => data
|
||||
}
|
||||
end
|
||||
|
||||
#创建项目
|
||||
|
||||
def create
|
||||
#Todo
|
||||
|
||||
|
||||
body = request.body.read
|
||||
project = Project.new()
|
||||
project.content = body[:content]
|
||||
project.name = body[:name]
|
||||
project.save!
|
||||
render :json => {:code => 0}
|
||||
end
|
||||
|
||||
#项目添加用户
|
||||
|
||||
def addUsers
|
||||
#Todo
|
||||
|
||||
body = request.body.read
|
||||
pu = Project_user.new()
|
||||
pu.project_id = body[:project_id]
|
||||
#pu.user_id = body[:user_id]
|
||||
pu.save!
|
||||
render :json => {:code => 0}
|
||||
end
|
||||
|
||||
#项目详情
|
||||
|
||||
def detail
|
||||
#Todo
|
||||
|
||||
pid = params[:id]
|
||||
project = Project.find(pid)
|
||||
uid = Project_user.where(:project_id => pid)
|
||||
users = []
|
||||
Users.find(uid).each do |i|
|
||||
users += [{
|
||||
:nickname => i.name,
|
||||
:id => i.id
|
||||
}]
|
||||
end
|
||||
|
||||
|
||||
render :json => {
|
||||
:code => 0,
|
||||
:data => {
|
||||
:name => project.name,
|
||||
:content => project.content,
|
||||
:users => users
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue