Skip to content

Commit

Permalink
Update event views to incldue args and kwargs as required by mixins
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtavis committed Sep 24, 2024
1 parent 2ab649e commit 37dc259
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 30 deletions.
6 changes: 3 additions & 3 deletions backend/backend/management/commands/populate_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def handle(self, *args: str, **options: Unpack[Options]) -> None:

for o in range(num_orgs_per_user):
user_org = OrganizationFactory(
name=f"{user_topic.name} Organization (U{u}-O{o})",
name=f"{user_topic.name} Organization (U{u}:O{o})",
created_by=user,
)

Expand All @@ -69,7 +69,7 @@ def handle(self, *args: str, **options: Unpack[Options]) -> None:
for g in range(num_groups_per_org):
user_org_group = GroupFactory(
org_id=user_org,
name=f"{user_topic.name} Group (U{u}-O{o}-G{g})",
name=f"{user_topic.name} Group (U{u}:O{o}:G{g})",
created_by=user,
)

Expand All @@ -79,7 +79,7 @@ def handle(self, *args: str, **options: Unpack[Options]) -> None:

for e in range(num_events_per_org):
user_org_event = EventFactory(
name=f"{user_topic.name} Event (U{u}-O{o}-E{e})",
name=f"{user_topic.name} Event (U{u}:O{o}:E{e})",
type=random.choice(["learn", "action"]),
created_by=user,
)
Expand Down
23 changes: 13 additions & 10 deletions backend/entities/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,17 @@ def create(self, request: Request) -> Response:
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
serializer.save(created_by=request.user)
data = {"message": f"New Group created: {serializer.data}"}
data = {"message": f"New group created: {serializer.data}"}

return Response(data, status=status.HTTP_201_CREATED)

def retrieve(self, request: Request, *args: str, **kwargs: int) -> Response:
group = self.queryset.get(id=kwargs["pk"])
serializer = self.get_serializer(group)
if group := self.queryset.get(id=kwargs["pk"]):
serializer = self.get_serializer(group)

return Response(serializer.data, status=status.HTTP_200_OK)
return Response(serializer.data, status=status.HTTP_200_OK)

return Response({"error": "Group not found"}, status.HTTP_404_NOT_FOUND)

def partial_update(self, request: Request, *args: str, **kwargs: int) -> Response:
group = self.queryset.filter(id=kwargs["pk"]).first()
Expand Down Expand Up @@ -126,13 +128,19 @@ class OrganizationViewSet(viewsets.ModelViewSet[Organization]):
permission_classes = [IsAuthenticatedOrReadOnly]
authentication_classes = [TokenAuthentication]

def list(self, request: Request) -> Response:
serializer = self.get_serializer(self.get_queryset(), many=True)

return Response(serializer.data, status=status.HTTP_200_OK)

def create(self, request: Request) -> Response:
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
org = serializer.save(created_by=request.user)
OrganizationApplication.objects.create(org_id=org)
data = {"message": f"New organization created: {serializer.data}"}

return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(data, status=status.HTTP_201_CREATED)

def retrieve(self, request: Request, pk: str | None = None) -> Response:
if org := self.queryset.filter(id=pk).first():
Expand All @@ -142,11 +150,6 @@ def retrieve(self, request: Request, pk: str | None = None) -> Response:

return Response({"error": "Organization not found"}, status.HTTP_404_NOT_FOUND)

def list(self, request: Request) -> Response:
serializer = self.get_serializer(self.get_queryset(), many=True)

return Response(serializer.data, status=status.HTTP_200_OK)

def update(self, request: Request, pk: str | None = None) -> Response:
org = self.queryset.filter(id=pk).first()
if org is None:
Expand Down
34 changes: 17 additions & 17 deletions backend/events/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,29 @@ class EventViewSet(viewsets.ModelViewSet[Event]):
permission_classes = [IsAuthenticatedOrReadOnly]
authentication_classes = [TokenAuthentication]

def create(self, request: Request) -> Response:
def list(self, request: Request, *args: str, **kwargs: int) -> Response:
serializer = self.get_serializer(self.get_queryset(), many=True)

return Response(serializer.data, status=status.HTTP_200_OK)

def create(self, request: Request, *args: str, **kwargs: int) -> Response:
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
event = serializer.save(created_by=request.user)
Event.objects.create(id=event)
serializer.save(created_by=request.user)
data = {"message": f"New event created: {serializer.data}"}

return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(data, status=status.HTTP_201_CREATED)

def retrieve(self, request: Request, pk: str | None = None) -> Response:
if event := self.queryset.filter(id=pk).first():
def retrieve(self, request: Request, *args: str, **kwargs: int) -> Response:
if event := self.queryset.get(id=kwargs["pk"]):
serializer = self.get_serializer(event)

return Response(serializer.data, status=status.HTTP_200_OK)

return Response({"error": "Event not found"}, status.HTTP_404_NOT_FOUND)

def list(self, request: Request) -> Response:
serializer = self.get_serializer(self.get_queryset(), many=True)

return Response(serializer.data, status=status.HTTP_200_OK)

def update(self, request: Request, pk: str | None = None) -> Response:
event = self.queryset.filter(id=pk).first()
def update(self, request: Request, *args: str, **kwargs: int) -> Response:
event = self.queryset.filter(id=kwargs["pk"]).first()
if event is None:
return Response({"error": "Event not found"}, status.HTTP_404_NOT_FOUND)

Expand All @@ -86,8 +86,8 @@ def update(self, request: Request, pk: str | None = None) -> Response:

return Response(serializer.data, status.HTTP_200_OK)

def partial_update(self, request: Request, pk: str | None = None) -> Response:
event = self.queryset.filter(id=pk).first()
def partial_update(self, request: Request, *args: str, **kwargs: int) -> Response:
event = self.queryset.filter(id=kwargs["pk"]).first()
if event is None:
return Response({"error": "Event not found"}, status.HTTP_404_NOT_FOUND)

Expand All @@ -103,8 +103,8 @@ def partial_update(self, request: Request, pk: str | None = None) -> Response:

return Response(serializer.data, status.HTTP_200_OK)

def destroy(self, request: Request, pk: str | None = None) -> Response:
event = self.queryset.filter(id=pk).first()
def destroy(self, request: Request, *args: str, **kwargs: int) -> Response:
event = self.queryset.filter(id=kwargs["pk"]).first()
if event is None:
return Response({"error": "Event not found"}, status.HTTP_404_NOT_FOUND)

Expand Down

0 comments on commit 37dc259

Please sign in to comment.