-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: added API to get subscribers of a thread. #415
Changes from 3 commits
1ac14a1
1dd23fa
aa6c814
76f1c08
bb4dfdf
5c447b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
|
||
get "#{APIPREFIX}/users/:user_id/subscribed_threads" do |user_id| | ||
handle_threads_query( | ||
user.subscribed_threads.where({"course_id" => params[:course_id]}), | ||
user.subscribed_threads.where({ "course_id" => params[:course_id] }), | ||
params["user_id"], | ||
params["course_id"], | ||
get_group_ids_from_params(params), | ||
|
@@ -28,3 +28,26 @@ | |
delete "#{APIPREFIX}/users/:user_id/subscriptions" do |user_id| | ||
user.unsubscribe(source).to_hash.to_json | ||
end | ||
|
||
get "#{APIPREFIX}/subscriptions/:thread_id" do |thread_id| | ||
page = (params['page'] || DEFAULT_PAGE).to_i | ||
per_page = (params['per_page'] || DEFAULT_PER_PAGE).to_i | ||
|
||
# Build a query hash based on the query parameters | ||
query = {} | ||
query[:subscriber_id] = params[:subscriber_id] if params[:subscriber_id] | ||
query[:source_id] = thread_id | ||
query[:source_type] = params[:source_type] if params[:source_type] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we only need the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added subscriber_id and source type to provide filtering of all available attributes. They are not used yet There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From what I understand, here the source type should always be that of a thread, otherwise this will be a general purpose API for subscriptions, but this seems to be focussed on threads.
AhtishamShahid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
subscriptions = Subscription.where(query).paginate(:page => page, :per_page => per_page) | ||
subscriptions_count = subscriptions.total_entries | ||
|
||
content_type :json | ||
|
||
{ | ||
collection: subscriptions.map(&:to_hash), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need to return the whole There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. subscription object has only 4 attributes, so I guess we can return all without taking any performance hit. |
||
num_pages: [1, (subscriptions_count / per_page.to_f).ceil].max, | ||
page: page, | ||
subscriptions_count: subscriptions_count | ||
}.to_json | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to follow the pattern above and put this under threads.
i.e.
That way it is not ambiguous what we are managing. As mentioned elsewhere, if in the future we need subscriptions for a different resource, it will be hard to disambiguate between the ids.