temp commit project controller

This commit is contained in:
alan snape 2016-12-28 08:50:19 +00:00
parent c946352470
commit ff7959fdc9
1 changed files with 51 additions and 7 deletions

View File

@ -7,30 +7,74 @@ class ProjectsController < ApplicationController
def index def index
#Todo #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 end
#创建项目 #创建项目
def create def create
#Todo #Todo
body = request.body.read
project = Project.new()
project.content = body[:content]
project.name = body[:name]
project.save!
render :json => {:code => 0}
end end
#项目添加用户 #项目添加用户
def addUsers def addUsers
#Todo #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 end
#项目详情 #项目详情
def detail def detail
#Todo #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
end end