Skip to content

Commit

Permalink
added cart creation for a user upon adding to a cart if a cart does n…
Browse files Browse the repository at this point in the history
…ot yet exist
  • Loading branch information
Dfeng6789 authored and rohangpta committed Oct 2, 2022
1 parent 3be5737 commit 4bf90cc
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion backend/clubs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2217,7 +2217,7 @@ def get_serializer_class(self):
return EventWriteSerializer
return EventSerializer

@action(detail=False, methods=["post"])
@action(detail=True, methods=["post"])
def cart(self, request, *args, **kwargs):
"""
Add a certain number of tickets to cart
Expand Down Expand Up @@ -2245,6 +2245,9 @@ def cart(self, request, *args, **kwargs):
count = request.data.get("count")
event = Event.objects.get(id=self.get_object().id)
cart = Cart.objects.filter(owner=self.request.user).first()
if not cart:
new_cart = Cart(owner=self.request.user)
new_cart.save()

# Try to get count unowned ticket of requested type
tickets = Ticket.objects.filter(
Expand Down

0 comments on commit 4bf90cc

Please sign in to comment.