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