Skip to content
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

Merged
merged 6 commits into from
Oct 2, 2023

Conversation

AhtishamShahid
Copy link
Contributor

Ticket

https://2u-internal.atlassian.net/browse/INF-943

added subscribers in thread object

@AhtishamShahid AhtishamShahid marked this pull request as draft August 4, 2023 10:54
@codecov
Copy link

codecov bot commented Aug 4, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (57a95ff) 96.10% compared to head (1fc8112) 96.14%.

❗ Current head 1fc8112 differs from pull request most recent head 5c447b0. Consider uploading reports for the commit 5c447b0 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #415      +/-   ##
==========================================
+ Coverage   96.10%   96.14%   +0.04%     
==========================================
  Files          58       58              
  Lines        4514     4562      +48     
==========================================
+ Hits         4338     4386      +48     
  Misses        176      176              
Files Coverage Δ
api/notifications_and_subscriptions.rb 94.73% <100.00%> (+7.23%) ⬆️
spec/api/notifications_and_subscriptions_spec.rb 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines 38 to 40
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]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we only need the source_id, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

Copy link
Contributor

Choose a reason for hiding this comment

The 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.
If that is the case, you should only have a one subscription between one use and thread, so specifying a subscriber_id might not make sense.

content_type :json

{
collection: subscriptions.map(&:to_hash),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to return the whole collection, or only the ids?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

@AhtishamShahid AhtishamShahid changed the title feat: added subscribers in thread object feat: added API to get subscribers of a thread. Aug 17, 2023
@AhtishamShahid AhtishamShahid marked this pull request as ready for review August 17, 2023 11:18
@asadazam93
Copy link
Contributor

@xitij2000 it would be great if you can take a quick look.

@@ -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|
Copy link
Contributor

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.

Suggested change
get "#{APIPREFIX}/subscriptions/:thread_id" do |thread_id|
get "#{APIPREFIX}/threads/:thread_id/subscriptions" do |thread_id|

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.

Comment on lines 38 to 40
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]
Copy link
Contributor

Choose a reason for hiding this comment

The 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.
If that is the case, you should only have a one subscription between one use and thread, so specifying a subscriber_id might not make sense.

@Ian2012
Copy link

Ian2012 commented Sep 29, 2023

Is this PR stale?

@AhtishamShahid AhtishamShahid merged commit 81e11c7 into master Oct 2, 2023
2 checks passed
@AhtishamShahid AhtishamShahid deleted the ahtisham/INF-943 branch October 2, 2023 07:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants