Skip to content

Commit

Permalink
Merge pull request #480 from bounswe/feature/BE-posts-by-tags
Browse files Browse the repository at this point in the history
Retrieve Posts by tags
  • Loading branch information
mahmutbugramert authored Dec 13, 2024
2 parents df88702 + fe66ff0 commit 8aef665
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion backend/marketfeed/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,13 @@ def user_posts(self, request, user_id=None):

return Response(data, status=status.HTTP_200_OK)

@action(detail=False, methods=['get'], url_path='posts-by-tag/(?P<tag_id>[^/.]+)')
def posts_by_tag(self, request, tag_id=None):
tag = get_object_or_404(Tag, id=tag_id)
queryset = Post.objects.filter(tags=tag)
serializer = PostSerializer(queryset, many=True)
return Response(serializer.data)


class CommentViewSet(viewsets.ModelViewSet):
queryset = Comment.objects.all()
Expand Down Expand Up @@ -550,4 +557,3 @@ def search_all(self, request, q=None):
results['portfolios'] = portfolio_serializer.data

return Response(results)

0 comments on commit 8aef665

Please sign in to comment.