分享功能完成;分享接口修改
This commit is contained in:
commit
bd58f7795c
|
@ -14,7 +14,7 @@ class MissionsController < ApplicationController
|
|||
|
||||
missions.each do |mission|
|
||||
|
||||
puts mission.inspect
|
||||
#puts mission.inspect
|
||||
|
||||
details += [{
|
||||
:id => mission.id,
|
||||
|
@ -41,19 +41,28 @@ class MissionsController < ApplicationController
|
|||
|
||||
def detail
|
||||
#Todo
|
||||
username = []
|
||||
comments_s = []
|
||||
mission_id = params[:id]
|
||||
mission = Mission.find_by(id: mission_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
|
||||
m_us = Missions_user.where("mission_id = ?",mission_id).all
|
||||
#puts m_us.inspect
|
||||
m_us.each do |m_u|
|
||||
user_id = m_u.user_id
|
||||
user = User.find_by(id: user_id)
|
||||
#puts user.inspect
|
||||
username << user.name
|
||||
end
|
||||
comments = Comment.where("mission_id = ?",mission_id).all
|
||||
comments.each do |c|
|
||||
uname = User.find_by(id: c.user_id).name
|
||||
comments_s += [{
|
||||
:nickname => uname,
|
||||
:content => c.content,
|
||||
:time => c.created_at
|
||||
}]
|
||||
end
|
||||
#puts comments_s.inspect
|
||||
render :json => {
|
||||
:code => 0,
|
||||
:data => {
|
||||
|
@ -63,41 +72,60 @@ class MissionsController < ApplicationController
|
|||
:status => mission.status,
|
||||
:deadline => mission.deadline,
|
||||
:users => username,
|
||||
:comments => comments
|
||||
:comments => comments_s
|
||||
}
|
||||
}
|
||||
end
|
||||
#======================================>创建任务
|
||||
|
||||
def create
|
||||
#Todo
|
||||
params_mission = {name: params[:name],project_id: params[:project_id],content: params[:content],deadline: params[:deadline],priority: params[:priority],status: params[:status]}
|
||||
mission = Mission.new(params_mission)
|
||||
mission.save
|
||||
#puts mission.inspect
|
||||
#puts mission.id
|
||||
usernames = params[:users]
|
||||
usernames.each do |name|
|
||||
|
||||
user_enties = User.find_by(name: name)
|
||||
#puts user_enties.inspect
|
||||
params_mu = {mission_id: mission.id,user_id: user_enties.id}
|
||||
missions_user = Missions_user.new(params_mu)
|
||||
missions_user.save
|
||||
content = "有新任务:"+mission.name
|
||||
|
||||
params_note = {content: content,user_id: user_enties.id,category: 3,project_id: mission.project_id}
|
||||
note = Note.new(params_note)
|
||||
note.save
|
||||
end
|
||||
render :json => {:code => 0}
|
||||
end
|
||||
|
||||
#======================================>修改任务信息
|
||||
|
||||
def update
|
||||
#Todo
|
||||
|
||||
id = params[:id]
|
||||
now = Datetime.now
|
||||
mission = Mission.find(id)
|
||||
mission.name = params[:name]
|
||||
mission.content = params[:content]
|
||||
mission.priority = params[:priority]
|
||||
mission.status = params[:status]
|
||||
mission.deadline = params[:deadline]
|
||||
mission.updated_at = now
|
||||
mission.save!
|
||||
pid = mission.project_id
|
||||
Mission_user.destory_all(:mission_id => id)
|
||||
params[:users].each do |i|
|
||||
uid = User.where(:email => i).id
|
||||
mu = Mission_user.new
|
||||
mu.mission_id = id
|
||||
mu.user_id = uid
|
||||
mu.save!
|
||||
note = Note.new
|
||||
note.project_id = pid
|
||||
note.user_id = uid
|
||||
note.category = 3
|
||||
note.created_at = now
|
||||
note.updated_at = now
|
||||
note.content = "任务信息发生了变化"
|
||||
note.save!
|
||||
#now = Datetime.now
|
||||
mission = Mission.find_by(id: id)
|
||||
params_mission = {name: params[:name],content: params[:content],deadline: params[:deadline],priority: params[:priority],status: params[:status]}
|
||||
#puts params_mission
|
||||
mission.update(params_mission)
|
||||
mission.save
|
||||
Missions_user.delete_all(["mission_id = ?",id])
|
||||
usernames = params[:users]
|
||||
usernames.each do |name|
|
||||
user_enties = User.find_by(name: name)
|
||||
params = {mission_id: id,user_id: user_enties.id}
|
||||
missions_user = Missions_user.new(params)
|
||||
missions_user.save
|
||||
content = mission.name + "——任务信息发生了变化"
|
||||
|
||||
params_note = {content: content,user_id: user_enties.id,category: 3,project_id: mission.project_id}
|
||||
note = Note.new(params_note)
|
||||
note.save
|
||||
end
|
||||
render :json => {:code => 0}
|
||||
end
|
||||
|
@ -106,22 +134,15 @@ class MissionsController < ApplicationController
|
|||
|
||||
def commentPublish
|
||||
#Todo
|
||||
puts "I'm in"
|
||||
content = params[:content]
|
||||
mission_id = params[:mission_id]
|
||||
content = params[:content]
|
||||
user_id = session[:user_id]
|
||||
puts user_id
|
||||
params_comment = {content: content,mission_id: mission_id,user_id: user_id}
|
||||
puts params_comment
|
||||
comment = Comments.new(params_comment)
|
||||
|
||||
# now = Datetime.now
|
||||
# put.created_at = now
|
||||
# put.updated_at = now
|
||||
comment.save!
|
||||
|
||||
params = {content: content, mission_id: mission_id, user_id: user_id}
|
||||
comment = Comment.new(params)
|
||||
comment.save
|
||||
render :json => {:code => 0}
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
|
@ -8,23 +8,24 @@ class NotesController < ApplicationController
|
|||
#Todo
|
||||
pid = params[:project_id]
|
||||
uid = session[:user_id]
|
||||
note = {}
|
||||
Note.where(:user_id => uid).where(:project_id => pid).each do |i|
|
||||
date = i.created_at.to_date.to_s
|
||||
if not note[date] then
|
||||
note[date] = []
|
||||
end
|
||||
note[:date] += [{
|
||||
:content => i.content,
|
||||
:time => i.created_at.to_time,
|
||||
:type => i.category
|
||||
}]
|
||||
notes = Note.where("user_id = ? AND project_id = ? ",uid,pid).order(:created_at).all
|
||||
note = Hash.new do |h,k|
|
||||
h[k] = []
|
||||
end
|
||||
notes.each do |n|
|
||||
date = n.created_at.to_s[/([\d\-]*)\s(.*)/,1]
|
||||
time = n.created_at.to_s[/(.*)\s([\d\:]*)/,2]
|
||||
note[date] << {
|
||||
:content => n.content,
|
||||
:time => time,
|
||||
:type => n.category
|
||||
}
|
||||
end
|
||||
data = []
|
||||
note.each do |date, list|
|
||||
note.each do |k,v|
|
||||
data += [{
|
||||
:time => date,
|
||||
:notes => list
|
||||
:time => k,
|
||||
:notes => v
|
||||
}]
|
||||
end
|
||||
render :json => {
|
||||
|
|
|
@ -8,23 +8,22 @@ class SharesController < ApplicationController
|
|||
#当前用户创建分享
|
||||
|
||||
def create
|
||||
uid = session[:user_id].to_i
|
||||
share=Share.new(share_params)
|
||||
share.user_id=uid
|
||||
if share.save
|
||||
content = User.find(uid).name + "分享了一些事"
|
||||
pid=share.project_id
|
||||
|
||||
Projects_user.where(:project_id => pid).each do |i|
|
||||
params_note = {user_id: i.user_id,content: content,category: 1,project_id: pid}
|
||||
note = Note.new(params_note)
|
||||
note.save!
|
||||
uid = session[:user_id].to_i
|
||||
share=Share.new(share_params)
|
||||
share.user_id=uid
|
||||
if share.save
|
||||
content = User.find(uid).name + "分享了一些事"
|
||||
pid=share.project_id
|
||||
|
||||
Projects_user.where(:project_id => pid).each do |i|
|
||||
params_note = {user_id: i.user_id,content: content,category: 1,project_id: pid}
|
||||
note = Note.new(params_note)
|
||||
note.save!
|
||||
end
|
||||
render status: :created, nothing: true
|
||||
else
|
||||
render json: project.errors, status: :unprocessable_entity
|
||||
end
|
||||
render status: :created, nothing: true
|
||||
else
|
||||
render json: project.errors, status: :unprocessable_entity
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
#获取项目的分享列表
|
||||
|
@ -32,6 +31,7 @@ class SharesController < ApplicationController
|
|||
def getShareList
|
||||
#Todo
|
||||
pid = params[:project_id]
|
||||
|
||||
data = []
|
||||
Share.where(:project_id => pid).order("created_at desc").each do |i|
|
||||
puts i.content
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
class Comment < ActiveRecord:: Base
|
||||
class Comment < ActiveRecord::Base
|
||||
|
||||
belongs_to :mission
|
||||
|
||||
validates :content, presence: true
|
||||
validates :mission_id, presence: true
|
||||
|
||||
validates :user_id, presence: true
|
||||
|
||||
validate :comment_has_atleast_one_character, on: :create
|
||||
validate :user_id_exist, on: :create
|
||||
|
||||
private
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
class Missions_user <ActiveRecord:: Base
|
||||
|
||||
validates :mission_id, presence: true, uniqueness: true
|
||||
validates :mission_id, presence: true
|
||||
validates :user_id, presence: true
|
||||
|
||||
validate :mission_exist, on: :create
|
||||
|
|
|
@ -2,6 +2,7 @@ class Project < ActiveRecord::Base
|
|||
has_and_belongs_to_many :users
|
||||
|
||||
validate :require_at_least_on_user,on: :update # 项目中最少要有一个用户
|
||||
|
||||
validates :name, presence: true, length: { minimum: 1, maximum: 50 }, uniqueness: true
|
||||
|
||||
private
|
||||
|
|
|
@ -73,8 +73,12 @@ Rails.application.routes.draw do
|
|||
delete 'projects/users' => 'projects#deleteUsers'
|
||||
get 'projects/detail' => 'projects#detail'
|
||||
|
||||
get 'notes/list' => 'notes#getNotesList'
|
||||
|
||||
get 'missions/project/status' => 'missions#getlist'
|
||||
get 'missions/detail' => 'missions#detail'
|
||||
patch 'missions/detail' => 'missions#update'
|
||||
post 'missions/comments' => 'missions#commentPublish'
|
||||
post 'missions/create' => 'missions#create'
|
||||
patch 'missions/detail' => 'missions#update'
|
||||
|
||||
end
|
||||
|
|
|
@ -2,62 +2,14 @@ require 'rails_helper'
|
|||
|
||||
RSpec.describe MissionsController, type: :controller do
|
||||
|
||||
# describe "GET #getlist" do
|
||||
describe "GET #getlist" do
|
||||
|
||||
# it "return a valid json format of missions" do
|
||||
it "return a valid json format of missions" do
|
||||
|
||||
# register = create(:user)
|
||||
# user = User.find_by(email: register.email)
|
||||
# session[:user_id] = user.id
|
||||
|
||||
# user1 = create(:user)
|
||||
# user2 = create(:user)
|
||||
# params = {name: "project addUsers test",content: "addUsers test"}
|
||||
# project = Project.new(params)
|
||||
# project.users << register
|
||||
# project.save
|
||||
|
||||
# params_mission = {name: "mission1",content: "mission content",deadline:"2016-10-17 10:00:00",priority:1,status:1,project_id: project.id}
|
||||
# params_mission2 = {name: "mission2",content: "mission content2",deadline:"2016-10-17 10:00:00",priority:1,status:2,project_id: project.id}
|
||||
# mission = Mission.new(params_mission)
|
||||
# mission2 = Mission.new(params_mission2)
|
||||
# mission.save
|
||||
# mission2.save
|
||||
# get :getlist,project_id: project.id,status_type: 1
|
||||
|
||||
# puts response.body
|
||||
|
||||
|
||||
# end
|
||||
|
||||
# end
|
||||
|
||||
# describe "GET #detail" do
|
||||
|
||||
# it "return a correct json format detail" do
|
||||
|
||||
# register = create(:user)
|
||||
# params = {name: "project addUsers test",content: "addUsers test"}
|
||||
# project = Project.new(params)
|
||||
# project.users << register
|
||||
# project.save
|
||||
|
||||
# params_mission = {name: "mission1",content: "mission content",deadline:"2016-10-17 10:00:00",priority:1,status:1,project_id: project.id}
|
||||
# params_mission2 = {name: "mission2",content: "mission content2",deadline:"2016-10-17 10:00:00",priority:1,status:2,project_id: project.id}
|
||||
# mission = Mission.new(params_mission)
|
||||
# mission.save
|
||||
# get :detail,id: mission.id
|
||||
|
||||
# end
|
||||
|
||||
# end
|
||||
|
||||
describe "POST #comments" do
|
||||
|
||||
it "can publish comments successfully" do
|
||||
|
||||
|
||||
register = create(:user)
|
||||
user = User.find_by(email: register.email)
|
||||
session[:user_id] = user.id
|
||||
|
||||
params = {name: "project addUsers test",content: "addUsers test"}
|
||||
project = Project.new(params)
|
||||
project.users << register
|
||||
|
@ -66,14 +18,133 @@ RSpec.describe MissionsController, type: :controller do
|
|||
params_mission = {name: "mission1",content: "mission content",deadline:"2016-10-17 10:00:00",priority:1,status:1,project_id: project.id}
|
||||
params_mission2 = {name: "mission2",content: "mission content2",deadline:"2016-10-17 10:00:00",priority:1,status:2,project_id: project.id}
|
||||
mission = Mission.new(params_mission)
|
||||
mission2 = Mission.new(params_mission2)
|
||||
mission.save
|
||||
mission2.save
|
||||
get :getlist,project_id: project.id,status_type: 1
|
||||
|
||||
puts response.body
|
||||
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "GET #detail" do
|
||||
|
||||
it "return a correct json format detail" do
|
||||
|
||||
register = create(:user)
|
||||
session[:user_id] = register.id
|
||||
params = {name: "project addUsers test",content: "addUsers test"}
|
||||
project = Project.new(params)
|
||||
project.users << register
|
||||
project.save
|
||||
|
||||
params_mission = {name: "mission1",content: "mission content",deadline:"2016-10-17 10:00:00",priority:1,status:1,project_id: project.id}
|
||||
#params_mission2 = {name: "mission2",content: "mission content2",deadline:"2016-10-17 10:00:00",priority:1,status:2,project_id: project.id}
|
||||
mission = Mission.new(params_mission)
|
||||
mission.save
|
||||
|
||||
post :comments , mission_id: mission.id,content: "用户评论"
|
||||
post :commentPublish,content: "评论1",mission_id: mission.id
|
||||
post :commentPublish,content: "评论2",mission_id: mission.id
|
||||
|
||||
get :detail,id: mission.id
|
||||
|
||||
puts "hello world"
|
||||
puts response.body
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "POST #comments" do
|
||||
|
||||
it "can publish comments successfully" do
|
||||
|
||||
|
||||
register = create(:user)
|
||||
params = {name: "project addUsers test",content: "addUsers test"}
|
||||
session[:user_id] = register.id
|
||||
project = Project.new(params)
|
||||
project.users << register
|
||||
project.save
|
||||
|
||||
params_mission = {name: "mission1",content: "mission content",deadline:"2016-10-17 10:00:00",priority:1,status:1,project_id: project.id}
|
||||
mission = Mission.new(params_mission)
|
||||
mission.save
|
||||
|
||||
post :commentPublish,mission_id: mission.id,content: "asda"
|
||||
|
||||
puts response.body
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
describe "POST #update" do
|
||||
|
||||
it "can update missions successfully" do
|
||||
|
||||
register = create(:user)
|
||||
user = User.find_by(email: register.email)
|
||||
session[:user_id] = user.id
|
||||
|
||||
params = {name: "project mission update test",content: "update test"}
|
||||
project = Project.new(params)
|
||||
project.users << register
|
||||
project.save
|
||||
|
||||
user1 = create(:user,name: "yangzhao")
|
||||
user2 = create(:user,name: "chenyi")
|
||||
|
||||
user3 = create(:user,name: "yangzhao")
|
||||
user4 = create(:user,name: "chenyi")
|
||||
|
||||
puts user1.inspect
|
||||
params_mission = {name: "mission1",content: "mission content",deadline:"2016-10-17 10:00:00",priority:1,status:1,project_id: project.id}
|
||||
mission = Mission.new(params_mission)
|
||||
mission.save
|
||||
|
||||
post :create,project_id: project.id,name: "前端原型开发",content:"开发出前端原型",priority:1,status:1,deadline:"2017-01-02 14:14:54",users: [user1.name,user2.name]
|
||||
|
||||
patch :update,name: "前端原型开发",id: mission.id,content:"完善前端原型",priority:1,status:1,deadline:"2017-01-03 14:14:54",users: [user3.name,user4.name]
|
||||
|
||||
post :detail,id: 1
|
||||
puts response.body
|
||||
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
describe "POST #create" do
|
||||
|
||||
it "can create missions successfully" do
|
||||
|
||||
register = create(:user)
|
||||
user = User.find_by(email: register.email)
|
||||
session[:user_id] = user.id
|
||||
|
||||
params = {name: "project mission update test",content: "update test"}
|
||||
project = Project.new(params)
|
||||
project.users << register
|
||||
project.save
|
||||
|
||||
user1 = create(:user)
|
||||
user2 = create(:user)
|
||||
project.users << user1
|
||||
project.users << user2
|
||||
#params_mission = {name: "mission1",content: "mission content",deadline:"2016-10-17 10:00:00",priority:1,status:1,project_id: project.id}
|
||||
|
||||
post :create,project_id: project.id,name: "前端原型开发",content:"开发出前端原型",priority:1,status:1,deadline:"2017-01-02 10:00:00",users: [user1.name,user2.name]
|
||||
|
||||
post :detail,id: 1
|
||||
|
||||
puts response.body
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
|
@ -0,0 +1,34 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe NotesController,type: :controller do
|
||||
|
||||
describe "GET #getNotesList" do
|
||||
|
||||
it "return correct json format of noteslist" do
|
||||
|
||||
register = create(:user)
|
||||
user = User.find_by(email: register.email)
|
||||
session[:user_id] = user.id
|
||||
|
||||
params = {name: "project mission update test",content: "update test"}
|
||||
project = Project.new(params)
|
||||
project.users << register
|
||||
project.save
|
||||
|
||||
params_note = {content: "note content 1",user_id: user.id,category: 2,project_id: project.id}
|
||||
note = Note.new(params_note)
|
||||
note.save
|
||||
|
||||
params_note2 = {content: "note content 2",user_id: user.id,category: 1,project_id: project.id}
|
||||
note2 = Note.new(params_note2)
|
||||
note2.save
|
||||
|
||||
|
||||
post :getNotesList,project_id: project.id
|
||||
puts response.body
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe SharesController,type: :controller do
|
||||
|
||||
describe "POST #create" do
|
||||
|
||||
it "create a correct share" do
|
||||
|
||||
register = create(:user)
|
||||
user = User.find_by(email: register.email)
|
||||
session[:user_id] = user.id
|
||||
|
||||
params = {name: "project addUsers test",content: "addUsers test"}
|
||||
project = Project.new(params)
|
||||
project.users << register
|
||||
project.save
|
||||
|
||||
post :create,project_id: project.id,content: "苟利国家生死以,岂因福祸避趋之"
|
||||
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "GET #getShareList" do
|
||||
|
||||
it "return correct share list" do
|
||||
|
||||
|
||||
register = create(:user)
|
||||
user = User.find_by(email: register.email)
|
||||
session[:user_id] = user.id
|
||||
|
||||
params = {name: "project test",content: " test"}
|
||||
project = Project.new(params)
|
||||
project.users << register
|
||||
project.save
|
||||
|
||||
post :create,project_id: project.id,content: "苟利国家生死以,岂因福祸避趋之"
|
||||
|
||||
post :create,project_id: project.id,content: "too young too simple"
|
||||
|
||||
post :create,project_id: project.id,content: "too young too naive"
|
||||
|
||||
|
||||
get :getShareList,project_id: project.id
|
||||
|
||||
puts response.body
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
Loading…
Reference in New Issue