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

#165273480 Add user like and or dislike article #18

Merged
merged 1 commit into from
May 6, 2019

Conversation

KabohaJeanMark
Copy link
Contributor

@KabohaJeanMark KabohaJeanMark commented May 1, 2019

What does this PR do?
It enables a user who has logged in to be able to like and or dislike their own or other people's articles

Tasks

  • Edit model for Articles to add two fields likes_count and dislikes_count
  • Add model for Like_Dislike which takes in foreign keys of User model and Articles and has a like_or_dislike field
  • Add tests for like and dislike article functionality
  • Add a serializer for the Like_Dislike model
  • Edit article views to add two view endpoint
  • Edit article urls.py file to add the two URLs for the like and dislike endpoint
  • Add validation for the user not liking or disliking the same article twice. If the endpoint for either like or dislike is hit again, the like or dislike is revoked and the likes count or dislike count in the article is updated.
  • Add functionality for if an authenticated user likes a previously disliked article, the dislike is deleted, dislike count reduces by one on the article and the like count increases by one with the like being saved and vice versa for if the user dislikes a previously liked article.

How to test out this PR?
Log in a user and go to access the following endpoints while passing the token in the header for existing articles to either like or dislike them.

Endpoints
/api/article/<article_id>/like Likes a specific article by its id
/api/article/<article_id>/dislike Dislikes specific article
/api/article/<article_id> To check the article @ fields likes_count, dislikes_count

Like an article
There is no data in the request body.
The following is the expected response body.

{
    "success": "You have successfully liked this article."
}

The expected response if you try to like the same article twice

{
    "message": "Your like has been revoked"
}

If the article is not found, this is the expected response body,

{
      "error": "That article is not found"
}

For disliking, the expected responses are similar. Simply expect dislike in the space of like
This then reduces the count in the article attribute likes_count

View article like count after like
The image below is from when you search article by id. View likes_count field.
/api/article/<article_id>/ To view article
Screen Shot 2019-05-01 at 7 00 47 PM

If the user hits like endpoint then immediately hits dislike endpoint, the expected response is

{
    "success": "Your like for the article has changed to a dislike."
}

