diff --git a/backend/clubs/migrations/0091_cart_ticket.py b/backend/clubs/migrations/0091_cart_ticket.py new file mode 100644 index 000000000..758aa2e30 --- /dev/null +++ b/backend/clubs/migrations/0091_cart_ticket.py @@ -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, + ), + ), + ], + ), + ] diff --git a/backend/clubs/migrations/0091_ticket.py b/backend/clubs/migrations/0091_ticket.py deleted file mode 100644 index a76becfee..000000000 --- a/backend/clubs/migrations/0091_ticket.py +++ /dev/null @@ -1,51 +0,0 @@ -# Generated by Django 3.2.8 on 2022-01-16 20:59 - -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="Ticket", - fields=[ - ( - "id", - models.UUIDField( - default=uuid.uuid4, - editable=False, - primary_key=True, - serialize=False, - ), - ), - ("type", models.CharField(max_length=100)), - ( - "event", - models.ForeignKey( - on_delete=django.db.models.deletion.DO_NOTHING, - related_name="tickets", - to="clubs.event", - ), - ), - ( - "owner", - models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="tickets", - to=settings.AUTH_USER_MODEL, - ), - ), - ], - ), - ] diff --git a/backend/clubs/migrations/0092_auto_20220211_1732.py b/backend/clubs/migrations/0092_auto_20220211_1732.py deleted file mode 100644 index fb2470a86..000000000 --- a/backend/clubs/migrations/0092_auto_20220211_1732.py +++ /dev/null @@ -1,53 +0,0 @@ -# Generated by Django 3.2.8 on 2022-02-11 22:32 - -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", "0091_ticket"), - ] - - operations = [ - migrations.AddField( - model_name="ticket", name="held", field=models.BooleanField(default=False), - ), - migrations.AddField( - model_name="ticket", - name="holding_expiration", - field=models.DateTimeField(blank=True, null=True), - ), - migrations.CreateModel( - name="Cart", - fields=[ - ( - "id", - models.AutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ( - "owner", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, - related_name="cart", - to=settings.AUTH_USER_MODEL, - ), - ), - ], - ), - migrations.AddField( - model_name="ticket", - name="carts", - field=models.ManyToManyField( - blank=True, related_name="tickets", to="clubs.Cart" - ), - ), - ] diff --git a/backend/clubs/migrations/0093_auto_20220706_0548.py b/backend/clubs/migrations/0093_auto_20220706_0548.py deleted file mode 100644 index 3a2c38eda..000000000 --- a/backend/clubs/migrations/0093_auto_20220706_0548.py +++ /dev/null @@ -1,51 +0,0 @@ -# Generated by Django 3.2.8 on 2022-07-06 09:48 - -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", "0092_auto_20220211_1732"), - ] - - operations = [ - migrations.RemoveField( - model_name="ticket", - name="held", - ), - migrations.AddField( - model_name="ticket", - name="holder", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="held_tickets", - to=settings.AUTH_USER_MODEL, - ), - ), - migrations.AlterField( - model_name="cart", - name="owner", - field=models.OneToOneField( - on_delete=django.db.models.deletion.CASCADE, - related_name="cart", - to=settings.AUTH_USER_MODEL, - ), - ), - migrations.AlterField( - model_name="ticket", - name="owner", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="owned_tickets", - to=settings.AUTH_USER_MODEL, - ), - ), - ] diff --git a/backend/clubs/serializers.py b/backend/clubs/serializers.py index fe4ec4452..9e3286308 100644 --- a/backend/clubs/serializers.py +++ b/backend/clubs/serializers.py @@ -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): @@ -483,6 +483,7 @@ class Meta: "location", "name", "start_time", + "ticketed", "type", "url", ] diff --git a/backend/clubs/views.py b/backend/clubs/views.py index 3325a1534..7cf52e543 100644 --- a/backend/clubs/views.py +++ b/backend/clubs/views.py @@ -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] @@ -2259,7 +2269,7 @@ def add_to_cart(self, request, *args, **kwargs): properties: detail: type: string - "403": + "403": content: application/json: schema: @@ -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: @@ -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"})