79 lines
1.7 KiB
Ruby
79 lines
1.7 KiB
Ruby
class MissionsController < ApplicationController
|
|
|
|
before_action :authenticate
|
|
|
|
#获取当前项目某状态的任务列表
|
|
|
|
def getlist
|
|
#Todo
|
|
pid = params[:project_id]
|
|
stu = params[:status_type]
|
|
missions = []
|
|
Mission.where(:project_id => pid).where(:status => stu) do |i|
|
|
missions += [{
|
|
:id => i.id,
|
|
:name => i.name,
|
|
:content => i.content
|
|
}]
|
|
end
|
|
render :json => {
|
|
:code => 0,
|
|
:data => missions
|
|
}
|
|
end
|
|
|
|
#获取任务详细信息
|
|
|
|
def detail
|
|
#Todo
|
|
id = params[:id]
|
|
mission = Mission.find(id)
|
|
userid = Mission_user.find_by_name("mission_id")
|
|
username = User.find(userid).pluck("name")
|
|
comments = []
|
|
Comments.where("mission_id" => id).each do |i|
|
|
name = User.find(i.user_id).name
|
|
comments += [{
|
|
:nickname => name,
|
|
:content => i.content,
|
|
:time => i.created_at
|
|
}]
|
|
end
|
|
render :json => {
|
|
:code => 0,
|
|
:data => {
|
|
:name => mission.name,
|
|
:content => mission.content,
|
|
:priority => mission.priority,
|
|
:status => mission.status,
|
|
:deadline => mission.deadline,
|
|
:users => username,
|
|
:comments => comments
|
|
}
|
|
}
|
|
end
|
|
|
|
#修改任务信息
|
|
|
|
def update
|
|
#Todo
|
|
body = request.body.read
|
|
|
|
render :json => {:code => 0}
|
|
end
|
|
|
|
#当前用户发表评论
|
|
|
|
def commentPublish
|
|
#Todo
|
|
body = request.body.read
|
|
put = Comments.new()
|
|
put.content = body[:content]
|
|
put.mission_id = body[:mission_id]
|
|
put.user_id = session[:user_id]
|
|
put.save!
|
|
render :json => {:code => 0}
|
|
end
|
|
|
|
|
|
end |