Commit 4aebb3a2 by Ibrahim Awwal

Add default_sort_key field to users.

parent 1e4f86a4
...@@ -48,7 +48,7 @@ put "#{APIPREFIX}/users/:user_id" do |user_id| ...@@ -48,7 +48,7 @@ put "#{APIPREFIX}/users/:user_id" do |user_id|
if not user if not user
user = User.new(external_id: user_id) user = User.new(external_id: user_id)
end end
user.update_attributes(params.slice(*%w[username email])) user.update_attributes(params.slice(*%w[username email default_sort_key]))
if user.errors.any? if user.errors.any?
error 400, user.errors.full_messages.to_json error 400, user.errors.full_messages.to_json
else else
......
...@@ -6,6 +6,7 @@ class User ...@@ -6,6 +6,7 @@ class User
field :external_id, type: String field :external_id, type: String
field :username, type: String field :username, type: String
field :email, type: String field :email, type: String
field :default_sort_key, type: String, default: "date"
has_many :comments, inverse_of: :author has_many :comments, inverse_of: :author
has_many :comment_threads, inverse_of: :author has_many :comment_threads, inverse_of: :author
...@@ -62,7 +63,8 @@ class User ...@@ -62,7 +63,8 @@ class User
"follower_ids" => subscriptions_as_source.map(&:subscriber_id), "follower_ids" => subscriptions_as_source.map(&:subscriber_id),
"id" => id, "id" => id,
"upvoted_ids" => upvoted_ids, "upvoted_ids" => upvoted_ids,
"downvoted_ids" => downvoted_ids) "downvoted_ids" => downvoted_ids,
"default_sort_key" => default_sort_key)
end end
if params[:course_id] if params[:course_id]
hash = hash.merge("threads_count" => comment_threads.where(course_id: params[:course_id]).count, hash = hash.merge("threads_count" => comment_threads.where(course_id: params[:course_id]).count,
......
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