Skip to content

Commit

Permalink
Get comment by id is created according to activity stream
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrahimbayat committed Dec 23, 2021
1 parent ff1be27 commit 354d9c9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion backend/comments/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

urlpatterns = [

#path('<int:postid>/comments/<int:commentid>', views.GetCommentById.as_view(), name="GetCommentById"),
path('<int:postid>/comments/<int:commentid>', views.GetCommentById.as_view(), name="GetCommentById"),
path('<int:id>/comments/', views.Comments.as_view(), name="AllComments"),
#path('api/posts/<post_id>/comments/<comment_id>/answers', views.Answers.as_view(), name="AllAnswers"),
]
24 changes: 24 additions & 0 deletions backend/comments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,30 @@
from django.forms.models import model_to_dict
from django.utils import timezone



class GetCommentById(APIView):

def get (self,request,postid,commentid):
try:
comments=Comment.objects.filter(eventid=postid,id=commentid)
except:
return Response(status=status.HTTP_400_BAD_REQUEST)

if(len(comments)==0):
return Response(status=status.HTTP_404_NOT_FOUND)
commentserializer = CommentSerializer(comments, many=True)
object = {"type": "Comment", "postId": comments[0].eventid.id, "ownerId": comments[0].owner.id, "content": comments[0].comment,
"creationDate": comments[0].creationDate} #timezone.now()}

response = {"@context": "https://www.w3.org/ns/activitystreams",
"summary": comments[0].owner.username + " created a comment",
"type":"Create",
"actor":{"type":"Person","name":comments[0].owner.username } }
response["object"] = object
return Response(response)


class Comments(APIView):
def get(self, request,id):

Expand Down

0 comments on commit 354d9c9

Please sign in to comment.