Skip to content

Commit

Permalink
combine serialisers and modify Project type
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewThien committed Oct 28, 2024
1 parent 15119b1 commit 271c86c
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 21 deletions.
12 changes: 0 additions & 12 deletions app/api/projects/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,6 @@ class Meta:
fields = ["id", "name"]


class ProjectWithMembersSerializer(DynamicFieldsMixin, serializers.ModelSerializer):
"""
Serialiser for showing the names and members of Projects. Use in non-admin ListViews.
"""

members = UserSerializer(read_only=True, many=True)

class Meta:
model = Project
fields = ["id", "name", "members", "created_at"]


class ProjectDatasetSerializer(DynamicFieldsMixin, serializers.ModelSerializer):
"""
Serialiser for only showing the names of Projects. Use in non-admin ListViews.
Expand Down
8 changes: 1 addition & 7 deletions app/api/projects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from projects.serializers import (
ProjectDatasetSerializer,
ProjectSerializer,
ProjectWithMembersSerializer,
)
from rest_framework.generics import ListAPIView, RetrieveAPIView
from rest_framework.permissions import IsAuthenticated
Expand All @@ -25,15 +24,10 @@ class ProjectList(ListAPIView):
ordering = "-created_at"

def get_serializer_class(self):
if (
self.request.GET.get("name") is not None
or self.request.GET.get("name__in") is not None
):
return ProjectSerializer
if self.request.GET.get("datasets") is not None:
return ProjectDatasetSerializer

return ProjectWithMembersSerializer
return ProjectSerializer

def get_queryset(self):
if dataset := self.request.GET.get("dataset"):
Expand Down
2 changes: 0 additions & 2 deletions app/next-client-app/types/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@ interface Project {
id: number;
name: string;
members: User[];
datasets: DataSet[];
created_at: Date;
updated_at: Date;
}

0 comments on commit 271c86c

Please sign in to comment.