Skip to content

Commit

Permalink
166000116-bg(Comments):fix parent info
Browse files Browse the repository at this point in the history
-fix parent info

[starts #166000116]
  • Loading branch information
Amoswachira committed May 14, 2019
1 parent 8421b24 commit 10c553f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
7 changes: 5 additions & 2 deletions authors/apps/articles/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ def representation(self):
"""
Representation of a comment in a JSON serializable format
"""

parent = self.parent
if self.parent:
parent = self.parent.pk
response = {
"id": self.pk,
"article": {
Expand All @@ -149,7 +151,8 @@ def representation(self):
"createdAt": self.created_at,
"updatedAt": self.updated_at,
"body": self.body,
"author": self.get_profile_details()
"author": self.get_profile_details(),
"parent": parent
}
return response

Expand Down
2 changes: 1 addition & 1 deletion authors/apps/articles/tests/test_comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class TestComments(BaseTest):
message = 'Comment deleted successfully'
no_update = 'unsuccesful update either the comment orslug not found'
no_comment = 'no comments on this article'
no_comment_with_id = 'This article does not have a comment withthat id'
no_comment_with_id = 'This article does not have a comment with that id'

def test_successful_comment_creation(self):
"""
Expand Down
2 changes: 2 additions & 0 deletions authors/apps/articles/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ def get_comments(comments):
"updatedAt": comment.updated_at,
"body": comment.body,
"author": comment.get_profile_details(),
"parent": comment.parent,
"replies": [{
"id": child.pk,
"createdAt": child.created_at,
"updatedAt": child.updated_at,
"body": child.body,
"author": child.get_profile_details(),
"parent": comment.pk
} for child in comment.children()]
})
return parents
2 changes: 1 addition & 1 deletion authors/apps/articles/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def get_serialiser_data(serializer_data, content):
response = Response(
data={
"comments": "This article does not have a comment with"
"that id"
" that id"
},
status=status.HTTP_404_NOT_FOUND
)
Expand Down

0 comments on commit 10c553f

Please sign in to comment.