Commit 0c55dfcf by David Ormsbee

Merge pull request #25 from rll/feature/kevin/pinning

Feature/kevin/pinning
parents 0769389d a071e152
put "#{APIPREFIX}/threads/:thread_id/pin" do |thread_id|
pin thread
end
put "#{APIPREFIX}/threads/:thread_id/unpin" do |thread_id|
unpin thread
end
......@@ -60,6 +60,7 @@ require './api/comment_threads'
require './api/comments'
require './api/users'
require './api/votes'
require './api/pins'
require './api/notifications_and_subscriptions'
if RACK_ENV.to_s == "development"
......
......@@ -43,6 +43,22 @@ helpers do
obj.reload.to_hash.to_json
end
def pin(obj)
raise ArgumentError, "User id is required" unless user
obj.pinned = true
obj.save
obj.reload.to_hash.to_json
end
def unpin(obj)
raise ArgumentError, "User id is required" unless user
obj.pinned = nil
obj.save
obj.reload.to_hash.to_json
end
def value_to_boolean(value)
!!(value.to_s =~ /^true$/i)
end
......@@ -111,6 +127,7 @@ helpers do
else
page = (params["page"] || DEFAULT_PAGE).to_i
per_page = (params["per_page"] || DEFAULT_PER_PAGE).to_i
#KChugh turns out we don't need to go through all the extra work on the back end because the client is resorting anyway
comment_threads = comment_threads.order_by("#{sort_key} #{sort_order}") if sort_key && sort_order
num_pages = [1, (comment_threads.count / per_page.to_f).ceil].max
page = [num_pages, [1, page].max].min
......
......@@ -22,6 +22,7 @@ class CommentThread < Content
field :at_position_list, type: Array, default: []
field :last_activity_at, type: Time
field :group_id, type: Integer
field :pinned, type: Boolean
index({author_id: 1, course_id: 1})
......@@ -44,6 +45,7 @@ class CommentThread < Content
indexes :commentable_id, type: :string, index: :not_analyzed, included_in_all: false
indexes :author_id, type: :string, as: 'author_id', index: :not_analyzed, included_in_all: false
indexes :group_id, type: :integer, as: 'group_id', index: :not_analyzed, included_in_all: false
#indexes :pinned, type: :boolean, as: 'pinned', index: :not_analyzed, included_in_all: false
end
belongs_to :author, class_name: "User", inverse_of: :comment_threads, index: true#, autosave: true
......@@ -176,6 +178,7 @@ class CommentThread < Content
"tags" => tags_array,
"type" => "thread",
"group_id" => group_id,
"pinned" => pinned?,
"endorsed" => endorsed?)
if params[:recursive]
......
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