2016-07-25 15:20:01 +08:00
#coding=utf-8
module Mobile
module Apis
class Projects < Grape :: API
resources :projects do
desc " 获取项目列表 "
params do
requires :token , type : String
end
get do
authenticate!
ps = ProjectsService . new
projects = ps . user_projects ( current_user )
present :data , projects , with : Mobile :: Entities :: Project , user : current_user
present :status , 0
end
desc " 返回单个项目 "
params do
requires :id , type : Integer
requires :token , type : String
end
route_param :id do
get do
# course = Course.find(params[:id])
ps = ProjectsService . new
project = ps . show_project ( params , current_user )
2016-07-25 17:02:42 +08:00
if project [ :status ] == 9
2016-07-25 15:20:01 +08:00
{ status : - 1 , message : '该项目不存在或已被删除啦' }
else
present :data , project , with : Mobile :: Entities :: Project , user : current_user
present :status , 0
end
end
end
desc " 获取项目动态 "
params do
2016-07-25 17:02:42 +08:00
requires :id , type : Integer
2016-07-25 15:20:01 +08:00
requires :token , type : String
end
2016-07-25 17:02:42 +08:00
post 'activities' do
2016-07-25 15:20:01 +08:00
authenticate!
2016-07-25 17:02:42 +08:00
user = current_user
2016-07-25 15:20:01 +08:00
2016-07-25 17:02:42 +08:00
project_types = " ('Message','Issue','Project') "
activities = UserActivity . where ( " (container_type = 'Project' and container_id = #{ params [ :id ] } and act_type in #{ project_types } ) " ) . order ( 'updated_at desc' )
2016-07-25 15:20:01 +08:00
2016-07-25 17:02:42 +08:00
page = params [ :page ] ? params [ :page ] : 0
all_count = activities . count
activities = activities . limit ( 10 ) . offset ( page * 10 )
count = activities . count
present :data , activities , with : Mobile :: Entities :: Activity , user : user
present :all_count , all_count
present :count , count
present :page , page
present :status , 0
2016-07-25 15:20:01 +08:00
end
2016-07-27 14:30:19 +08:00
desc " 获取项目成员 "
2016-07-25 15:20:01 +08:00
params do
2016-07-27 14:30:19 +08:00
requires :id , type : Integer
2016-07-25 15:20:01 +08:00
requires :token , type : String
end
2016-07-27 14:30:19 +08:00
post 'members' do
2016-07-25 15:20:01 +08:00
authenticate!
2016-07-27 14:30:19 +08:00
project = Project . find ( " #{ params [ :id ] } " )
members = project . member_principals
master_members = project . member_principals . includes ( :roles , :principal ) . where ( " member_roles.role_id=3 " ) . all . sort
2016-07-25 15:20:01 +08:00
2016-07-27 14:30:19 +08:00
master_members . each do | m |
if m . user_id == project . user_id
master_members . delete ( m )
master_members . insert ( 0 , m )
break
end
2016-07-25 15:20:01 +08:00
end
2016-07-27 14:30:19 +08:00
develop_members = project . member_principals . includes ( :roles , :principal ) . where ( " member_roles.role_id=4 " ) . all . sort
report_members = project . member_principals . includes ( :roles , :principal ) . where ( " member_roles.role_id=5 " ) . all . sort
2016-08-03 09:37:24 +08:00
review_master_members = [ ]
review_develop_members = [ ]
my_member = project . member_principals . where ( " users.id= #{ current_user . id } " ) . first
if my_member && my_member . roles [ 0 ] && my_member . roles [ 0 ] . id == 3
ps = ProjectsService . new
user = current_user
review_master_members = ps . get_project_review_members ( project , 3 , user )
review_develop_members = ps . get_project_review_members ( project , 4 , user )
end
2016-07-27 14:30:19 +08:00
present :master_members , master_members , with : Mobile :: Entities :: ProjectMember
present :develop_members , develop_members , with : Mobile :: Entities :: ProjectMember
present :report_members , report_members , with : Mobile :: Entities :: ProjectMember
2016-08-03 14:55:54 +08:00
present :review_master_members , review_master_members
present :review_develop_members , review_develop_members
2016-07-27 14:30:19 +08:00
present :status , 0
2016-07-25 15:20:01 +08:00
end
2016-07-27 14:30:19 +08:00
desc " 获取项目某成员角色信息 "
2016-07-25 15:20:01 +08:00
params do
2016-07-27 14:30:19 +08:00
requires :id , type : Integer
2016-07-25 15:20:01 +08:00
requires :token , type : String
2016-07-27 14:30:19 +08:00
requires :user_id , type : Integer
2016-07-25 15:20:01 +08:00
end
2016-07-27 14:30:19 +08:00
post 'get_member_info' do
2016-07-25 15:20:01 +08:00
authenticate!
2016-07-27 14:30:19 +08:00
project = Project . find ( " #{ params [ :id ] } " )
2016-07-25 15:20:01 +08:00
2016-07-27 14:30:19 +08:00
my_member = project . member_principals . where ( " users.id= #{ params [ :user_id ] } " ) . first
2016-07-25 15:20:01 +08:00
2016-07-27 14:30:19 +08:00
if my_member && my_member . roles [ 0 ]
present :project_id , params [ :id ]
present :user_id , params [ :user_id ]
present :member_info , my_member , with : Mobile :: Entities :: ProjectMember
2016-07-25 15:20:01 +08:00
present :status , 0
2016-07-27 14:30:19 +08:00
else
present :status , - 1
2016-07-25 15:20:01 +08:00
end
end
2016-07-27 14:30:19 +08:00
desc " 修改项目某成员角色信息 "
2016-07-25 15:20:01 +08:00
params do
2016-07-27 14:30:19 +08:00
requires :id , type : Integer
2016-07-25 15:20:01 +08:00
requires :token , type : String
2016-07-27 14:30:19 +08:00
requires :user_id , type : Integer
requires :role_id , type : Integer
2016-07-25 15:20:01 +08:00
end
2016-07-27 14:30:19 +08:00
post 'edit_member_role' do
2016-07-25 15:20:01 +08:00
authenticate!
2016-07-27 14:30:19 +08:00
project = Project . find ( " #{ params [ :id ] } " )
2016-07-25 15:20:01 +08:00
2016-07-27 14:30:19 +08:00
my_member = project . member_principals . where ( " users.id= #{ current_user . id } " ) . first
2016-07-25 15:20:01 +08:00
2016-07-27 14:30:19 +08:00
#3管理 4开发 5报告
if ! ( my_member && my_member . roles [ 0 ] && my_member . roles [ 0 ] . id == 3 ) || project . user_id == params [ :user_id ] || ! ( params [ :role_id ] == 3 || params [ :role_id ] == 4 || params [ :role_id ] == 5 )
present :status , - 1
2016-07-25 15:20:01 +08:00
else
2016-07-28 14:49:45 +08:00
ps = ProjectsService . new
2016-07-27 14:30:19 +08:00
2016-07-28 14:49:45 +08:00
status = ps . modify_user_project_role params
present :status , status
2016-07-25 15:20:01 +08:00
end
end
2016-07-27 14:30:19 +08:00
desc " 新建项目 "
params do
requires :token , type : String
requires :name , type : String , desc : '项目名称'
end
post 'create' do
authenticate!
2016-07-28 14:49:45 +08:00
ps = ProjectsService . new
status = ps . createNewProject params , current_user
2016-07-27 14:30:19 +08:00
present :status , 0
end
desc " 加入项目 "
params do
requires :token , type : String
requires :invite_code , type : String , desc : '邀请码'
2016-08-02 15:50:15 +08:00
requires :role_id , type : Integer , desc : '身份'
2016-07-27 14:30:19 +08:00
end
2016-08-02 15:50:15 +08:00
post " join_project " do
2016-07-27 14:30:19 +08:00
authenticate!
2016-08-02 15:50:15 +08:00
role_id = params [ :role_id ]
2016-08-01 11:14:03 +08:00
2016-08-02 15:50:15 +08:00
if role_id != 3 && role_id != 4 && role_id != 5
{ status : - 1 , message : " 请至少选择一个角色 " }
else
ps = ProjectsService . new
status = ps . join_project ( { role : role_id , openid : params [ :openid ] , invite_code : params [ :invite_code ] } , current_user )
{ status : status , message : ProjectsService :: JoinProjectError . message ( status ) }
end
2016-07-27 14:30:19 +08:00
2016-08-01 11:14:03 +08:00
# {status:-1, message: '该功能将在近日开放,敬请期待!' }
2016-07-27 14:30:19 +08:00
end
2016-08-03 09:37:24 +08:00
desc " 项目单个未审核用户信息 "
params do
requires :token , type : String
requires :project_id , type : Integer , desc : " 项目id "
requires :user_id , type : Integer , desc : " 用户id "
end
post 'review_member_info' do
authenticate!
ps = ProjectsService . new
2016-08-04 18:09:54 +08:00
result = ps . get_reviewer_info ( params , current_user )
present :data , result [ :reviewer ] , with : Mobile :: Entities :: User
present :status , result [ :status ]
2016-08-03 09:37:24 +08:00
end
desc " 处理管理或开发的身份申请 "
params do
requires :token , type : String
requires :project_id , type : Integer , desc : " 项目id "
requires :user_id , type : Integer , desc : " 用户id "
requires :type , type : Integer , desc : " 同意或拒绝 "
end
post 'deal_join_apply' do
authenticate!
ps = ProjectsService . new
result = ps . deal_join_apply ( params , current_user )
present :status , result [ :status ]
present :message , result [ :message ]
end
2016-07-27 14:30:19 +08:00
end
2016-07-25 15:20:01 +08:00
end
end
end