Commit bc407596 by Rocky Duan

changed comment_thread to thread & removed commentable in url

parent 83989fc2
......@@ -21,68 +21,67 @@ Dir[File.dirname(__FILE__) + '/models/*.rb'].each {|file| require file}
# DELETE /api/v1/commentables/:commentable_type/:commentable_id
# delete the commentable object and all of its associated comment threads and comments
delete '/api/v1/commentables/:commentable_type/:commentable_id' do |commentable_type, commentable_id|
delete '/api/v1/:commentable_type/:commentable_id/comments' do |commentable_type, commentable_id|
commentable = Commentable.find_or_initialize_by(commentable_type: commentable_type, commentable_id: commentable_id)
commentable.destroy
commentable.to_hash.to_json
end
# GET /api/v1/commentables/:commentable_type/:commentable_id/comment_threads
# GET /api/v1/commentables/:commentable_type/:commentable_id/threads
# get all comment threads associated with a commentable object
# additional parameters accepted: recursive
get '/api/v1/commentables/:commentable_type/:commentable_id/comment_threads' do |commentable_type, commentable_id|
get '/api/v1/:commentable_type/:commentable_id/threads' do |commentable_type, commentable_id|
commentable = Commentable.find_or_create_by(commentable_type: commentable_type, commentable_id: commentable_id)
commentable.comment_threads.map{|t| t.to_hash(recursive: params["recursive"])}.to_json
end
# POST /api/v1/commentables/:commentable_type/:commentable_id/comment_threads
# POST /api/v1/commentables/:commentable_type/:commentable_id/threads
# create a new comment thread for the commentable object
post '/api/v1/commentables/:commentable_type/:commentable_id/comment_threads' do |commentable_type, commentable_id|
post '/api/v1/:commentable_type/:commentable_id/threads' do |commentable_type, commentable_id|
commentable = Commentable.find_or_create_by(commentable_type: commentable_type, commentable_id: commentable_id)
comment_thread = commentable.comment_threads.new(params.slice(*%w[title body course_id]))
comment_thread.author = User.find_or_create_by(external_id: params["user_id"]) if params["user_id"]
comment_thread.save!
comment_thread.to_hash.to_json
thread = commentable.comment_threads.new(params.slice(*%w[title body course_id]))
thread.author = User.find_or_create_by(external_id: params["user_id"]) if params["user_id"]
thread.save!
thread.to_hash.to_json
end
# GET /api/v1/comment_threads/:comment_thread_id
# GET /api/v1/threads/:thread_id
# get information of a single comment thread
# additional parameters accepted: recursive
get '/api/v1/comment_threads/:comment_thread_id' do |comment_thread_id|
comment_thread = CommentThread.find(comment_thread_id)
comment_thread.to_hash(recursive: params["recursive"]).to_json
get '/api/v1/threads/:thread_id' do |thread_id|
thread = CommentThread.find(thread_id)
thread.to_hash(recursive: params["recursive"]).to_json
end
# PUT /api/v1/comment_threads/:comment_thread_id
# PUT /api/v1/threads/:thread_id
# update information of comment thread
put '/api/v1/comment_threads/:comment_thread_id' do |comment_thread_id|
comment_thread = CommentThread.find(comment_thread_id)
comment_thread.update_attributes!(params.slice(*%w[title body]))
comment_thread.to_hash.to_json
put '/api/v1/threads/:thread_id' do |thread_id|
thread = CommentThread.find(thread_id)
thread.update_attributes!(params.slice(*%w[title body]))
thread.to_hash.to_json
end
# POST /api/v1/comment_threads/:comment_thread_id/comments
# POST /api/v1/threads/:thread_id/comments
# create a comment to the comment thread
post '/api/v1/comment_threads/:comment_thread_id/comments' do |comment_thread_id|
comment_thread = CommentThread.find(comment_thread_id)
comment = comment_thread.comments.new(params.slice(*%w[body course_id]))
post '/api/v1/threads/:thread_id/comments' do |thread_id|
thread = CommentThread.find(thread_id)
comment = thread.comments.new(params.slice(*%w[body course_id]))
comment.author = User.find_or_create_by(external_id: params["user_id"]) if params["user_id"]
comment.save!
comment.to_hash.to_json
end
# DELETE /api/v1/comment_threads/:comment_thread_id
# DELETE /api/v1/threads/:thread_id
# delete the comment thread and its comments
delete '/api/v1/comment_threads/:comment_thread_id' do |comment_thread_id|
comment_thread = CommentThread.find(comment_thread_id)
comment_thread.destroy
comment_thread.to_hash.to_json
delete '/api/v1/threads/:thread_id' do |thread_id|
thread = CommentThread.find(thread_id)
thread.destroy
thread.to_hash.to_json
end
# GET /api/v1/comments/:comment_id
......@@ -143,24 +142,24 @@ delete '/api/v1/votes/comments/:comment_id/users/:user_id' do |comment_id, user_
Comment.find(comment_id).to_hash.to_json
end
# PUT /api/v1/votes/comment_threads/:comment_thread_id/users/:user_id
# PUT /api/v1/votes/threads/:thread_id/users/:user_id
# create or update the vote on the comment thread
put '/api/v1/votes/comment_threads/:comment_thread_id/users/:user_id' do |comment_thread_id, user_id|
comment_thread = CommentThread.find(comment_thread_id)
put '/api/v1/votes/threads/:thread_id/users/:user_id' do |thread_id, user_id|
thread = CommentThread.find(thread_id)
user = User.find_or_create_by(external_id: user_id)
user.vote(comment_thread, params["value"].intern)
CommentThread.find(comment_thread_id).to_hash.to_json
user.vote(thread, params["value"].intern)
CommentThread.find(thread_id).to_hash.to_json
end
# DELETE /api/v1/votes/comment_threads/:comment_thread_id/users/:user_id
# DELETE /api/v1/votes/threads/:thread_id/users/:user_id
# unvote on the comment thread
delete '/api/v1/votes/comment_threads/:comment_thread_id/users/:user_id' do |comment_thread_id, user_id|
comment_thread = CommentThread.find(comment_thread_id)
delete '/api/v1/votes/threads/:thread_id/users/:user_id' do |thread_id, user_id|
thread = CommentThread.find(thread_id)
user = User.find_or_create_by(external_id: user_id)
user.unvote(comment_thread)
CommentThread.find(comment_thread_id).to_hash.to_json
user.unvote(thread)
CommentThread.find(thread_id).to_hash.to_json
end
# GET /api/v1/users/:user_id/feeds
......@@ -213,23 +212,23 @@ post '/api/v1/users/:user_id/unwatch/commentable' do |user_id|
user.to_hash.to_json
end
# POST /api/v1/users/:user_id/watch/comment_thread
# POST /api/v1/users/:user_id/watch/thread
# watch a comment thread
post '/api/v1/users/:user_id/watch/comment_thread' do |user_id|
post '/api/v1/users/:user_id/watch/thread' do |user_id|
user = User.find_or_create_by(external_id: user_id)
comment_thread = CommentThread.find(params["comment_thread_id"])
user.watch_comment_thread(comment_thread)
thread = CommentThread.find(params["thread_id"])
user.watch_comment_thread(thread)
user.to_hash.to_json
end
# POST /api/v1/users/:user_id/unwatch/comment_thread
# POST /api/v1/users/:user_id/unwatch/thread
# unwatch a comment thread
post '/api/v1/users/:user_id/unwatch/comment_thread' do |user_id|
post '/api/v1/users/:user_id/unwatch/thread' do |user_id|
user = User.find_or_create_by(external_id: user_id)
comment_thread = CommentThread.find(params["comment_thread_id"])
user.unwatch_comment_thread(comment_thread)
thread = CommentThread.find(params["thread_id"])
user.unwatch_comment_thread(thread)
user.to_hash.to_json
end
......
......@@ -58,8 +58,8 @@ private
feed = Feed.new(
feed_type: "post_reply",
info: {
comment_thread_id: get_comment_thread.id,
comment_thread_title: get_comment_thread.title,
thread_id: get_comment_thread.id,
thread_title: get_comment_thread.title,
comment_id: id,
},
)
......
......@@ -41,8 +41,8 @@ private
info: {
commentable_id: commentable.commentable_id,
commentable_type: commentable.commentable_type,
comment_thread_id: id,
comment_thread_title: title,
thread_id: id,
thread_title: title,
},
)
feed.actor = author
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment