socialforge/app/api/mobile/apis/comments.rb

133 lines
5.0 KiB
Ruby
Raw Normal View History

#coding=utf-8
module Mobile
module Apis
class Comments < Grape::API
2015-03-19 14:41:31 +08:00
include ApplicationHelper
resource :comments do
desc '课程通知评论'
params do
requires :token, type: String
2015-02-04 14:39:46 +08:00
requires :comments, type: String
end
post ':id' do
cs = CommentService.new
2015-02-04 14:39:46 +08:00
cs_params = {
id: params[:id],
comment: params.reject{|k,v| [:id].include?(k)}}
comments = cs.news_comments cs_params,current_user
raise "create comments failed #{comments.errors.full_messages}" if comments.new_record?
present :data, comments, with: Mobile::Entities::Comment
present :status, 0
end
desc '作业留言(教师布置的作业)'
params do
requires :token, type: String
requires :message,type: String, desc: '留言'
2015-02-05 16:11:35 +08:00
#optional :reference_content, type: String ,desc: '引用的内容'
#optional :reference_user_id, type: Integer,desc: '被引用的人'
end
2015-02-05 16:11:35 +08:00
post ':id/create_homework_message' do
cs_params = {
id: params[:id],
token: params[:token],
reference_content: params[:reference_content],
bid_message: params.reject{|k,v| [:id,:token,:reference_content].include?(k)}}
cs = CommentService.new
2015-02-05 16:11:35 +08:00
message = cs.homework_message cs_params,current_user
present :data, message, with: Mobile::Entities::Jours
present :status, 0
end
2015-02-06 10:35:38 +08:00
desc '课程留言'
params do
requires :token, type: String
requires :course_message,type: String, desc: '留言'
end
post ':id/leave_course_message' do
cs_params = {
id: params[:id],
token: params[:token],
new_form: params.reject{|k,v| [:id,:token].include?(k)}}
cs = CommentService.new
message = cs.leave_course_message cs_params,current_user
present :data, message, with: Mobile::Entities::Jours
present :status, 0
end
desc '回复留言'
params do
requires :token, type: String
requires :reference_id, type: Integer,desc: '所属留言树的根留言id最顶层的非回复的留言,留言对象中的m_parent_id'
requires :reference_user_id,type: Integer ,desc: '被回复的留言的作者id'
#requires :reference_message_id,type: Integer,desc: '被回复的留言的id'
requires :user_notes,type: String,desc: '留言的内容'
requires :jour_type,type: String,desc: '等于父留言的jour_type'
requires :jour_id,type:Integer, desc: '等于父留言的jour_id'
end
post ':reference_message_id/create_reply'do
cs = CommentService.new
message = cs.create_reply params,current_user
raise "create reply failed #{message.errors.full_messages}" if message.new_record?
present :data, message, with: Mobile::Entities::Jours
present :status, 0
end
2015-03-05 10:09:19 +08:00
desc ' 意见反馈'
params do
requires :token, type: String
requires :subject,type: String,desc: '意见'
end
post do
cs_params = {
2015-04-11 15:52:48 +08:00
memo: {:subject => '该贴来自手机App意见反馈' ,:content => params[:subject]},
2015-03-05 10:09:19 +08:00
}
cs = CommentService.new
2015-03-19 14:41:31 +08:00
memo,message = cs.create_feedback cs_params, current_user
raise message if memo.new_record?
2015-03-05 10:09:19 +08:00
present :status, 0
end
2015-03-07 16:19:55 +08:00
desc '课程留言列表'
params do
optional :token, type: String
2015-05-29 14:22:43 +08:00
optional :page,type:Integer,desc:'页数'
2015-03-07 16:19:55 +08:00
end
get ':id/course_message' do
cs = CommentService.new
jours = cs.course_messages params,(current_user.nil? ? User.find(2):current_user)
present :data, jours, with: Mobile::Entities::Jours
present :status, 0
end
desc '留言详情'
params do
requires :token, type: String
requires :comment_parent_id,type:Integer,desc:'留言id'
optional :course_id,type:Integer,desc:'课程id'
end
get ':comment_parent_id/comment_details' do
cs = CommentService.new
jour = cs.comment_detail params,current_user
present :data, jour, with: Mobile::Entities::Jours
present :status, 0
end
desc '通知评论列表'
params do
2016-04-01 18:23:12 +08:00
#requires :token, type: String
requires :notice_id,type:Integer,desc:'通知id'
optional :page,type:Integer,desc:'页码'
end
get ':notice_id/notice_comments' do
cs = CommentService.new
comments = cs.notice_comments params,current_user
present :data, comments, with: Mobile::Entities::Comment
present :status, 0
end
end
end
end
end