Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tanaka chinengundu update post #73

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
path("api/posts/new/", views.PostCreate.as_view(), name="post-create"),
path("api/posts/<int:pk>/", views.PostDetail.as_view(), name="post-detail"),
path("api/posts/delete/<int:pk>/", views.PostDelete.as_view(), name="post-delete"),
path("api/posts/<int:pk>/edit/", views.PostUpdate.as_view(), name='post-update'),
path("api/signup", views.SignUpView.as_view(), name="signup-view"),
]
17 changes: 17 additions & 0 deletions backend/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
14 changes: 13 additions & 1 deletion frontend/src/components/common/Post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"];

Expand All @@ -20,9 +21,20 @@ const Post = () => {
className="object-fill h-8"
/>
<div className="flex flex-col">
<p className="text-sm font-bold">Jessica William</p>
<div className="flex flex-row items-center justify-between">
<span className="text-sm font-bold">Jessica William</span>
<button
onClick={() => {
//!TODO implement a dropdown for edit, delete and share options
}}
className="ml-auto"
>
<SlOptionsVertical />
</button>
</div>
<p className="text-xs">{formatPostDate(createdAt)}</p>
</div>

</div>
<div className="my-2">
<p className="text-subheading-100 text-sm">
Expand Down