Skip to content

Commit

Permalink
🎉 Modify sold_out to return event type and count
Browse files Browse the repository at this point in the history
  • Loading branch information
joyliu-q committed Apr 21, 2024
1 parent 843de60 commit 80424ab
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions backend/clubs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4784,7 +4784,16 @@ def cart(self, request, *args, **kwargs):
allOf:
- $ref: "#/components/schemas/Ticket"
sold_out:
type: integer
type: list
items:
type: object
properties:
type:
type: string
event:
type: integer
count:
type: integer
---
"""

Expand All @@ -4802,12 +4811,11 @@ def cart(self, request, *args, **kwargs):
return Response(
{
"tickets": TicketSerializer(cart.tickets.all(), many=True).data,
"sold_out": 0,
"sold_out": [],
},
)

sold_out_count = 0

sold_out_tickets = []
replacement_tickets = []
tickets_in_cart = cart.tickets.values_list("id", flat=True)
for ticket_class in tickets_to_replace.values("type", "event").annotate(
Expand All @@ -4821,7 +4829,13 @@ def cart(self, request, *args, **kwargs):
holder__isnull=True,
).exclude(id__in=tickets_in_cart)[: ticket_class["count"]]

sold_out_count += ticket_class["count"] - tickets.count()
sold_out_tickets += [
{
"type": ticket_class["type"],
"event": ticket_class["event"],
"count": ticket_class["count"] - tickets.count(),
}
]
replacement_tickets.extend(list(tickets))

cart.tickets.remove(*tickets_to_replace)
Expand All @@ -4832,7 +4846,7 @@ def cart(self, request, *args, **kwargs):
return Response(
{
"tickets": TicketSerializer(cart.tickets.all(), many=True).data,
"sold_out": sold_out_count,
"sold_out": sold_out_tickets,
},
)

Expand Down

0 comments on commit 80424ab

Please sign in to comment.