-
Notifications
You must be signed in to change notification settings - Fork 5
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
#163383200 Users should see their reading stats #45
Conversation
Hello @codjoero! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on February 21, 2019 at 12:23 Hours UTC |
7c38323
to
6557db2
Compare
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.
Thank you for explaining this to me, I understand it a little bit better. Nice work you did here, I appreciate that you went ahead and implemented authors being able to see read stats of their articles.
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.
Good work on this @codjoero.
I have left specific comments below.
}, status=status.HTTP_404_NOT_FOUND) | ||
serialized_data = self.serializer_class(article, | ||
context=context) | ||
if not request.user.is_anonymous and\ |
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.
A few comments here would be helpful @codjoero
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.
@karuhanga thanks for the suggestion, I went ahead and added some comments where I thought the code was abit complex.
authors/apps/profiles/urls.py
Outdated
path("", UserProfileListAPIView.as_view(), name="profile-list"), | ||
path("", UserProfileListAPIView.as_view(), | ||
name="profile-list"), | ||
path('<username>/readstats', ReadStatsView.as_view(), |
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.
Why do you need to specify a username
if the user is already logged in
, and from what I understand, a user can only
get their
stats
?
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.
@karuhanga As you might notice if you read the API spec, GET /profiles/:username
would try to fetch you the profile of <username>
hence the use of GET /profiles/:username/readstats
to fetch the user's reading stats.
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.
True, I have noticed that. But in this case one cannot retrieve another user's reading stats the way they can retrieve their profile. In light of this therefore, I do not see the need to require the API consumer to supply a user for a user that is already logged in.
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.
@karuhanga , thanks for the feedback, the issue has been resolved
authors/apps/articles/models.py
Outdated
@@ -60,6 +60,7 @@ class Article(models.Model): | |||
disliked_by = models.ManyToManyField(to=settings.AUTH_USER_MODEL, | |||
related_name='disliked_articles', | |||
related_query_name='disliked_article') | |||
read_stats = models.IntegerField(default=0) |
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 would like to understand the use of this field, and where exactly it is being used.
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.
@karuhanga , thanks for the catch, had planned to use it to store the Article readstats before i changed to a MethodSerializer.
6557db2
to
1d6f6f0
Compare
Great work here @codjoero. Your code is easy to follow and understand. |
1d6f6f0
to
66784d6
Compare
@codjoero ,please resolve merge conflicts. |
66784d6
to
76f029d
Compare
76f029d
to
365802c
Compare
@codjoero some merge conflits |
365802c
to
32ee0ca
Compare
- add a model for the stats - add the ReadStatsSerializer class to handle the model information - add the view endpoint for all read stats - add functionality to get the data from the read articles - update the urls to add the stats endpoint - write tests for the functionality [Starts #163383200]
32ee0ca
to
fc21eb9
Compare
What does this PR do?
This PR enables a user to be able to see their reading stats
This task should also allow an author to see the reading stats for each of their article
Description of Task to be completed?
How should this be manually tested?
Screenshots
Get read stats for a user
/api/v1/profiles/user/readstats
Reading an article
/api/v1/articles/<slug>
Author get their article
/api/v1/articles/<slug>
Related story
163383200