2016-04-01 18:23:12 +08:00
|
|
|
#coding=utf-8
|
|
|
|
|
|
|
|
module Mobile
|
|
|
|
module Apis
|
|
|
|
class NewComment< Grape::API
|
|
|
|
include ApplicationHelper
|
|
|
|
include ApiHelper
|
|
|
|
resources :new_comment do
|
|
|
|
|
|
|
|
desc "add a new comment"
|
|
|
|
params do
|
|
|
|
requires :type, type: String
|
|
|
|
requires :content, type: String
|
2016-04-02 08:13:52 +08:00
|
|
|
requires :openid, type: String
|
2016-04-01 18:23:12 +08:00
|
|
|
end
|
2016-04-01 22:38:45 +08:00
|
|
|
post ':id' do
|
2016-04-01 18:23:12 +08:00
|
|
|
type = params[:type]
|
|
|
|
result = 1
|
2016-04-02 08:13:52 +08:00
|
|
|
current_user = UserWechat.find_by_openid(params[:openid]).user
|
2016-04-01 18:23:12 +08:00
|
|
|
if params[:content]!="" && current_user
|
|
|
|
case type
|
|
|
|
when "HomeworkCommon"
|
|
|
|
homework_common = HomeworkCommon.find(params[:id])
|
|
|
|
feedback = HomeworkCommon.add_homework_jour(current_user, params[:content], params[:id])
|
|
|
|
if (feedback.errors.empty?)
|
|
|
|
homework_common.update_attributes(:updated_at => Time.now)
|
2016-04-01 22:38:45 +08:00
|
|
|
data = homework_common.journals_for_messages.last
|
2016-04-01 23:22:39 +08:00
|
|
|
present :data, data, with: Mobile::Entities::Jours
|
2016-04-01 18:23:12 +08:00
|
|
|
result = 2
|
|
|
|
else
|
|
|
|
result = 3
|
|
|
|
end
|
|
|
|
when "News"
|
|
|
|
news = News.find(params[:id])
|
|
|
|
comment = Comment.new
|
|
|
|
comment.comments = params[:content]
|
|
|
|
comment.author = current_user
|
|
|
|
if news.comments << comment
|
2016-04-02 00:37:24 +08:00
|
|
|
data = comment
|
|
|
|
present :data, data, with: Mobile::Entities::Comment
|
2016-04-01 18:23:12 +08:00
|
|
|
result = 2
|
|
|
|
else
|
|
|
|
result = 3
|
|
|
|
end
|
|
|
|
when "Message"
|
|
|
|
message = Message.find(params[:id])
|
|
|
|
board = Board.find(message.board_id)
|
|
|
|
topic = message.root
|
|
|
|
reply = Message.new
|
|
|
|
reply.author = current_user
|
|
|
|
reply.board = board
|
|
|
|
reply.content = params[:content]
|
|
|
|
reply.parent_id = params[:id]
|
|
|
|
reply.subject = "RE: #{topic.subject}"
|
|
|
|
if topic.children << reply
|
2016-04-02 00:37:24 +08:00
|
|
|
data = reply
|
|
|
|
present :data, data, with: Mobile::Entities::Message
|
2016-04-01 18:23:12 +08:00
|
|
|
result = 2
|
|
|
|
else
|
|
|
|
result = 3
|
|
|
|
end
|
|
|
|
when "JournalsForMessage"
|
|
|
|
jour = JournalsForMessage.find params[:id]
|
|
|
|
parent_id = params[:id]
|
|
|
|
author_id = current_user.id
|
|
|
|
reply_user_id = jour.user_id
|
|
|
|
reply_id = params[:id]
|
|
|
|
content = params[:content]
|
|
|
|
options = {:user_id => author_id,
|
|
|
|
:status => true,
|
|
|
|
:m_parent_id => parent_id,
|
|
|
|
:m_reply_id => reply_id,
|
|
|
|
:reply_id => reply_user_id,
|
|
|
|
:notes => content,
|
|
|
|
:is_readed => false}
|
|
|
|
jfm = jour.user.add_jour(nil, nil, nil, options)
|
|
|
|
if jfm.errors.empty?
|
|
|
|
(JournalsForMessage.find parent_id).update_attribute(:updated_on,Time.now)
|
|
|
|
result = 2
|
|
|
|
else
|
|
|
|
result = 3
|
|
|
|
end
|
|
|
|
when 'Issue'
|
|
|
|
issue = Issue.find params[:id]
|
2016-04-01 21:32:33 +08:00
|
|
|
is_jour = Journal.new
|
|
|
|
is_jour.user_id = current_user.id
|
|
|
|
is_jour.notes = params[:content]
|
|
|
|
is_jour.journalized = issue
|
|
|
|
#is_jour.journalized_type = "Issue"
|
2016-04-01 23:22:39 +08:00
|
|
|
if is_jour.save
|
|
|
|
data = is_jour
|
|
|
|
present :data, data, with: Mobile::Entities::Journal
|
2016-04-01 18:23:12 +08:00
|
|
|
result = 2
|
|
|
|
else
|
|
|
|
result = 3
|
|
|
|
end
|
|
|
|
when 'BlogComment'
|
|
|
|
blog = BlogComment.find(params[:id]).root
|
|
|
|
blogComment = BlogComment.new
|
|
|
|
blogComment.author = current_user
|
|
|
|
blogComment.blog = blog.blog
|
|
|
|
blogComment.content = params[:content]
|
|
|
|
blogComment.title = "RE: #{blog.title}"
|
|
|
|
blog.children << blogComment
|
|
|
|
if blog.save
|
|
|
|
result = 2
|
|
|
|
else
|
|
|
|
result = 3
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if result == 2
|
|
|
|
update_course_activity_api(type,params[:id])
|
|
|
|
update_user_activity_api(type,params[:id])
|
|
|
|
update_org_activity_api(type,params[:id])
|
|
|
|
update_forge_activity_api(type,params[:id])
|
|
|
|
update_principal_activity_api(type,params[:id])
|
|
|
|
end
|
|
|
|
else
|
|
|
|
result = 4
|
|
|
|
end
|
2016-04-01 22:38:45 +08:00
|
|
|
present :result, result
|
2016-04-01 18:23:12 +08:00
|
|
|
present :status, 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|