From 354d9c9518e88c31e2239e571519ce7774784e9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0brahim=20Bayat?= Date: Thu, 23 Dec 2021 16:18:49 +0200 Subject: [PATCH] Get comment by id is created according to activity stream --- backend/comments/urls.py | 2 +- backend/comments/views.py | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/backend/comments/urls.py b/backend/comments/urls.py index 828fe704..01ee7188 100644 --- a/backend/comments/urls.py +++ b/backend/comments/urls.py @@ -4,7 +4,7 @@ urlpatterns = [ - #path('/comments/', views.GetCommentById.as_view(), name="GetCommentById"), + path('/comments/', views.GetCommentById.as_view(), name="GetCommentById"), path('/comments/', views.Comments.as_view(), name="AllComments"), #path('api/posts//comments//answers', views.Answers.as_view(), name="AllAnswers"), ] diff --git a/backend/comments/views.py b/backend/comments/views.py index b97ed1e1..283ec0f5 100644 --- a/backend/comments/views.py +++ b/backend/comments/views.py @@ -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):