Commit 07febd58 by Rocky Duan

add user info api; fix comparison bug

parent 31a04cee
......@@ -174,16 +174,15 @@ namespace :db do
users = (1..10).map {|id| User.find_or_create_by(external_id: id.to_s)}
3.times do
users.first.subscribe(users.sample)
end
10.times do
users.sample.subscribe(users.sample)
end
generate_comments_for("question_1")
generate_comments_for("question_2")
generate_comments_for("course_1")
generate_comments_for("lecture_1")
generate_comments_for("video_1")
generate_comments_for("video_2")
generate_comments_for("lab_1")
generate_comments_for("lab_2")
......@@ -231,6 +230,32 @@ namespace :sunspot do
puts "Successfully stopped Solr ..."
end
desc 'Restart the Solr instance'
task :restart => :environment do
case RUBY_PLATFORM
when /w(in)?32$/, /java$/
abort("This command is not supported on #{RUBY_PLATFORM}. " +
"Use rake sunspot:solr:run to run Solr in the foreground.")
end
Sunspot::Solr::Server.new.stop
Sunspot::Solr::Server.new.start
puts "Successfully restarted Solr ..."
end
end
end
namespace :jobs do
desc "Clear the delayed_job queue."
task :clear => :environment do
Delayed::Job.delete_all
end
desc "Start a delayed_job worker."
task :work => :environment do
Delayed::Worker.new(:min_priority => ENV['MIN_PRIORITY'], :max_priority => ENV['MAX_PRIORITY'], :queues => (ENV['QUEUES'] || ENV['QUEUE'] || '').split(','), :quiet => false).start
end
end
......@@ -115,6 +115,11 @@ delete '/api/v1/threads/:thread_id/votes' do |thread_id|
undo_vote_for thread
end
get '/api/v1/users/:user_id' do |user_id|
user = User.find_or_create_by(external_id: user_id)
user.to_hash(complete: params["complete"]).to_json
end
get '/api/v1/users/:user_id/notifications' do |user_id|
user = User.find_or_create_by(external_id: user_id)
user.notifications.map(&:to_hash).to_json
......
......@@ -2,6 +2,7 @@ class NilClass
def to_hash
{}
end
def destroy
end
end
......@@ -30,7 +30,7 @@ class Comment < Content
def to_hash(params={})
sort_by_parent_and_time = Proc.new do |x, y|
arr_cmp = x.parent_ids <=> y.parent_ids
arr_cmp = x.parent_ids.map(&:to_s) <=> y.parent_ids.map(&:to_s)
if arr_cmp != 0
arr_cmp
else
......@@ -57,6 +57,7 @@ private
thread_id: comment_thread.id,
thread_title: comment_thread.title,
comment_id: id,
commentable_id: comment_thread.commentable_id,
},
)
notification.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