Skip to content

Commit

Permalink
Add check to add_to_cart
Browse files Browse the repository at this point in the history
  • Loading branch information
aviupadhyayula committed Oct 10, 2024
1 parent 6fb5368 commit 618c00f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions backend/clubs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2416,10 +2416,17 @@ def add_to_cart(self, request, *args, **kwargs):
event = self.get_object()
cart, _ = Cart.objects.get_or_create(owner=self.request.user)

# Check if the event has already ended
if event.end_time <= timezone.now():
return Response(
{"detail": "This event has already ended", "success": False},
status=status.HTTP_403_FORBIDDEN,
)

# Cannot add tickets that haven't dropped yet
if event.ticket_drop_time and timezone.now() < event.ticket_drop_time:
return Response(
{"detail": "Ticket drop time has not yet elapsed"},
{"detail": "Ticket drop time has not yet elapsed", "success": False},
status=status.HTTP_403_FORBIDDEN,
)

Expand Down Expand Up @@ -2463,7 +2470,10 @@ def add_to_cart(self, request, *args, **kwargs):

if tickets.count() < count:
return Response(
{"detail": f"Not enough tickets of type {type} left!"},
{
"detail": f"Not enough tickets of type {type} left!",
"success": False,
},
status=status.HTTP_403_FORBIDDEN,
)
cart.tickets.add(*tickets[:count])
Expand Down

0 comments on commit 618c00f

Please sign in to comment.