From 478481e9a13a3c4511ae5767e92af18ad44848b9 Mon Sep 17 00:00:00 2001 From: Tanaka Chinengundu Date: Sat, 2 Nov 2024 13:51:24 +0200 Subject: [PATCH 1/2] added dropdown on post header for delete, edit and share options --- frontend/src/components/common/Post.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/common/Post.tsx b/frontend/src/components/common/Post.tsx index 3b2d435..966b799 100644 --- a/frontend/src/components/common/Post.tsx +++ b/frontend/src/components/common/Post.tsx @@ -5,6 +5,7 @@ import TechSTack from "./TechSTack"; import { AiOutlineLike } from "react-icons/ai"; import { GrView } from "react-icons/gr"; import { FaRegCommentAlt } from "react-icons/fa"; +import { SlOptionsVertical } from "react-icons/sl"; const techSTack = ["HTML", "React", "PHP", "Laravel"]; @@ -20,9 +21,20 @@ const Post = () => { className="object-fill h-8" />
-

Jessica William

+
+ Jessica William + +

{formatPostDate(createdAt)}

+

From 4fc57ef8afea3573d19fcbfe8b08e3778288605a Mon Sep 17 00:00:00 2001 From: Tanaka Chinengundu Date: Sat, 2 Nov 2024 13:59:11 +0200 Subject: [PATCH 2/2] added post edit endpoint and view --- backend/api/urls.py | 1 + backend/api/views.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/backend/api/urls.py b/backend/api/urls.py index 157fdf2..ac48a00 100644 --- a/backend/api/urls.py +++ b/backend/api/urls.py @@ -24,5 +24,6 @@ path("api/posts/new/", views.PostCreate.as_view(), name="post-create"), path("api/posts//", views.PostDetail.as_view(), name="post-detail"), path("api/posts/delete//", views.PostDelete.as_view(), name="post-delete"), + path("api/posts//edit/", views.PostUpdate.as_view(), name='post-update'), path("api/signup", views.SignUpView.as_view(), name="signup-view"), ] diff --git a/backend/api/views.py b/backend/api/views.py index daceea6..23eab57 100644 --- a/backend/api/views.py +++ b/backend/api/views.py @@ -194,3 +194,20 @@ def delete(self, request, *args, **kwargs): return self.destroy(request, *args, **kwargs) else: return Response(status=status.HTTP_403_FORBIDDEN) + + +class PostUpdate(generics.UpdateAPIView): + """ + View to edit a single post. + """ + + queryset = Post.objects.all() + serializer_class = PostSerializer + lookup_field = "pk" + + def put(self, request, *args, **kwargs): + post = self.get_object() + if post.user_profile.user == request.user: # Check if the user has permission to edit + return self.update(request, *args, **kwargs) + else: + return Response(status=status.HTTP_403_FORBIDDEN) \ No newline at end of file