[Starts #165273480]

Copy link
Contributor

@joelmugaya joelmugaya left a comment

Choose a reason for hiding this comment

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

This is a job well done.
I think having two separate test methods with the same data one testing a status code and the other testing response message is lengthy. Testing both in the same method would do the job

@joelmugaya joelmugaya temporarily deployed to inviticus-staging-pr-18 May 1, 2019 19:22 Inactive
@joelmugaya
Copy link
Contributor

I was able to like and dislike the same article, I think it should be only one of the two.
I also think the user would be happy if he can change his mind later and stops disliking an article he had earlier disliked or stops liking an aticle he had liked.

authors/apps/articles/tests/test_likes.py Outdated Show resolved Hide resolved
authors/apps/articles/views.py Outdated Show resolved Hide resolved
@archibishop
Copy link

@KabohaJeanMark Look into your logic to check when one likes an article and then dislikes it. The likes_count for the article doesn't decrease and ensure the like is removed and vice versa.

@archibishop
Copy link

@KabohaJeanMark The feedback should given for Likes should also be applied to the dislikes class. Go through your logic to confirm its working as expected.

@archibishop
Copy link

@KabohaJeanMark Fix the endpoints provided in the description.

@KabohaJeanMark KabohaJeanMark force-pushed the ft-user-like-or-dislike-articles-165273480 branch from 5a04cc2 to c2a4064 Compare May 2, 2019 07:55
@joelmugaya joelmugaya temporarily deployed to inviticus-staging-pr-18 May 2, 2019 07:56 Inactive
@KabohaJeanMark KabohaJeanMark force-pushed the ft-user-like-or-dislike-articles-165273480 branch from c2a4064 to c5ed665 Compare May 2, 2019 07:58
@joelmugaya joelmugaya temporarily deployed to inviticus-staging-pr-18 May 2, 2019 07:58 Inactive
@KabohaJeanMark KabohaJeanMark force-pushed the ft-user-like-or-dislike-articles-165273480 branch from c5ed665 to 35d59d5 Compare May 2, 2019 08:18
@KabohaJeanMark KabohaJeanMark force-pushed the ft-user-like-or-dislike-articles-165273480 branch from caef875 to ea2936b Compare May 3, 2019 15:22
@joelmugaya joelmugaya temporarily deployed to inviticus-staging-pr-18 May 3, 2019 15:22 Inactive
@KabohaJeanMark KabohaJeanMark force-pushed the ft-user-like-or-dislike-articles-165273480 branch from ea2936b to 8b2c5b1 Compare May 3, 2019 17:07
@joelmugaya joelmugaya temporarily deployed to inviticus-staging-pr-18 May 3, 2019 17:08 Inactive
@KabohaJeanMark KabohaJeanMark force-pushed the ft-user-like-or-dislike-articles-165273480 branch from 8b2c5b1 to f556969 Compare May 3, 2019 17:15
@joelmugaya joelmugaya temporarily deployed to inviticus-staging-pr-18 May 3, 2019 17:15 Inactive
Copy link
Contributor

@3Nakajugo 3Nakajugo left a comment

Choose a reason for hiding this comment

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

tested it and it worked.

@joelmugaya joelmugaya temporarily deployed to inviticus-staging-pr-18 May 5, 2019 08:27 Inactive
@KabohaJeanMark KabohaJeanMark force-pushed the ft-user-like-or-dislike-articles-165273480 branch from f556969 to c4f6baf Compare May 5, 2019 09:52
@joelmugaya joelmugaya temporarily deployed to inviticus-staging-pr-18 May 5, 2019 09:52 Inactive
@KabohaJeanMark KabohaJeanMark force-pushed the ft-user-like-or-dislike-articles-165273480 branch from c4f6baf to b336487 Compare May 5, 2019 10:35
@joelmugaya joelmugaya temporarily deployed to inviticus-staging-pr-18 May 5, 2019 10:35 Inactive
@KabohaJeanMark KabohaJeanMark force-pushed the ft-user-like-or-dislike-articles-165273480 branch from b336487 to 300296e Compare May 5, 2019 10:40
@joelmugaya joelmugaya temporarily deployed to inviticus-staging-pr-18 May 5, 2019 10:40 Inactive
@KabohaJeanMark KabohaJeanMark force-pushed the ft-user-like-or-dislike-articles-165273480 branch from 300296e to 58540a9 Compare May 5, 2019 18:33
@joelmugaya joelmugaya temporarily deployed to inviticus-staging-pr-18 May 5, 2019 18:33 Inactive
@KabohaJeanMark KabohaJeanMark force-pushed the ft-user-like-or-dislike-articles-165273480 branch from 58540a9 to dcf4963 Compare May 5, 2019 19:28
@joelmugaya joelmugaya temporarily deployed to inviticus-staging-pr-18 May 5, 2019 19:29 Inactive
- Add user like article
- Add count in article to increment when liked
- Add validation for user not liking same article twice

[Starts #165273480]
@KabohaJeanMark KabohaJeanMark force-pushed the ft-user-like-or-dislike-articles-165273480 branch from dcf4963 to d2cfcaf Compare May 5, 2019 22:12
@joelmugaya joelmugaya temporarily deployed to inviticus-staging-pr-18 May 5, 2019 22:12 Inactive
@joelmugaya joelmugaya temporarily deployed to inviticus-staging-pr-18 May 6, 2019 05:00 Inactive
Copy link

@archibishop archibishop left a comment

Choose a reason for hiding this comment

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

@KabohaJeanMark LGTM I am merging this.

@archibishop archibishop merged commit 7f5f8af into develop May 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants