return comment after voting
This commit is contained in:
Родитель
bfb43459f9
Коммит
035d6f4c32
15
Rakefile
15
Rakefile
|
@ -27,8 +27,9 @@ namespace :db do
|
|||
Vote.delete_all
|
||||
User.delete_all
|
||||
level_limit = YAML.load_file("config/application.yml")["level_limit"]
|
||||
(1..3).each do |question_id|
|
||||
comment_thread = CommentThread.create! :commentable_type => "questions", :commentable_id => question_id
|
||||
|
||||
def generate_comments(commentable_type, commentable_id, level_limit)
|
||||
comment_thread = CommentThread.create! :commentable_type => commentable_type, :commentable_id => commentable_id
|
||||
5.times do
|
||||
comment_thread.root_comments.create :body => "top comment", :title => "top #{rand(10)}", :user_id => 1, :course_id => 1, :comment_thread_id => comment_thread.id
|
||||
end
|
||||
|
@ -37,6 +38,15 @@ namespace :db do
|
|||
comment.children.create :body => "comment body", :title => "comment title #{rand(50)}", :user_id => 1, :course_id => 1, :comment_thread_id => comment_thread.id
|
||||
end
|
||||
end
|
||||
|
||||
generate_comments("questions" , 1, level_limit)
|
||||
generate_comments("questions" , 2, level_limit)
|
||||
generate_comments("questions" , 3, level_limit)
|
||||
generate_comments("courses" , 1, level_limit)
|
||||
generate_comments("lectures" , 1, level_limit)
|
||||
generate_comments("lectures" , 2, level_limit)
|
||||
generate_comments("lectures" , 3, level_limit)
|
||||
|
||||
Comment.all.reject{|c| c.is_root?}.each do |c|
|
||||
(1..20).each do |id|
|
||||
user = User.find_or_create_by_id(id)
|
||||
|
@ -44,4 +54,5 @@ namespace :db do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
5
app.rb
5
app.rb
|
@ -69,7 +69,6 @@ end
|
|||
|
||||
# get the information of a single comment
|
||||
get '/api/v1/comments/:comment_id' do |comment_id|
|
||||
puts params
|
||||
comment = Comment.find_by_id(comment_id)
|
||||
if comment.nil? or comment.is_root?
|
||||
error 400, {:error => "invalid comment id"}.to_json
|
||||
|
@ -124,7 +123,7 @@ put '/api/v1/votes/comments/:comment_id/users/:user_id' do |comment_id, user_id|
|
|||
if %w[up down].include? params["value"]
|
||||
user = User.find_or_create_by_id(user_id)
|
||||
vote = user.vote(comment, { :direction => (params["value"] == "up" ? :up : :down ), :exclusive => :true})
|
||||
vote.to_json
|
||||
comment.to_json
|
||||
else
|
||||
error 400, {:error => "value must be up or down"}.to_json
|
||||
end
|
||||
|
@ -138,7 +137,7 @@ delete '/api/v1/votes/comments/:comment_id/users/:user_id' do |comment_id, user_
|
|||
comment = Comment.find_by_id(comment_id)
|
||||
if user and comment and not comment.is_root?
|
||||
vote = user.unvote_for(comment)
|
||||
vote.to_json
|
||||
comment.to_json
|
||||
else
|
||||
error 400, {:error => "invalid user or comment id"}.to_json
|
||||
end
|
||||
|
|
Загрузка…
Ссылка в новой задаче