Skip to content

Commit

Permalink
bg(fixing comments): fix backend
Browse files Browse the repository at this point in the history
- To get a comment for an article

[Delivers #164162050]
  • Loading branch information
james wafula authored and james wafula committed Feb 22, 2019
1 parent 510b467 commit 13e5d98
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
3 changes: 0 additions & 3 deletions authors/apps/comments/tests/test_comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ def test_get_all_comments(self):
format='json',
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertIn('count', response.data)
self.assertIn('next', response.data)
self.assertIn('previous', response.data)

def test_get_specific_comment(self):
"""
Expand Down
23 changes: 11 additions & 12 deletions authors/apps/comments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from authors.apps.articles.models import Article
from authors.apps.profiles.models import Profile
from ..authentication.messages import error_msg, success_msg
from authors.apps.core.pagination import PaginateContent


class CreateCommentAPiView(generics.ListCreateAPIView):
Expand Down Expand Up @@ -42,17 +41,17 @@ def post(self, request, *args, **kwargs):

def get(self, request, *args, **kwargs):
'''This method gets all comments for an article'''
paginate_data = PaginateContent()
comments_per_article = paginate_data.paginate_queryset(
self.queryset, request)
serializer = CommentSerializer(
comments_per_article,
context={
'request': request
},
many=True
)
return paginate_data.get_paginated_response(serializer.data)
slug = self.kwargs['slug']
article = self.util.check_article(slug)
comments = self.queryset.filter(article_id=article.id)
serializer = self.serializer_class(comments, context={'request':request}, many=True)
return Response({"comments": serializer.data,
"commentsCount": comments.count()
}, status=status.HTTP_200_OK)





class CommentApiView(generics.RetrieveUpdateDestroyAPIView):
Expand Down

0 comments on commit 13e5d98

Please sign in to comment.