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

#161966615 like and dislike articles #25

Merged
merged 1 commit into from
Dec 13, 2018

Conversation

salma-nyagaka
Copy link
Contributor

@salma-nyagaka salma-nyagaka commented Dec 13, 2018

What does this pull request do?

This PR implements the functionality of liking and disliking articles.

Description of the tasks to be completed?

  • like article
    PUT /api/slug/like/
  • dislike article
    PUT /api/slug/dislike/

How should this be manually tested?

   $ git clone https://github.com/andela/ah-technocrats.git
   $ cd ah-technocrats
   $ git checkout ft-like-dislike-161966615
   $ python3 -m venv venv
   $ source venv/bin/activate
   $ pip install -r requirements.txt
   $ python manage.py makemigrations
   $ python manage.py migrate
   $ python manage.py runserver

testing:

   $ python manage.py test

Screenshots:

Like an article

screen shot 2018-12-13 at 18 08 47

Unlike an article

screen shot 2018-12-13 at 18 06 49

Disliked an article

screen shot 2018-12-13 at 18 06 54

Un-dislike an article

screen shot 2018-12-13 at 18 06 56

What are the relevant Pivotal Tracker Stories

#161966615

Checklist:

  • My code follows the style guidelines of this project
  • At least 2 people have reviewed my PR
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • My PR has one commit.

@salma-nyagaka salma-nyagaka added the WIP Work In Progress label Dec 13, 2018
return Response({'message':"article not found."})


class LikeArticle(UpdateAPIView):
Copy link

Choose a reason for hiding this comment

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

Similar blocks of code found in 2 locations. Consider refactoring.

return Response(message, status.HTTP_200_OK)


class DislikeArticle(UpdateAPIView):
Copy link

Choose a reason for hiding this comment

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

Similar blocks of code found in 2 locations. Consider refactoring.

body = serializers.CharField()
author = UserSerializer(read_only = True)

def likes(self, instance):
Copy link

Choose a reason for hiding this comment

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

Similar blocks of code found in 2 locations. Consider refactoring.

liked = instance.likes.all().filter(id=user_id).count() == 1
return {'likes': instance.likes.count(), 'User': liked}

def dislikes(self, instance):
Copy link

Choose a reason for hiding this comment

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

Similar blocks of code found in 2 locations. Consider refactoring.

@salma-nyagaka salma-nyagaka force-pushed the ft-like-dislike-articles-161966615 branch 5 times, most recently from 0b6ee09 to d6c0e4b Compare December 13, 2018 14:49
@salma-nyagaka salma-nyagaka added WIP Work In Progress and removed WIP Work In Progress labels Dec 13, 2018
@salma-nyagaka salma-nyagaka force-pushed the ft-like-dislike-articles-161966615 branch 2 times, most recently from cdfdca6 to fb8c508 Compare December 13, 2018 18:54
user = request.user
# checks for the boolean value of liking an article
liked = bool(user in article.like.all())
if liked is True:
Copy link

Choose a reason for hiding this comment

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

Similar blocks of code found in 2 locations. Consider refactoring.

user = request.user
# checks for the boolean value of disliking an article
disliked = bool(user in article.dislike.all())
if disliked is True:
Copy link

Choose a reason for hiding this comment

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

Similar blocks of code found in 2 locations. Consider refactoring.

@salma-nyagaka salma-nyagaka added the WIP Work In Progress label Dec 13, 2018
@salma-nyagaka salma-nyagaka force-pushed the ft-like-dislike-articles-161966615 branch 3 times, most recently from b901d6a to 80747b0 Compare December 13, 2018 20:55
…sliking an article

- add tests for liking and disliking fuctionality
- modify the base file to accomodate the tests
- add fields in the model for liking and disliking an article
- add a method in the serializer for returning a liked or disliked functionality
- add views for liking and disliking an article.

[Delivers #161966615]
@SilasKenneth SilasKenneth force-pushed the ft-like-dislike-articles-161966615 branch from 80747b0 to e4dcd39 Compare December 13, 2018 21:34
@codeclimate
Copy link

codeclimate bot commented Dec 13, 2018

Code Climate has analyzed commit e4dcd39 and detected 4 issues on this pull request.

Here's the issue category breakdown:

Category Count
Duplication 4

View more on Code Climate.

@salma-nyagaka salma-nyagaka removed the WIP Work In Progress label Dec 13, 2018
Copy link

@Mnickii Mnickii left a comment

Choose a reason for hiding this comment

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

LGTM

@Mnickii Mnickii merged commit 19b07b1 into develop Dec 13, 2018
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.

2 participants