Skip to content

Commit

Permalink
rebase master
Browse files Browse the repository at this point in the history
  • Loading branch information
rohangpta committed Oct 2, 2022
1 parent 525d63a commit df42cbd
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 162 deletions.
90 changes: 90 additions & 0 deletions backend/clubs/migrations/0091_cart_ticket.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Generated by Django 3.2.8 on 2022-10-02 16:50

import uuid

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("clubs", "0090_adminnote"),
]

operations = [
migrations.CreateModel(
name="Cart",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"owner",
models.OneToOneField(
on_delete=django.db.models.deletion.CASCADE,
related_name="cart",
to=settings.AUTH_USER_MODEL,
),
),
],
),
migrations.CreateModel(
name="Ticket",
fields=[
(
"id",
models.UUIDField(
default=uuid.uuid4,
editable=False,
primary_key=True,
serialize=False,
),
),
("type", models.CharField(max_length=100)),
("holding_expiration", models.DateTimeField(blank=True, null=True)),
(
"carts",
models.ManyToManyField(
blank=True, related_name="tickets", to="clubs.Cart"
),
),
(
"event",
models.ForeignKey(
on_delete=django.db.models.deletion.DO_NOTHING,
related_name="tickets",
to="clubs.event",
),
),
(
"holder",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="held_tickets",
to=settings.AUTH_USER_MODEL,
),
),
(
"owner",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="owned_tickets",
to=settings.AUTH_USER_MODEL,
),
),
],
),
]
51 changes: 0 additions & 51 deletions backend/clubs/migrations/0091_ticket.py

This file was deleted.

53 changes: 0 additions & 53 deletions backend/clubs/migrations/0092_auto_20220211_1732.py

This file was deleted.

51 changes: 0 additions & 51 deletions backend/clubs/migrations/0093_auto_20220706_0548.py

This file was deleted.

3 changes: 2 additions & 1 deletion backend/clubs/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ class ClubEventSerializer(serializers.ModelSerializer):
ticketed = serializers.SerializerMethodField("get_ticketed")
creator = serializers.HiddenField(default=serializers.CurrentUserDefault())

def get_ticketed(self, obj):
def get_ticketed(self, obj) -> bool:
return Event.tickets.exists()

def get_event_url(self, obj):
Expand Down Expand Up @@ -483,6 +483,7 @@ class Meta:
"location",
"name",
"start_time",
"ticketed",
"type",
"url",
]
Expand Down
24 changes: 18 additions & 6 deletions backend/clubs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2214,6 +2214,16 @@ class ClubEventViewSet(viewsets.ModelViewSet):
buy:
Buy a ticket for an event
buyers:
Get information about the buyers of an event's ticket
remove_from_cart:
Remove a ticket for this event from cart
add_to_cart:
Add a ticket for this event to cart
"""

permission_classes = [EventPermission | IsSuperuser]
Expand Down Expand Up @@ -2259,7 +2269,7 @@ def add_to_cart(self, request, *args, **kwargs):
properties:
detail:
type: string
"403":
"403":
content:
application/json:
schema:
Expand Down Expand Up @@ -2421,6 +2431,7 @@ def tickets(self, request, *args, **kwargs):
return Response({"totals": totals, "available": available})

@tickets.mapping.put
@transaction.atomic
def create_tickets(self, request, *args, **kwargs):
"""
requestBody:
Expand Down Expand Up @@ -2451,13 +2462,14 @@ def create_tickets(self, request, *args, **kwargs):
event = self.get_object()
quantities = request.data.get("quantities")

print(request.method)

Ticket.objects.filter(event=event).delete() # Idempotency
tickets = [
Ticket(event=event, type=item["type"])
for item in quantities
for _ in range(item["count"])
]

for item in quantities:
for _ in range(item["count"]):
Ticket.objects.create(event=event, type=item["type"])
Ticket.objects.bulk_create(tickets)

return Response({"detail": "success"})

Expand Down

0 comments on commit df42cbd

Please sign in to comment.