From d3ca8560fc667a8823919c90f5bb95277485b1df Mon Sep 17 00:00:00 2001 From: pablohashescobar <118773738+pablohashescobar@users.noreply.github.com> Date: Wed, 15 Mar 2023 23:24:26 +0530 Subject: [PATCH] fix: project list ordering (#427) --- apiserver/plane/api/views/project.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/apiserver/plane/api/views/project.py b/apiserver/plane/api/views/project.py index 730875e0c..0134547c5 100644 --- a/apiserver/plane/api/views/project.py +++ b/apiserver/plane/api/views/project.py @@ -81,6 +81,27 @@ class ProjectViewSet(BaseViewSet): .distinct() ) + def list(self, request, slug): + try: + subquery = ProjectFavorite.objects.filter( + user=self.request.user, + project_id=OuterRef("pk"), + workspace__slug=self.kwargs.get("slug"), + ) + projects = ( + self.get_queryset() + .annotate(is_favorite=Exists(subquery)) + .order_by("-is_favorite") + ) + return Response(ProjectDetailSerializer(projects, many=True).data) + except Exception as e: + capture_exception(e) + return Response( + {"error": "Something went wrong please try again later"}, + status=status.HTTP_400_BAD_REQUEST, + ) + + def create(self, request, slug): try: workspace = Workspace.objects.get(slug=slug)