Skip to content

Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️

Initial endpoints and components

Dave Earley252ce28db73f
diff --git a/backend/app/DomainObjects/AttributeEventDomainObject.php b/backend/app/DomainObjects/AttributeEventDomainObject.php
deleted file mode 100644
index 5427d8c23..000000000
--- a/backend/app/DomainObjects/AttributeEventDomainObject.php
+++ /dev/null
@@ -1,7 +0,0 @@
-<?php
-
-namespace HiEvents\DomainObjects;
-
-class AttributeEventDomainObject extends Generated\AttributeEventDomainObjectAbstract
-{
-}
diff --git a/backend/app/DomainObjects/CapacityAssignmentDomainObject.php b/backend/app/DomainObjects/CapacityAssignmentDomainObject.php
new file mode 100644
index 000000000..68c5e065c
--- /dev/null
+++ b/backend/app/DomainObjects/CapacityAssignmentDomainObject.php
@@ -0,0 +1,31 @@
+<?php
+
+namespace HiEvents\DomainObjects;
+
+use Illuminate\Support\Collection;
+
+class CapacityAssignmentDomainObject extends Generated\CapacityAssignmentDomainObjectAbstract
+{
+ public ?Collection $tickets = null;
+
+ public function getPercentageUsed(): float
+ {
+ if (!$this->getCapacity()) {
+ return 0;
+ }
+
+ return round(($this->getUsedCapacity() / $this->getCapacity()) * 100, 2);
+ }
+
+ public function getTickets(): ?Collection
+ {
+ return $this->tickets;
+ }
+
+ public function setTickets(?Collection $tickets): static
+ {
+ $this->tickets = $tickets;
+
+ return $this;
+ }
+}
diff --git a/backend/app/DomainObjects/CustomerDomainObject.php b/backend/app/DomainObjects/CustomerDomainObject.php
deleted file mode 100644
index ce7dd1241..000000000
--- a/backend/app/DomainObjects/CustomerDomainObject.php
+++ /dev/null
@@ -1,7 +0,0 @@
-<?php
-
-namespace HiEvents\DomainObjects;
-
-class CustomerDomainObject extends Generated\CustomerDomainObjectAbstract
-{
-}
diff --git a/backend/app/DomainObjects/Enums/CapacityAssignmentAppliesTo.php b/backend/app/DomainObjects/Enums/CapacityAssignmentAppliesTo.php
new file mode 100644
index 000000000..75d27759b
--- /dev/null
+++ b/backend/app/DomainObjects/Enums/CapacityAssignmentAppliesTo.php
@@ -0,0 +1,11 @@
+<?php
+
+namespace HiEvents\DomainObjects\Enums;
+
+enum CapacityAssignmentAppliesTo
+{
+ use BaseEnum;
+
+ case TICKETS;
+ case EVENT;
+}
diff --git a/backend/app/DomainObjects/Generated/CapacityAssignmentDomainObjectAbstract.php b/backend/app/DomainObjects/Generated/CapacityAssignmentDomainObjectAbstract.php
new file mode 100644
index 000000000..afa49a0e5
--- /dev/null
+++ b/backend/app/DomainObjects/Generated/CapacityAssignmentDomainObjectAbstract.php
@@ -0,0 +1,160 @@
+<?php
+
+namespace HiEvents\DomainObjects\Generated;
+
+/**
+ * THIS FILE IS AUTOGENERATED - DO NOT EDIT IT DIRECTLY.
+ * @package HiEvents\DomainObjects\Generated
+ */
+abstract class CapacityAssignmentDomainObjectAbstract extends \HiEvents\DomainObjects\AbstractDomainObject
+{
+ final public const SINGULAR_NAME = 'capacity_assignment';
+ final public const PLURAL_NAME = 'capacity_assignments';
+ final public const ID = 'id';
+ final public const EVENT_ID = 'event_id';
+ final public const NAME = 'name';
+ final public const CAPACITY = 'capacity';
+ final public const USED_CAPACITY = 'used_capacity';
+ final public const APPLIES_TO = 'applies_to';
+ final public const STATUS = 'status';
+ final public const CREATED_AT = 'created_at';
+ final public const UPDATED_AT = 'updated_at';
+ final public const DELETED_AT = 'deleted_at';
+
+ protected int $id;
+ protected int $event_id;
+ protected string $name;
+ protected ?int $capacity = null;
+ protected int $used_capacity = 0;
+ protected string $applies_to = 'EVENT';
+ protected string $status = 'ACTIVE';
+ protected ?string $created_at = null;
+ protected ?string $updated_at = null;
+ protected ?string $deleted_at = null;
+
+ public function toArray(): array
+ {
+ return [
+ 'id' => $this->id ?? null,
+ 'event_id' => $this->event_id ?? null,
+ 'name' => $this->name ?? null,
+ 'capacity' => $this->capacity ?? null,
+ 'used_capacity' => $this->used_capacity ?? null,
+ 'applies_to' => $this->applies_to ?? null,
+ 'status' => $this->status ?? null,
+ 'created_at' => $this->created_at ?? null,
+ 'updated_at' => $this->updated_at ?? null,
+ 'deleted_at' => $this->deleted_at ?? null,
+ ];
+ }
+
+ public function setId(int $id): self
+ {
+ $this->id = $id;
+ return $this;
+ }
+
+ public function getId(): int
+ {
+ return $this->id;
+ }
+
+ public function setEventId(int $event_id): self
+ {
+ $this->event_id = $event_id;
+ return $this;
+ }
+
+ public function getEventId(): int
+ {
+ return $this->event_id;
+ }
+
+ public function setName(string $name): self
+ {
+ $this->name = $name;
+ return $this;
+ }
+
+ public function getName(): string
+ {
+ return $this->name;
+ }
+
+ public function setCapacity(?int $capacity): self
+ {
+ $this->capacity = $capacity;
+ return $this;
+ }
+
+ public function getCapacity(): ?int
+ {
+ return $this->capacity;
+ }
+
+ public function setUsedCapacity(int $used_capacity): self
+ {
+ $this->used_capacity = $used_capacity;
+ return $this;
+ }
+
+ public function getUsedCapacity(): int
+ {
+ return $this->used_capacity;
+ }
+
+ public function setAppliesTo(string $applies_to): self
+ {
+ $this->applies_to = $applies_to;
+ return $this;
+ }
+
+ public function getAppliesTo(): string
+ {
+ return $this->applies_to;
+ }
+
+ public function setStatus(string $status): self
+ {
+ $this->status = $status;
+ return $this;
+ }
+
+ public function getStatus(): string
+ {
+ return $this->status;
+ }
+
+ public function setCreatedAt(?string $created_at): self
+ {
+ $this->created_at = $created_at;
+ return $this;
+ }
+
+ public function getCreatedAt(): ?string
+ {
+ return $this->created_at;
+ }
+
+ public function setUpdatedAt(?string $updated_at): self
+ {
+ $this->updated_at = $updated_at;
+ return $this;
+ }
+
+ public function getUpdatedAt(): ?string
+ {
+ return $this->updated_at;
+ }
+
+ public function setDeletedAt(?string $deleted_at): self
+ {
+ $this->deleted_at = $deleted_at;
+ return $this;
+ }
+
+ public function getDeletedAt(): ?string
+ {
+ return $this->deleted_at;
+ }
+}
diff --git a/backend/app/DomainObjects/Generated/OrderDomainObjectAbstract.php b/backend/app/DomainObjects/Generated/OrderDomainObjectAbstract.php
index 939ca2cd9..b9d645f1c 100644
--- a/backend/app/DomainObjects/Generated/OrderDomainObjectAbstract.php
+++ b/backend/app/DomainObjects/Generated/OrderDomainObjectAbstract.php
@@ -24,7 +24,6 @@ abstract class OrderDomainObjectAbstract extends \HiEvents\DomainObjects\Abstrac
final public const STATUS = 'status';
final public const PAYMENT_STATUS = 'payment_status';
final public const REFUND_STATUS = 'refund_status';
- final public const RESERVED_UNTIL = 'reserved_until';
final public const IS_MANUALLY_CREATED = 'is_manually_created';
final public const SESSION_ID = 'session_id';
final public const PUBLIC_ID = 'public_id';
@@ -39,6 +38,7 @@ abstract class OrderDomainObjectAbstract extends \HiEvents\DomainObjects\Abstrac
final public const TOTAL_TAX = 'total_tax';
final public const TOTAL_FEE = 'total_fee';
final public const LOCALE = 'locale';
+ final public const RESERVED_UNTIL = 'reserved_until';
protected int $id;
protected int $event_id;
@@ -54,7 +54,6 @@ abstract class OrderDomainObjectAbstract extends \HiEvents\DomainObjects\Abstrac
protected string $status;
protected ?string $payment_status = null;
protected ?string $refund_status = null;
- protected ?string $reserved_until = null;
protected bool $is_manually_created = false;
protected ?string $session_id = null;
protected string $public_id;
@@ -69,6 +68,7 @@ abstract class OrderDomainObjectAbstract extends \HiEvents\DomainObjects\Abstrac
protected float $total_tax = 0.0;
protected float $total_fee = 0.0;
protected string $locale = 'en';
+ protected ?string $reserved_until = null;
public function toArray(): array
{
@@ -87,7 +87,6 @@ abstract class OrderDomainObjectAbstract extends \HiEvents\DomainObjects\Abstrac
'status' => $this->status ?? null,
'payment_status' => $this->payment_status ?? null,
'refund_status' => $this->refund_status ?? null,
- 'reserved_until' => $this->reserved_until ?? null,
'is_manually_created' => $this->is_manually_created ?? null,
'session_id' => $this->session_id ?? null,
'public_id' => $this->public_id ?? null,
@@ -102,6 +101,7 @@ abstract class OrderDomainObjectAbstract extends \HiEvents\DomainObjects\Abstrac
'total_tax' => $this->total_tax ?? null,
'total_fee' => $this->total_fee ?? null,
'locale' => $this->locale ?? null,
+ 'reserved_until' => $this->reserved_until ?? null,
];
}
@@ -259,17 +259,6 @@ abstract class OrderDomainObjectAbstract extends \HiEvents\DomainObjects\Abstrac
return $this->refund_status;
}
- public function setReservedUntil(?string $reserved_until): self
- {
- $this->reserved_until = $reserved_until;
- return $this;
- }
-
- public function getReservedUntil(): ?string
- {
- return $this->reserved_until;
- }
-
public function setIsManuallyCreated(bool $is_manually_created): self
{
$this->is_manually_created = $is_manually_created;
@@ -423,4 +412,15 @@ abstract class OrderDomainObjectAbstract extends \HiEvents\DomainObjects\Abstrac
{
return $this->locale;
}
+
+ public function setReservedUntil(?string $reserved_until): self
+ {
+ $this->reserved_until = $reserved_until;
+ return $this;
+ }
+
+ public function getReservedUntil(): ?string
+ {
+ return $this->reserved_until;
+ }
}
diff --git a/backend/app/DomainObjects/Generated/TicketCapacityAssignmentDomainObjectAbstract.php b/backend/app/DomainObjects/Generated/TicketCapacityAssignmentDomainObjectAbstract.php
new file mode 100644
index 000000000..40ed85936
--- /dev/null
+++ b/backend/app/DomainObjects/Generated/TicketCapacityAssignmentDomainObjectAbstract.php
@@ -0,0 +1,104 @@
+<?php
+
+namespace HiEvents\DomainObjects\Generated;
+
+/**
+ * THIS FILE IS AUTOGENERATED - DO NOT EDIT IT DIRECTLY.
+ * @package HiEvents\DomainObjects\Generated
+ */
+abstract class TicketCapacityAssignmentDomainObjectAbstract extends \HiEvents\DomainObjects\AbstractDomainObject
+{
+ final public const SINGULAR_NAME = 'ticket_capacity_assignment';
+ final public const PLURAL_NAME = 'ticket_capacity_assignments';
+ final public const ID = 'id';
+ final public const TICKET_ID = 'ticket_id';
+ final public const CAPACITY_ASSIGNMENT_ID = 'capacity_assignment_id';
+ final public const CREATED_AT = 'created_at';
+ final public const UPDATED_AT = 'updated_at';
+ final public const DELETED_AT = 'deleted_at';
+
+ protected int $id;
+ protected int $ticket_id;
+ protected int $capacity_assignment_id;
+ protected ?string $created_at = null;
+ protected ?string $updated_at = null;
+ protected ?string $deleted_at = null;
+
+ public function toArray(): array
+ {
+ return [
+ 'id' => $this->id ?? null,
+ 'ticket_id' => $this->ticket_id ?? null,
+ 'capacity_assignment_id' => $this->capacity_assignment_id ?? null,
+ 'created_at' => $this->created_at ?? null,
+ 'updated_at' => $this->updated_at ?? null,
+ 'deleted_at' => $this->deleted_at ?? null,
+ ];
+ }
+
+ public function setId(int $id): self
+ {
+ $this->id = $id;
+ return $this;
+ }
+
+ public function getId(): int
+ {
+ return $this->id;
+ }
+
+ public function setTicketId(int $ticket_id): self
+ {
+ $this->ticket_id = $ticket_id;
+ return $this;
+ }
+
+ public function getTicketId(): int
+ {
+ return $this->ticket_id;
+ }
+
+ public function setCapacityAssignmentId(int $capacity_assignment_id): self
+ {
+ $this->capacity_assignment_id = $capacity_assignment_id;
+ return $this;
+ }
+
+ public function getCapacityAssignmentId(): int
+ {
+ return $this->capacity_assignment_id;
+ }
+
+ public function setCreatedAt(?string $created_at): self
+ {
+ $this->created_at = $created_at;
+ return $this;
+ }
+
+ public function getCreatedAt(): ?string
+ {
+ return $this->created_at;
+ }
+
+ public function setUpdatedAt(?string $updated_at): self
+ {
+ $this->updated_at = $updated_at;
+ return $this;
+ }
+
+ public function getUpdatedAt(): ?string
+ {
+ return $this->updated_at;
+ }
+
+ public function setDeletedAt(?string $deleted_at): self
+ {
+ $this->deleted_at = $deleted_at;
+ return $this;
+ }
+
+ public function getDeletedAt(): ?string
+ {
+ return $this->deleted_at;
+ }
+}
diff --git a/backend/app/DomainObjects/Generated/TicketPriceDomainObjectAbstract.php b/backend/app/DomainObjects/Generated/TicketPriceDomainObjectAbstract.php
index 1f9f33cf9..c6e47272c 100644
--- a/backend/app/DomainObjects/Generated/TicketPriceDomainObjectAbstract.php
+++ b/backend/app/DomainObjects/Generated/TicketPriceDomainObjectAbstract.php
@@ -23,6 +23,7 @@ abstract class TicketPriceDomainObjectAbstract extends \HiEvents\DomainObjects\A
final public const QUANTITY_SOLD = 'quantity_sold';
final public const IS_HIDDEN = 'is_hidden';
final public const ORDER = 'order';
+ final public const QUANTITY_AVAILABLE = 'quantity_available';
protected int $id;
protected int $ticket_id;
@@ -37,6 +38,7 @@ abstract class TicketPriceDomainObjectAbstract extends \HiEvents\DomainObjects\A
protected int $quantity_sold = 0;
protected ?bool $is_hidden = false;
protected int $order = 1;
+ protected ?int $quantity_available = null;
public function toArray(): array
{
@@ -54,6 +56,7 @@ abstract class TicketPriceDomainObjectAbstract extends \HiEvents\DomainObjects\A
'quantity_sold' => $this->quantity_sold ?? null,
'is_hidden' => $this->is_hidden ?? null,
'order' => $this->order ?? null,
+ 'quantity_available' => $this->quantity_available ?? null,
];
}
@@ -199,4 +202,15 @@ abstract class TicketPriceDomainObjectAbstract extends \HiEvents\DomainObjects\A
{
return $this->order;
}
+
+ public function setQuantityAvailable(?int $quantity_available): self
+ {
+ $this->quantity_available = $quantity_available;
+ return $this;
+ }
+
+ public function getQuantityAvailable(): ?int
+ {
+ return $this->quantity_available;
+ }
}
diff --git a/backend/app/DomainObjects/Status/CapacityAssignmentStatus.php b/backend/app/DomainObjects/Status/CapacityAssignmentStatus.php
new file mode 100644
index 000000000..0ac47e816
--- /dev/null
+++ b/backend/app/DomainObjects/Status/CapacityAssignmentStatus.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace HiEvents\DomainObjects\Status;
+
+use HiEvents\DomainObjects\Enums\BaseEnum;
+
+enum CapacityAssignmentStatus
+{
+ use BaseEnum;
+
+ case ACTIVE;
+ case INACTIVE;
+}
diff --git a/backend/app/DomainObjects/TicketCapacityAssignmentDomainObject.php b/backend/app/DomainObjects/TicketCapacityAssignmentDomainObject.php
new file mode 100644
index 000000000..307951d9d
--- /dev/null
+++ b/backend/app/DomainObjects/TicketCapacityAssignmentDomainObject.php
@@ -0,0 +1,7 @@
+<?php
+
+namespace HiEvents\DomainObjects;
+
+class TicketCapacityAssignmentDomainObject extends Generated\TicketCapacityAssignmentDomainObjectAbstract
+{
+}
diff --git a/backend/app/DomainObjects/TicketDomainObject.php b/backend/app/DomainObjects/TicketDomainObject.php
index 1d51237c2..bc054fa1e 100644
--- a/backend/app/DomainObjects/TicketDomainObject.php
+++ b/backend/app/DomainObjects/TicketDomainObject.php
@@ -108,7 +108,7 @@ class TicketDomainObject extends Generated\TicketDomainObjectAbstract implements
public function isAvailable(): bool
{
// If all prices are hidden, it's not available
- if ($this->getType() === TicketType::TIERED->name && $this->getTicketPrices()->isEmpty()) {
+ if ($this->getType() === TicketType::TIERED->name && $this->getTicketPrices()?->isEmpty()) {
return false;
}
diff --git a/backend/app/DomainObjects/TicketPriceDomainObject.php b/backend/app/DomainObjects/TicketPriceDomainObject.php
index 413390160..769528d44 100644
--- a/backend/app/DomainObjects/TicketPriceDomainObject.php
+++ b/backend/app/DomainObjects/TicketPriceDomainObject.php
@@ -14,8 +14,6 @@ class TicketPriceDomainObject extends Generated\TicketPriceDomainObjectAbstract
private ?float $feeTotal = null;
- private ?int $quantityAvailable = null;
-
private ?bool $isAvailable = null;
public function getPriceBeforeDiscount(): ?float
@@ -91,17 +89,6 @@ class TicketPriceDomainObject extends Generated\TicketPriceDomainObjectAbstract
return $this->getQuantitySold() >= $this->getInitialQuantityAvailable();
}
- public function setQuantityAvailable(?int $quantityAvailable): TicketPriceDomainObject
- {
- $this->quantityAvailable = $quantityAvailable;
- return $this;
- }
-
- public function getQuantityAvailable(): ?int
- {
- return $this->quantityAvailable;
- }
-
public function isAvailable(): ?bool
{
return $this->isAvailable;
diff --git a/backend/app/Http/Actions/CapacityAssignments/CreateCapacityAssignmentAction.php b/backend/app/Http/Actions/CapacityAssignments/CreateCapacityAssignmentAction.php
new file mode 100644
index 000000000..5da2daf1a
--- /dev/null
+++ b/backend/app/Http/Actions/CapacityAssignments/CreateCapacityAssignmentAction.php
@@ -0,0 +1,50 @@
+<?php
+
+namespace HiEvents\Http\Actions\CapacityAssignments;
+
+use HiEvents\DomainObjects\EventDomainObject;
+use HiEvents\Http\Actions\BaseAction;
+use HiEvents\Http\Request\CapacityAssigment\UpsertCapacityAssignmentRequest;
+use HiEvents\Resources\CapacityAssignment\CapacityAssignmentResource;
+use HiEvents\Services\Domain\Ticket\Exception\UnrecognizedTicketIdException;
+use HiEvents\Services\Handlers\CapacityAssignment\CreateCapacityAssignmentHandler;
+use HiEvents\Services\Handlers\CapacityAssignment\DTO\UpsertCapacityAssignmentDTO;
+use Illuminate\Http\JsonResponse;
+use Symfony\Component\HttpFoundation\Response;
+
+class CreateCapacityAssignmentAction extends BaseAction
+{
+ public function __construct(
+ private readonly CreateCapacityAssignmentHandler $createCapacityAssignmentHandler
+ )
+ {
+ }
+
+ public function __invoke(int $eventId, UpsertCapacityAssignmentRequest $request): JsonResponse
+ {
+ $this->isActionAuthorized($eventId, EventDomainObject::class);
+
+ try {
+ $assignment = $this->createCapacityAssignmentHandler->handle(
+ UpsertCapacityAssignmentDTO::fromArray([
+ 'name' => $request->validated('name'),
+ 'event_id' => $eventId,
+ 'capacity' => $request->validated('capacity'),
+ 'applies_to' => $request->validated('applies_to'),
+ 'status' => $request->validated('status'),
+ 'ticket_ids' => $request->validated('ticket_ids'),
+ ]),
+ );
+ } catch (UnrecognizedTicketIdException $exception) {
+ return $this->errorResponse(
+ message: $exception->getMessage(),
+ statusCode: Response::HTTP_UNPROCESSABLE_ENTITY,
+ );
+ }
+
+ return $this->resourceResponse(
+ resource: CapacityAssignmentResource::class,
+ data: $assignment,
+ );
+ }
+}
diff --git a/backend/app/Http/Actions/CapacityAssignments/DeleteCapacityAssignmentAction.php b/backend/app/Http/Actions/CapacityAssignments/DeleteCapacityAssignmentAction.php
new file mode 100644
index 000000000..e1062a600
--- /dev/null
+++ b/backend/app/Http/Actions/CapacityAssignments/DeleteCapacityAssignmentAction.php
@@ -0,0 +1,29 @@
+<?php
+
+namespace HiEvents\Http\Actions\CapacityAssignments;
+
+use HiEvents\DomainObjects\EventDomainObject;
+use HiEvents\Http\Actions\BaseAction;
+use HiEvents\Services\Handlers\CapacityAssignment\DeleteCapacityAssignmentHandler;
+use Illuminate\Http\Response;
+
+class DeleteCapacityAssignmentAction extends BaseAction
+{
+ public function __construct(
+ private readonly DeleteCapacityAssignmentHandler $deleteCapacityAssignmentHandler
+ )
+ {
+ }
+
+ public function __invoke(int $eventId, int $capacityAssignmentId): Response
+ {
+ $this->isActionAuthorized($eventId, EventDomainObject::class);
+
+ $this->deleteCapacityAssignmentHandler->handle(
+ $capacityAssignmentId,
+ $eventId,
+ );
+
+ return $this->noContentResponse();
+ }
+}
diff --git a/backend/app/Http/Actions/CapacityAssignments/GetCapacityAssignmentsAction.php b/backend/app/Http/Actions/CapacityAssignments/GetCapacityAssignmentsAction.php
new file mode 100644
index 000000000..3fa850a8c
--- /dev/null
+++ b/backend/app/Http/Actions/CapacityAssignments/GetCapacityAssignmentsAction.php
@@ -0,0 +1,33 @@
+<?php
+
+namespace HiEvents\Http\Actions\CapacityAssignments;
+
+use HiEvents\DomainObjects\EventDomainObject;
+use HiEvents\Http\Actions\BaseAction;
+use HiEvents\Resources\CapacityAssignment\CapacityAssignmentResource;
+use HiEvents\Services\Handlers\CapacityAssignment\DTO\GetCapacityAssignmentsDTO;
+use HiEvents\Services\Handlers\CapacityAssignment\GetCapacityAssignmentsHandler;
+use Illuminate\Http\JsonResponse;
+
+class GetCapacityAssignmentsAction extends BaseAction
+{
+ public function __construct(
+ private readonly GetCapacityAssignmentsHandler $getCapacityAssignmentsHandler,
+ )
+ {
+ }
+
+ public function __invoke(int $eventId): JsonResponse
+ {
+ $this->isActionAuthorized($eventId, EventDomainObject::class);
+
+ return $this->resourceResponse(
+ resource: CapacityAssignmentResource::class,
+ data: $this->getCapacityAssignmentsHandler->handle(
+ GetCapacityAssignmentsDTO::fromArray([
+ 'eventId' => $eventId,
+ ]),
+ ),
+ );
+ }
+}
diff --git a/backend/app/Http/Actions/CapacityAssignments/UpdateCapacityAssignmentAction.php b/backend/app/Http/Actions/CapacityAssignments/UpdateCapacityAssignmentAction.php
new file mode 100644
index 000000000..01af83fbb
--- /dev/null
+++ b/backend/app/Http/Actions/CapacityAssignments/UpdateCapacityAssignmentAction.php
@@ -0,0 +1,51 @@
+<?php
+
+namespace HiEvents\Http\Actions\CapacityAssignments;
+
+use HiEvents\DomainObjects\EventDomainObject;
+use HiEvents\Http\Actions\BaseAction;
+use HiEvents\Http\Request\CapacityAssigment\UpsertCapacityAssignmentRequest;
+use HiEvents\Resources\CapacityAssignment\CapacityAssignmentResource;
+use HiEvents\Services\Domain\Ticket\Exception\UnrecognizedTicketIdException;
+use HiEvents\Services\Handlers\CapacityAssignment\DTO\UpsertCapacityAssignmentDTO;
+use HiEvents\Services\Handlers\CapacityAssignment\UpdateCapacityAssignmentHandler;
+use Illuminate\Http\JsonResponse;
+use Symfony\Component\HttpFoundation\Response;
+
+class UpdateCapacityAssignmentAction extends BaseAction
+{
+ public function __construct(
+ private readonly UpdateCapacityAssignmentHandler $updateCapacityAssignmentHandler
+ )
+ {
+ }
+
+ public function __invoke(int $eventId, int $capacityAssignmentId, UpsertCapacityAssignmentRequest $request): JsonResponse
+ {
+ $this->isActionAuthorized($eventId, EventDomainObject::class);
+
+ try {
+ $assignment = $this->updateCapacityAssignmentHandler->handle(
+ UpsertCapacityAssignmentDTO::fromArray([
+ 'id' => $capacityAssignmentId,
+ 'name' => $request->validated('name'),
+ 'event_id' => $eventId,
+ 'capacity' => $request->validated('capacity'),
+ 'applies_to' => $request->validated('applies_to'),
+ 'status' => $request->validated('status'),
+ 'ticket_ids' => $request->validated('ticket_ids'),
+ ]),
+ );
+ } catch (UnrecognizedTicketIdException $exception) {
+ return $this->errorResponse(
+ message: $exception->getMessage(),
+ statusCode: Response::HTTP_UNPROCESSABLE_ENTITY,
+ );
+ }
+
+ return $this->resourceResponse(
+ resource: CapacityAssignmentResource::class,
+ data: $assignment,
+ );
+ }
+}
diff --git a/backend/app/Http/Request/CapacityAssigment/UpsertCapacityAssignmentRequest.php b/backend/app/Http/Request/CapacityAssigment/UpsertCapacityAssignmentRequest.php
new file mode 100644
index 000000000..8d37eb28b
--- /dev/null
+++ b/backend/app/Http/Request/CapacityAssigment/UpsertCapacityAssignmentRequest.php
@@ -0,0 +1,30 @@
+<?php
+
+namespace HiEvents\Http\Request\CapacityAssigment;
+
+use HiEvents\DomainObjects\Enums\CapacityAssignmentAppliesTo;
+use HiEvents\DomainObjects\Status\CapacityAssignmentStatus;
+use HiEvents\Http\Request\BaseRequest;
+use HiEvents\Validators\Rules\RulesHelper;
+use Illuminate\Validation\Rule;
+
+class UpsertCapacityAssignmentRequest extends BaseRequest
+{
+ public function rules(): array
+ {
+ return [
+ 'name' => RulesHelper::REQUIRED_STRING,
+ 'capacity' => ['nullable', 'numeric', 'min:1'],
+ 'applies_to' => [Rule::in(CapacityAssignmentAppliesTo::valuesArray())],
+ 'status' => [Rule::in(CapacityAssignmentStatus::valuesArray())],
+ 'ticket_ids' => ['nullable', 'required_if:applies_to,' . CapacityAssignmentAppliesTo::TICKETS->name, 'array'],
+ ];
+ }
+
+ public function messages(): array
+ {
+ return [
+ 'ticket_ids.required_if' => __('Please select at least one ticket.'),
+ ];
+ }
+}
diff --git a/backend/app/Models/CapacityAssignment.php b/backend/app/Models/CapacityAssignment.php
new file mode 100644
index 000000000..7359f9455
--- /dev/null
+++ b/backend/app/Models/CapacityAssignment.php
@@ -0,0 +1,32 @@
+<?php
+
+namespace HiEvents\Models;
+
+use Illuminate\Database\Eloquent\Relations\BelongsTo;
+use Illuminate\Database\Eloquent\Relations\BelongsToMany;
+
+class CapacityAssignment extends BaseModel
+{
+ protected function getCastMap(): array
+ {
+ return [];
+ }
+
+ protected function getFillableFields(): array
+ {
+ return [];
+ }
+
+ public function event(): BelongsTo
+ {
+ return $this->belongsTo(Event::class);
+ }
+
+ public function tickets(): BelongsToMany
+ {
+ return $this->belongsToMany(
+ related: Ticket::class,
+ table: 'ticket_capacity_assignments',
+ );
+ }
+}
diff --git a/backend/app/Models/Event.php b/backend/app/Models/Event.php
index 5fe2e6101..e559180bc 100644
--- a/backend/app/Models/Event.php
+++ b/backend/app/Models/Event.php
@@ -48,6 +48,7 @@ class Event extends BaseModel
{
parent::boot();
+ // todo - move into a domain service
static::creating(
static function (Event $event) {
$event->user_id = auth()->user()->id;
diff --git a/backend/app/Models/Ticket.php b/backend/app/Models/Ticket.php
index add6831a2..1d406188d 100644
--- a/backend/app/Models/Ticket.php
+++ b/backend/app/Models/Ticket.php
@@ -37,4 +37,9 @@ class Ticket extends BaseModel
{
return $this->belongsToMany(TaxAndFee::class, 'ticket_taxes_and_fees');
}
+
+ public function capacity_assignments(): BelongsToMany
+ {
+ return $this->belongsToMany(CapacityAssignment::class, 'ticket_capacity_assignments');
+ }
}
diff --git a/backend/app/Providers/RepositoryServiceProvider.php b/backend/app/Providers/RepositoryServiceProvider.php
index 5fae882c0..d5317967f 100644
--- a/backend/app/Providers/RepositoryServiceProvider.php
+++ b/backend/app/Providers/RepositoryServiceProvider.php
@@ -7,6 +7,7 @@ namespace HiEvents\Providers;
use HiEvents\Repository\Eloquent\AccountRepository;
use HiEvents\Repository\Eloquent\AccountUserRepository;
use HiEvents\Repository\Eloquent\AttendeeRepository;
+use HiEvents\Repository\Eloquent\CapacityAssignmentRepository;
use HiEvents\Repository\Eloquent\EventDailyStatisticRepository;
use HiEvents\Repository\Eloquent\EventRepository;
use HiEvents\Repository\Eloquent\EventSettingsRepository;
@@ -21,6 +22,7 @@ use HiEvents\Repository\Eloquent\PasswordResetTokenRepository;
use HiEvents\Repository\Eloquent\PromoCodeRepository;
use HiEvents\Repository\Eloquent\QuestionAnswerRepository;
use HiEvents\Repository\Eloquent\QuestionRepository;
+use HiEvents\Repository\Eloquent\ReservationRepository;
use HiEvents\Repository\Eloquent\StripePaymentsRepository;
use HiEvents\Repository\Eloquent\TaxAndFeeRepository;
use HiEvents\Repository\Eloquent\TicketPriceRepository;
@@ -29,6 +31,7 @@ use HiEvents\Repository\Eloquent\UserRepository;
use HiEvents\Repository\Interfaces\AccountRepositoryInterface;
use HiEvents\Repository\Interfaces\AccountUserRepositoryInterface;
use HiEvents\Repository\Interfaces\AttendeeRepositoryInterface;
+use HiEvents\Repository\Interfaces\CapacityAssignmentRepositoryInterface;
use HiEvents\Repository\Interfaces\EventDailyStatisticRepositoryInterface;
use HiEvents\Repository\Interfaces\EventRepositoryInterface;
use HiEvents\Repository\Interfaces\EventSettingsRepositoryInterface;
@@ -43,6 +46,7 @@ use HiEvents\Repository\Interfaces\PasswordResetTokenRepositoryInterface;
use HiEvents\Repository\Interfaces\PromoCodeRepositoryInterface;
use HiEvents\Repository\Interfaces\QuestionAnswerRepositoryInterface;
use HiEvents\Repository\Interfaces\QuestionRepositoryInterface;
+use HiEvents\Repository\Interfaces\ReservationRepositoryInterface;
use HiEvents\Repository\Interfaces\StripePaymentsRepositoryInterface;
use HiEvents\Repository\Interfaces\TaxAndFeeRepositoryInterface;
use HiEvents\Repository\Interfaces\TicketPriceRepositoryInterface;
@@ -78,6 +82,8 @@ class RepositoryServiceProvider extends ServiceProvider
EventSettingsRepositoryInterface::class => EventSettingsRepository::class,
OrganizerRepositoryInterface::class => OrganizerRepository::class,
AccountUserRepositoryInterface::class => AccountUserRepository::class,
+ CapacityAssignmentRepositoryInterface::class => CapacityAssignmentRepository::class,
+ ReservationRepositoryInterface::class => ReservationRepository::class,
];
public function register(): void
diff --git a/backend/app/Repository/Eloquent/AttendeeRepository.php b/backend/app/Repository/Eloquent/AttendeeRepository.php
index 28b236699..87702d06d 100644
--- a/backend/app/Repository/Eloquent/AttendeeRepository.php
+++ b/backend/app/Repository/Eloquent/AttendeeRepository.php
@@ -2,16 +2,16 @@
namespace HiEvents\Repository\Eloquent;
-use Illuminate\Database\Eloquent\Builder;
-use Illuminate\Pagination\LengthAwarePaginator;
-use Illuminate\Support\Collection;
-use Illuminate\Support\Facades\DB;
use HiEvents\DomainObjects\AttendeeDomainObject;
use HiEvents\DomainObjects\Generated\AttendeeDomainObjectAbstract;
use HiEvents\DomainObjects\Status\OrderStatus;
use HiEvents\Http\DTO\QueryParamsDTO;
use HiEvents\Models\Attendee;
use HiEvents\Repository\Interfaces\AttendeeRepositoryInterface;
+use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Pagination\LengthAwarePaginator;
+use Illuminate\Support\Collection;
+use Illuminate\Support\Facades\DB;
class AttendeeRepository extends BaseRepository implements AttendeeRepositoryInterface
{
diff --git a/backend/app/Repository/Eloquent/BaseRepository.php b/backend/app/Repository/Eloquent/BaseRepository.php
index 0bee98ac0..da3ce5c37 100644
--- a/backend/app/Repository/Eloquent/BaseRepository.php
+++ b/backend/app/Repository/Eloquent/BaseRepository.php
@@ -15,7 +15,6 @@ use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use HiEvents\DomainObjects\Interfaces\DomainObjectInterface;
-use HiEvents\DomainObjects\Interfaces\HasDefaultEagerLoads;
use HiEvents\Models\BaseModel;
use HiEvents\Repository\Eloquent\Value\Relationship;
use HiEvents\Repository\Interfaces\RepositoryInterface;
diff --git a/backend/app/Repository/Eloquent/CapacityAssignmentRepository.php b/backend/app/Repository/Eloquent/CapacityAssignmentRepository.php
new file mode 100644
index 000000000..422a3ea1d
--- /dev/null
+++ b/backend/app/Repository/Eloquent/CapacityAssignmentRepository.php
@@ -0,0 +1,20 @@
+<?php
+
+namespace HiEvents\Repository\Eloquent;
+
+use HiEvents\DomainObjects\CapacityAssignmentDomainObject;
+use HiEvents\Models\CapacityAssignment;
+use HiEvents\Repository\Interfaces\CapacityAssignmentRepositoryInterface;
+
+class CapacityAssignmentRepository extends BaseRepository implements CapacityAssignmentRepositoryInterface
+{
+ protected function getModel(): string
+ {
+ return CapacityAssignment::class;
+ }
+
+ public function getDomainObject(): string
+ {
+ return CapacityAssignmentDomainObject::class;
+ }
+}
diff --git a/backend/app/Repository/Eloquent/EventRepository.php b/backend/app/Repository/Eloquent/EventRepository.php
index 66f6e63ca..86e62b710 100644
--- a/backend/app/Repository/Eloquent/EventRepository.php
+++ b/backend/app/Repository/Eloquent/EventRepository.php
@@ -4,15 +4,15 @@ declare(strict_types=1);
namespace HiEvents\Repository\Eloquent;
-use Illuminate\Database\Eloquent\Builder;
-use Illuminate\Pagination\LengthAwarePaginator;
-use Illuminate\Support\Collection;
use HiEvents\DomainObjects\EventDomainObject;
use HiEvents\DomainObjects\Generated\EventDomainObjectAbstract;
use HiEvents\DomainObjects\Status\OrderStatus;
use HiEvents\Http\DTO\QueryParamsDTO;
use HiEvents\Models\Event;
use HiEvents\Repository\Interfaces\EventRepositoryInterface;
+use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Pagination\LengthAwarePaginator;
+use Illuminate\Support\Collection;
class EventRepository extends BaseRepository implements EventRepositoryInterface
{
@@ -52,34 +52,59 @@ class EventRepository extends BaseRepository implements EventRepositoryInterface
$reserved = OrderStatus::RESERVED->name;
$query = <<<SQL
- SELECT tickets.id as ticket_id,
- ticket_prices.id as price_id,
- tickets.title as ticket_title,
- ticket_prices.label as price_label,
- (ticket_prices.initial_quantity_available - ticket_prices.quantity_sold -
- COALESCE(reserved_quantities.quantity_reserved, 0)) AS quantity_available
- FROM ticket_prices
- INNER JOIN
- tickets ON ticket_prices.ticket_id = tickets.id
- LEFT JOIN
- (SELECT order_items.ticket_id,
- order_items.ticket_price_id,
- SUM(order_items.quantity) AS quantity_reserved
- FROM orders
- INNER JOIN
- order_items ON order_items.order_id = orders.id
- WHERE orders.event_id = $eventId
- AND orders.status = '$reserved'
- AND orders.reserved_until > NOW()
- AND orders.deleted_at IS NULL
- GROUP BY order_items.ticket_id, order_items.ticket_price_id) AS reserved_quantities
- ON ticket_prices.id = reserved_quantities.ticket_price_id
- WHERE tickets.event_id = $eventId
- AND tickets.deleted_at IS NULL
- AND ticket_prices.deleted_at IS NULL
- ORDER BY ticket_prices.id;
+ WITH reserved_quantities AS (
+ SELECT order_items.ticket_id,
+ order_items.ticket_price_id,
+ SUM(order_items.quantity) AS quantity_reserved
+ FROM orders
+ INNER JOIN order_items ON order_items.order_id = orders.id
+ WHERE orders.event_id = :eventId
+ AND orders.status = :reserved
+ AND orders.reserved_until > NOW()
+ AND orders.deleted_at IS NULL
+ GROUP BY order_items.ticket_id, order_items.ticket_price_id
+ ),
+ capacity_reserved AS (
+ SELECT ticket_capacity_assignments.ticket_id,
+ ticket_capacity_assignments.capacity_assignment_id,
+ SUM(order_items.quantity) AS quantity_reserved
+ FROM orders
+ INNER JOIN order_items ON order_items.order_id = orders.id
+ INNER JOIN ticket_capacity_assignments ON order_items.ticket_id = ticket_capacity_assignments.ticket_id
+ WHERE orders.event_id = :eventId
+ AND orders.status = :reserved
+ AND orders.reserved_until > NOW()
+ AND orders.deleted_at IS NULL
+ GROUP BY ticket_capacity_assignments.ticket_id, ticket_capacity_assignments.capacity_assignment_id
+ ),
+ min_capacity AS (
+ SELECT ticket_capacity_assignments.ticket_id,
+ MIN(capacity_assignments.capacity - capacity_assignments.used_capacity - COALESCE(capacity_reserved.quantity_reserved, 0)) AS remaining_capacity
+ FROM ticket_capacity_assignments
+ INNER JOIN capacity_assignments ON ticket_capacity_assignments.capacity_assignment_id = capacity_assignments.id
+ LEFT JOIN capacity_reserved ON ticket_capacity_assignments.ticket_id = capacity_reserved.ticket_id
+ AND ticket_capacity_assignments.capacity_assignment_id = capacity_reserved.capacity_assignment_id
+ WHERE capacity_assignments.deleted_at IS NULL
+ GROUP BY ticket_capacity_assignments.ticket_id
+ )
+ SELECT
+ tickets.id AS ticket_id,
+ ticket_prices.id AS price_id,
+ tickets.title AS ticket_title,
+ ticket_prices.label AS price_label,
+ LEAST(
+ ticket_prices.initial_quantity_available - ticket_prices.quantity_sold - COALESCE(reserved_quantities.quantity_reserved, 0),
+ COALESCE(min_capacity.remaining_capacity, ticket_prices.initial_quantity_available - ticket_prices.quantity_sold - COALESCE(reserved_quantities.quantity_reserved, 0))
+ ) AS quantity_available
+ FROM ticket_prices
+ INNER JOIN tickets ON ticket_prices.ticket_id = tickets.id
+ LEFT JOIN reserved_quantities ON ticket_prices.id = reserved_quantities.ticket_price_id
+ LEFT JOIN min_capacity ON tickets.id = min_capacity.ticket_id
+ WHERE tickets.event_id = :eventId
+ AND tickets.deleted_at IS NULL
+ AND ticket_prices.deleted_at IS NULL
+ ORDER BY ticket_prices.id;
SQL;
-
- return collect($this->db->select($query));
+ return collect($this->db->select($query, ['eventId' => $eventId, 'reserved' => $reserved]));
}
}
diff --git a/backend/app/Repository/Eloquent/OrderRepository.php b/backend/app/Repository/Eloquent/OrderRepository.php
index c01a680a8..ca3c729fb 100644
--- a/backend/app/Repository/Eloquent/OrderRepository.php
+++ b/backend/app/Repository/Eloquent/OrderRepository.php
@@ -4,9 +4,6 @@ declare(strict_types=1);
namespace HiEvents\Repository\Eloquent;
-use Illuminate\Contracts\Pagination\LengthAwarePaginator;
-use Illuminate\Database\Eloquent\Builder;
-use Illuminate\Support\Facades\DB;
use HiEvents\DomainObjects\AttendeeDomainObject;
use HiEvents\DomainObjects\Generated\OrderDomainObjectAbstract;
use HiEvents\DomainObjects\OrderDomainObject;
@@ -16,6 +13,9 @@ use HiEvents\Http\DTO\QueryParamsDTO;
use HiEvents\Models\Order;
use HiEvents\Models\OrderItem;
use HiEvents\Repository\Interfaces\OrderRepositoryInterface;
+use Illuminate\Contracts\Pagination\LengthAwarePaginator;
+use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Support\Facades\DB;
class OrderRepository extends BaseRepository implements OrderRepositoryInterface
{
@@ -87,6 +87,27 @@ class OrderRepository extends BaseRepository implements OrderRepositoryInterface
return $this->findFirstByField('short_id', $orderShortId);
}
+ public function getReservedQuantityForTicketPrice(int $ticketId, int $ticketPriceId): int
+ {
+ $query = <<<SQL
+ SELECT COALESCE(SUM(order_items.quantity), 0) as reserved_quantity
+ FROM orders
+ INNER JOIN order_items ON orders.id = order_items.order_id
+ WHERE order_items.ticket_id = :ticketId AND order_items.ticket_price_id = :ticketPriceId
+ AND orders.status = 'RESERVED'
+ AND current_timestamp < orders.reserved_until
+ AND orders.deleted_at IS NULL
+ AND order_items.deleted_at IS NULL
+ SQL;
+
+ $result = $this->db->selectOne($query, [
+ 'ticketId' => $ticketId,
+ 'ticketPriceId' => $ticketPriceId,
+ ]);
+
+ return (int)$result->reserved_quantity;
+ }
+
public function getDomainObject(): string
{
return OrderDomainObject::class;
diff --git a/backend/app/Repository/Eloquent/TicketRepository.php b/backend/app/Repository/Eloquent/TicketRepository.php
index 1a6cc9103..f8b136757 100644
--- a/backend/app/Repository/Eloquent/TicketRepository.php
+++ b/backend/app/Repository/Eloquent/TicketRepository.php
@@ -4,16 +4,20 @@ declare(strict_types=1);
namespace HiEvents\Repository\Eloquent;
-use Illuminate\Database\Eloquent\Builder;
-use Illuminate\Pagination\LengthAwarePaginator;
-use Illuminate\Support\Collection;
use HiEvents\Constants;
+use HiEvents\DomainObjects\CapacityAssignmentDomainObject;
use HiEvents\DomainObjects\Generated\TicketDomainObjectAbstract;
use HiEvents\DomainObjects\TaxAndFeesDomainObject;
use HiEvents\DomainObjects\TicketDomainObject;
use HiEvents\Http\DTO\QueryParamsDTO;
+use HiEvents\Models\CapacityAssignment;
use HiEvents\Models\Ticket;
use HiEvents\Repository\Interfaces\TicketRepositoryInterface;
+use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Pagination\LengthAwarePaginator;
+use Illuminate\Support\Collection;
+use Illuminate\Support\Facades\DB;
+use RuntimeException;
class TicketRepository extends BaseRepository implements TicketRepositoryInterface
{
@@ -73,6 +77,10 @@ class TicketRepository extends BaseRepository implements TicketRepositoryInterfa
'ticketId' => $ticketId
]);
+ if ($result === null) {
+ throw new RuntimeException('Ticket price not found');
+ }
+
if ($result->unlimited_tickets_available) {
return Constants::INFINITE;
}
@@ -87,6 +95,7 @@ class TicketRepository extends BaseRepository implements TicketRepositoryInterfa
FROM ticket_taxes_and_fees ttf
INNER JOIN taxes_and_fees tf ON tf.id = ttf.tax_and_fee_id
WHERE ttf.ticket_id = :ticketId
+ AND tf.deleted_at IS NULL
SQL;
$taxAndFees = $this->db->select($query, [
@@ -103,6 +112,7 @@ class TicketRepository extends BaseRepository implements TicketRepositoryInterfa
FROM ticket_taxes_and_fees ttf
INNER JOIN tickets t ON t.id = ttf.ticket_id
WHERE ttf.tax_and_fee_id = :taxAndFeeId
+ AND t.deleted_at IS NULL
SQL;
$tickets = $this->model->select($query, [
@@ -112,11 +122,34 @@ class TicketRepository extends BaseRepository implements TicketRepositoryInterfa
return $this->handleResults($tickets, TicketDomainObject::class);
}
- public function addTaxToTicket(int $ticketId, array $taxIds): void
+ public function getCapacityAssignmentsByTicketId(int $ticketId): Collection
+ {
+ /** @var Ticket $ticket */
+ $ticket = $this->model->findOrFail($ticketId);
+ $capacityAssignments = $ticket->capacity_assignments()->get();
+
+ return $this->handleResults($capacityAssignments, CapacityAssignmentDomainObject::class);
+ }
+
+ public function addTaxesAndFeesToTicket(int $ticketId, array $taxIds): void
{
Ticket::findOrFail($ticketId)?->tax_and_fees()->sync($taxIds);
}
+ public function addCapacityAssignmentToTickets(int $capacityAssignmentId, array $ticketIds): void
+ {
+ Ticket::whereIn('id', $ticketIds)->each(function (Ticket $ticket) use ($capacityAssignmentId) {
+ $ticket->capacity_assignments()->syncWithoutDetaching([$capacityAssignmentId]);
+ });
+ }
+
+ public function removeCapacityAssignmentFromTickets(int $capacityAssignmentId): void
+ {
+ $capacityAssignment = CapacityAssignment::find($capacityAssignmentId);
+
+ $capacityAssignment?->tickets()->detach();
+ }
+
public function sortTickets(int $eventId, array $orderedTicketIds): void
{
$parameters = [
diff --git a/backend/app/Repository/Interfaces/CapacityAssignmentRepositoryInterface.php b/backend/app/Repository/Interfaces/CapacityAssignmentRepositoryInterface.php
new file mode 100644
index 000000000..7c0c042b3
--- /dev/null
+++ b/backend/app/Repository/Interfaces/CapacityAssignmentRepositoryInterface.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace HiEvents\Repository\Interfaces;
+
+use HiEvents\DomainObjects\CapacityAssignmentDomainObject;
+
+/**
+ * @extends RepositoryInterface<CapacityAssignmentDomainObject>
+ */
+interface CapacityAssignmentRepositoryInterface extends RepositoryInterface
+{
+
+}
diff --git a/backend/app/Repository/Interfaces/OrderRepositoryInterface.php b/backend/app/Repository/Interfaces/OrderRepositoryInterface.php
index 9baf7b100..7b6b49a34 100644
--- a/backend/app/Repository/Interfaces/OrderRepositoryInterface.php
+++ b/backend/app/Repository/Interfaces/OrderRepositoryInterface.php
@@ -24,4 +24,6 @@ interface OrderRepositoryInterface extends RepositoryInterface
public function addOrderItem(array $data): OrderItemDomainObject;
public function findByShortId(string $orderShortId): ?OrderDomainObject;
+
+ public function getReservedQuantityForTicketPrice(int $ticketId, int $ticketPriceId): int;
}
diff --git a/backend/app/Repository/Interfaces/TicketRepositoryInterface.php b/backend/app/Repository/Interfaces/TicketRepositoryInterface.php
index 88fa56adf..3b4501c30 100644
--- a/backend/app/Repository/Interfaces/TicketRepositoryInterface.php
+++ b/backend/app/Repository/Interfaces/TicketRepositoryInterface.php
@@ -41,12 +41,31 @@ interface TicketRepositoryInterface extends RepositoryInterface
*/
public function getTicketsByTaxId(int $taxId): Collection;
+ /**
+ * @param int $ticketId
+ * @return Collection
+ */
+ public function getCapacityAssignmentsByTicketId(int $ticketId): Collection;
+
/**
* @param int $ticketId
* @param array $taxIds
* @return void
*/
- public function addTaxToTicket(int $ticketId, array $taxIds): void;
+ public function addTaxesAndFeesToTicket(int $ticketId, array $taxIds): void;
+
+ /**
+ * @param array $ticketIds
+ * @param int $capacityAssignmentId
+ * @return void
+ */
+ public function addCapacityAssignmentToTickets(int $capacityAssignmentId, array $ticketIds): void;
+
+ /**
+ * @param int $capacityAssignmentId
+ * @return void
+ */
+ public function removeCapacityAssignmentFromTickets(int $capacityAssignmentId): void;
/**
* @param int $eventId
diff --git a/backend/app/Resources/CapacityAssignment/CapacityAssignmentResource.php b/backend/app/Resources/CapacityAssignment/CapacityAssignmentResource.php
new file mode 100644
index 000000000..af6af4626
--- /dev/null
+++ b/backend/app/Resources/CapacityAssignment/CapacityAssignmentResource.php
@@ -0,0 +1,37 @@
+<?php
+
+namespace HiEvents\Resources\CapacityAssignment;
+
+use HiEvents\DomainObjects\CapacityAssignmentDomainObject;
+use HiEvents\DomainObjects\Enums\CapacityAssignmentAppliesTo;
+use HiEvents\DomainObjects\TicketDomainObject;
+use HiEvents\Resources\BaseResource;
+use Illuminate\Http\Request;
+
+/**
+ * @mixin CapacityAssignmentDomainObject
+ */
+class CapacityAssignmentResource extends BaseResource
+{
+ public function toArray(Request $request): array
+ {
+ return [
+ 'id' => $this->getId(),
+ 'name' => $this->getName(),
+ 'capacity' => $this->getCapacity(),
+ 'used_capacity' => $this->getUsedCapacity(),
+ 'percentage_used' => $this->getPercentageUsed(),
+ 'applies_to' => $this->getAppliesTo(),
+ 'status' => $this->getStatus(),
+ 'event_id' => $this->getEventId(),
+ $this->mergeWhen(
+ condition: $this->getTickets() !== null && $this->getAppliesTo() === CapacityAssignmentAppliesTo::TICKETS->name,
+ value: [
+ 'tickets' => $this->getTickets()?->map(fn(TicketDomainObject $ticket) => [
+ 'id' => $ticket->getId(),
+ 'title' => $ticket->getTitle(),
+ ]),
+ ]),
+ ];
+ }
+}
diff --git a/backend/app/Services/Domain/CapacityAssignment/CapacityAssignmentTicketAssociationService.php b/backend/app/Services/Domain/CapacityAssignment/CapacityAssignmentTicketAssociationService.php
new file mode 100644
index 000000000..c5a0f5a2f
--- /dev/null
+++ b/backend/app/Services/Domain/CapacityAssignment/CapacityAssignmentTicketAssociationService.php
@@ -0,0 +1,53 @@
+<?php
+
+namespace HiEvents\Services\Domain\CapacityAssignment;
+
+use HiEvents\Repository\Interfaces\TicketRepositoryInterface;
+use Illuminate\Database\DatabaseManager;
+
+class CapacityAssignmentTicketAssociationService
+{
+ public function __construct(
+ private readonly TicketRepositoryInterface $ticketRepository,
+ public readonly DatabaseManager $databaseManager,
+ )
+ {
+ }
+
+ public function addCapacityToTickets(
+ int $capacityAssignmentId,
+ ?array $ticketIds,
+ bool $removePreviousAssignments = true
+ ): void
+ {
+ $this->databaseManager->transaction(function () use ($capacityAssignmentId, $ticketIds, $removePreviousAssignments) {
+ $this->associateTicketsWithCapacityAssignment(
+ capacityAssignmentId: $capacityAssignmentId,
+ ticketIds: $ticketIds,
+ removePreviousAssignments: $removePreviousAssignments,
+ );
+ });
+ }
+
+ private function associateTicketsWithCapacityAssignment(
+ int $capacityAssignmentId,
+ ?array $ticketIds,
+ bool $removePreviousAssignments = true
+ ): void
+ {
+ if (empty($ticketIds)) {
+ return;
+ }
+
+ if ($removePreviousAssignments) {
+ $this->ticketRepository->removeCapacityAssignmentFromTickets(
+ capacityAssignmentId: $capacityAssignmentId,
+ );
+ }
+
+ $this->ticketRepository->addCapacityAssignmentToTickets(
+ capacityAssignmentId: $capacityAssignmentId,
+ ticketIds: array_unique($ticketIds),
+ );
+ }
+}
diff --git a/backend/app/Services/Domain/CapacityAssignment/CreateCapacityAssignmentService.php b/backend/app/Services/Domain/CapacityAssignment/CreateCapacityAssignmentService.php
new file mode 100644
index 000000000..461cfa0ca
--- /dev/null
+++ b/backend/app/Services/Domain/CapacityAssignment/CreateCapacityAssignmentService.php
@@ -0,0 +1,60 @@
+<?php
+
+namespace HiEvents\Services\Domain\CapacityAssignment;
+
+use HiEvents\DomainObjects\CapacityAssignmentDomainObject;
+use HiEvents\DomainObjects\Enums\CapacityAssignmentAppliesTo;
+use HiEvents\DomainObjects\Generated\CapacityAssignmentDomainObjectAbstract;
+use HiEvents\Repository\Interfaces\CapacityAssignmentRepositoryInterface;
+use HiEvents\Services\Domain\Ticket\EventTicketValidationService;
+use HiEvents\Services\Domain\Ticket\Exception\UnrecognizedTicketIdException;
+use Illuminate\Database\DatabaseManager;
+
+class CreateCapacityAssignmentService
+{
+ public function __construct(
+ private readonly DatabaseManager $databaseManager,
+ private readonly CapacityAssignmentRepositoryInterface $capacityAssignmentRepository,
+ private readonly EventTicketValidationService $eventTicketValidationService,
+ private readonly CapacityAssignmentTicketAssociationService $capacityAssignmentTicketAssociationService,
+ )
+ {
+ }
+
+ /**
+ * @throws UnrecognizedTicketIdException
+ */
+ public function createCapacityAssignment(
+ CapacityAssignmentDomainObject $capacityAssignment,
+ ?array $ticketIds = null,
+ ): CapacityAssignmentDomainObject
+ {
+ $this->eventTicketValidationService->validateTicketIds($ticketIds, $capacityAssignment->getEventId());
+
+ return $this->persistAssignmentAndAssociateTickets($capacityAssignment, $ticketIds);
+ }
+
+ private function persistAssignmentAndAssociateTickets(CapacityAssignmentDomainObject $capacityAssignment, ?array $ticketIds): CapacityAssignmentDomainObject
+ {
+ return $this->databaseManager->transaction(function () use ($capacityAssignment, $ticketIds) {
+ /** @var CapacityAssignmentDomainObject $capacityAssignment */
+ $capacityAssignment = $this->capacityAssignmentRepository->create([
+ CapacityAssignmentDomainObjectAbstract::NAME => $capacityAssignment->getName(),
+ CapacityAssignmentDomainObjectAbstract::EVENT_ID => $capacityAssignment->getEventId(),
+ CapacityAssignmentDomainObjectAbstract::CAPACITY => $capacityAssignment->getCapacity(),
+ CapacityAssignmentDomainObjectAbstract::APPLIES_TO => $capacityAssignment->getAppliesTo(),
+ CapacityAssignmentDomainObjectAbstract::STATUS => $capacityAssignment->getStatus(),
+ ]);
+
+ if ($capacityAssignment->getAppliesTo() === CapacityAssignmentAppliesTo::TICKETS->name) {
+ $this->capacityAssignmentTicketAssociationService->addCapacityToTickets(
+ capacityAssignmentId: $capacityAssignment->getId(),
+ ticketIds: $ticketIds,
+ removePreviousAssignments: false,
+ );
+ }
+
+ return $capacityAssignment;
+ });
+ }
+}
diff --git a/backend/app/Services/Domain/CapacityAssignment/Exception/TicketsDoNotBelongToEventException.php b/backend/app/Services/Domain/CapacityAssignment/Exception/TicketsDoNotBelongToEventException.php
new file mode 100644
index 000000000..8e2cbefb8
--- /dev/null
+++ b/backend/app/Services/Domain/CapacityAssignment/Exception/TicketsDoNotBelongToEventException.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace HiEvents\Services\Domain\CapacityAssignment\Exception;
+
+use Exception;
+
+class TicketsDoNotBelongToEventException extends Exception
+{
+
+}
diff --git a/backend/app/Services/Domain/CapacityAssignment/UpdateCapacityAssignmentService.php b/backend/app/Services/Domain/CapacityAssignment/UpdateCapacityAssignmentService.php
new file mode 100644
index 000000000..769909f12
--- /dev/null
+++ b/backend/app/Services/Domain/CapacityAssignment/UpdateCapacityAssignmentService.php
@@ -0,0 +1,69 @@
+<?php
+
+namespace HiEvents\Services\Domain\CapacityAssignment;
+
+use HiEvents\DomainObjects\CapacityAssignmentDomainObject;
+use HiEvents\DomainObjects\Enums\CapacityAssignmentAppliesTo;
+use HiEvents\DomainObjects\Generated\CapacityAssignmentDomainObjectAbstract;
+use HiEvents\Repository\Interfaces\CapacityAssignmentRepositoryInterface;
+use HiEvents\Services\Domain\Ticket\EventTicketValidationService;
+use HiEvents\Services\Domain\Ticket\Exception\UnrecognizedTicketIdException;
+use Illuminate\Database\DatabaseManager;
+
+class UpdateCapacityAssignmentService
+{
+ public function __construct(
+ private readonly DatabaseManager $databaseManager,
+ private readonly CapacityAssignmentRepositoryInterface $capacityAssignmentRepository,
+ private readonly EventTicketValidationService $eventTicketValidationService,
+ private readonly CapacityAssignmentTicketAssociationService $capacityAssignmentTicketAssociationService,
+ )
+ {
+ }
+
+ /**
+ * @throws UnrecognizedTicketIdException
+ */
+ public function updateCapacityAssignment(
+ CapacityAssignmentDomainObject $capacityAssignment,
+ ?array $ticketIds = null,
+ ): CapacityAssignmentDomainObject
+ {
+ $this->eventTicketValidationService->validateTicketIds($ticketIds, $capacityAssignment->getEventId());
+
+ return $this->updateAssignmentAndAssociateTickets($capacityAssignment, $ticketIds);
+ }
+
+ private function updateAssignmentAndAssociateTickets(
+ CapacityAssignmentDomainObject $capacityAssignment,
+ ?array $ticketIds
+ ): CapacityAssignmentDomainObject
+ {
+ return $this->databaseManager->transaction(function () use ($capacityAssignment, $ticketIds) {
+ /** @var CapacityAssignmentDomainObject $capacityAssignment */
+ $capacityAssignment = $this->capacityAssignmentRepository->updateWhere(
+ attributes: [
+ CapacityAssignmentDomainObjectAbstract::NAME => $capacityAssignment->getName(),
+ CapacityAssignmentDomainObjectAbstract::EVENT_ID => $capacityAssignment->getEventId(),
+ CapacityAssignmentDomainObjectAbstract::CAPACITY => $capacityAssignment->getCapacity(),
+ CapacityAssignmentDomainObjectAbstract::APPLIES_TO => $capacityAssignment->getAppliesTo(),
+ CapacityAssignmentDomainObjectAbstract::STATUS => $capacityAssignment->getStatus(),
+ ],
+ where: [
+ CapacityAssignmentDomainObjectAbstract::ID => $capacityAssignment->getId(),
+ CapacityAssignmentDomainObjectAbstract::EVENT_ID => $capacityAssignment->getEventId(),
+ ]
+ );
+
+ if ($capacityAssignment->getAppliesTo() === CapacityAssignmentAppliesTo::TICKETS->name) {
+ $this->capacityAssignmentTicketAssociationService->addCapacityToTickets(
+ capacityAssignmentId: $capacityAssignment->getId(),
+ ticketIds: $ticketIds,
+ );
+ }
+
+ return $capacityAssignment;
+ });
+ }
+
+}
diff --git a/backend/app/Services/Domain/Order/OrderCreateRequestValidationService.php b/backend/app/Services/Domain/Order/OrderCreateRequestValidationService.php
index c0833551a..ae16f1dcc 100644
--- a/backend/app/Services/Domain/Order/OrderCreateRequestValidationService.php
+++ b/backend/app/Services/Domain/Order/OrderCreateRequestValidationService.php
@@ -12,17 +12,19 @@ use HiEvents\Helper\Currency;
use HiEvents\Repository\Interfaces\EventRepositoryInterface;
use HiEvents\Repository\Interfaces\PromoCodeRepositoryInterface;
use HiEvents\Repository\Interfaces\TicketRepositoryInterface;
+use HiEvents\Services\Domain\Ticket\TicketAvailableQuantityService;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\ValidationException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
-readonly class OrderCreateRequestValidationService
+class OrderCreateRequestValidationService
{
public function __construct(
- private TicketRepositoryInterface $ticketRepository,
- private PromoCodeRepositoryInterface $promoCodeRepository,
- private EventRepositoryInterface $eventRepository
+ readonly private TicketRepositoryInterface $ticketRepository,
+ readonly private PromoCodeRepositoryInterface $promoCodeRepository,
+ readonly private EventRepositoryInterface $eventRepository,
+ readonly private TicketAvailableQuantityService $ticketAvailableQuantityService,
)
{
}
@@ -139,22 +141,26 @@ readonly class OrderCreateRequestValidationService
ticketId: $ticketId,
ticket: $ticket
);
+
$this->validateTicketQuantity(
ticketIndex: $ticketIndex,
ticketAndQuantities: $ticketAndQuantities,
ticket: $ticket
);
+
$this->validateTicketTypeAndPrice(
event: $event,
ticketIndex: $ticketIndex,
ticketAndQuantities: $ticketAndQuantities,
ticket: $ticket
);
+
$this->validateSoldOutTickets(
ticketId: $ticketId,
ticketIndex: $ticketIndex,
ticket: $ticket
);
+
$this->validatePriceIdAndQuantity(
ticketIndex: $ticketIndex,
ticketAndQuantities: $ticketAndQuantities,
@@ -274,13 +280,11 @@ readonly class OrderCreateRequestValidationService
private function validateTicketPricesQuantity(array $quantities, TicketDomainObject $ticket, int $ticketIndex): void
{
foreach ($quantities as $ticketQuantity) {
- $numberAvailable = $this->ticketRepository->getQuantityRemainingForTicketPrice(
+ $numberAvailable = $this->ticketAvailableQuantityService->getAvailableQuantity(
ticketId: $ticket->getId(),
ticketPriceId: $ticketQuantity['price_id']
);
- $numberAvailable = max(0, $numberAvailable);
-
/** @var TicketPriceDomainObject $ticketPrice */
$ticketPrice = $ticket->getTicketPrices()
?->first(fn(TicketPriceDomainObject $price) => $price->getId() === $ticketQuantity['price_id']);
diff --git a/backend/app/Services/Domain/Order/OrderManagementService.php b/backend/app/Services/Domain/Order/OrderManagementService.php
index 998c110ed..acfe5bc21 100644
--- a/backend/app/Services/Domain/Order/OrderManagementService.php
+++ b/backend/app/Services/Domain/Order/OrderManagementService.php
@@ -15,11 +15,11 @@ use HiEvents\Services\Domain\Tax\TaxAndFeeOrderRollupService;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
-readonly class OrderManagementService
+class OrderManagementService
{
public function __construct(
- private OrderRepositoryInterface $orderRepository,
- private TaxAndFeeOrderRollupService $taxAndFeeOrderRollupService,
+ readonly private OrderRepositoryInterface $orderRepository,
+ readonly private TaxAndFeeOrderRollupService $taxAndFeeOrderRollupService,
)
{
}
diff --git a/backend/app/Services/Domain/Payment/Stripe/EventHandlers/PaymentIntentSucceededHandler.php b/backend/app/Services/Domain/Payment/Stripe/EventHandlers/PaymentIntentSucceededHandler.php
index 96ba2ec7f..f86119594 100644
--- a/backend/app/Services/Domain/Payment/Stripe/EventHandlers/PaymentIntentSucceededHandler.php
+++ b/backend/app/Services/Domain/Payment/Stripe/EventHandlers/PaymentIntentSucceededHandler.php
@@ -56,7 +56,7 @@ readonly class PaymentIntentSucceededHandler
$updatedOrder = $this->updateOrderStatuses($stripePayment);
- $this->quantityUpdateService->updateTicketQuantities($updatedOrder);
+ $this->quantityUpdateService->updateQuantities($updatedOrder);
OrderStatusChangedEvent::dispatch($updatedOrder);
});
diff --git a/backend/app/Services/Domain/Tax/TaxAndTicketAssociationService.php b/backend/app/Services/Domain/Tax/TaxAndTicketAssociationService.php
index 25e3a7056..1f5b643f2 100644
--- a/backend/app/Services/Domain/Tax/TaxAndTicketAssociationService.php
+++ b/backend/app/Services/Domain/Tax/TaxAndTicketAssociationService.php
@@ -36,7 +36,7 @@ readonly class TaxAndTicketAssociationService
throw new InvalidTaxOrFeeIdException(__('One or more tax IDs are invalid'));
}
- $this->ticketRepository->addTaxToTicket($params->ticketId, $params->taxAndFeeIds);
+ $this->ticketRepository->addTaxesAndFeesToTicket($params->ticketId, $params->taxAndFeeIds);
return $taxesAndFees;
}
diff --git a/backend/app/Services/Domain/Ticket/DTO/AvailableTicketQuantitiesDTO.php b/backend/app/Services/Domain/Ticket/DTO/AvailableTicketQuantitiesDTO.php
new file mode 100644
index 000000000..b62cca4c5
--- /dev/null
+++ b/backend/app/Services/Domain/Ticket/DTO/AvailableTicketQuantitiesDTO.php
@@ -0,0 +1,18 @@
+<?php
+
+namespace HiEvents\Services\Domain\Ticket\DTO;
+
+use HiEvents\DataTransferObjects\BaseDTO;
+
+class AvailableTicketQuantitiesDTO extends BaseDTO
+{
+ public function __construct(
+ public int $ticket_id,
+ public int $price_id,
+ public string $ticket_title,
+ public ?string $price_label,
+ public int $quantity_available,
+ )
+ {
+ }
+}
diff --git a/backend/app/Services/Domain/Ticket/EventTicketValidationService.php b/backend/app/Services/Domain/Ticket/EventTicketValidationService.php
index e36f7c68c..4ac741f0c 100644
--- a/backend/app/Services/Domain/Ticket/EventTicketValidationService.php
+++ b/backend/app/Services/Domain/Ticket/EventTicketValidationService.php
@@ -6,10 +6,10 @@ use HiEvents\DomainObjects\TicketDomainObject;
use HiEvents\Repository\Interfaces\TicketRepositoryInterface;
use HiEvents\Services\Domain\Ticket\Exception\UnrecognizedTicketIdException;
-readonly class EventTicketValidationService
+class EventTicketValidationService
{
public function __construct(
- private TicketRepositoryInterface $ticketRepository,
+ readonly private TicketRepositoryInterface $ticketRepository,
)
{
}
diff --git a/backend/app/Services/Domain/Ticket/FetchAvailableTicketQuantitiesService.php b/backend/app/Services/Domain/Ticket/FetchAvailableTicketQuantitiesService.php
new file mode 100644
index 000000000..0beac0efb
--- /dev/null
+++ b/backend/app/Services/Domain/Ticket/FetchAvailableTicketQuantitiesService.php
@@ -0,0 +1,122 @@
+<?php
+
+namespace HiEvents\Services\Domain\Ticket;
+
+use HiEvents\DomainObjects\Status\OrderStatus;
+use HiEvents\Services\Domain\Ticket\DTO\AvailableTicketQuantitiesDTO;
+use Illuminate\Config\Repository as Config;
+use Illuminate\Contracts\Cache\Repository as Cache;
+use Illuminate\Database\DatabaseManager;
+use Illuminate\Support\Collection;
+
+class FetchAvailableTicketQuantitiesService
+{
+ public function __construct(
+ private readonly DatabaseManager $db,
+ private readonly Config $config,
+ private readonly Cache $cache
+ )
+ {
+ }
+
+ /**
+ * @param int $eventId
+ * @return Collection<AvailableTicketQuantitiesDTO>
+ */
+ public function getAvailableTicketQuantities(int $eventId): Collection
+ {
+ if ($this->config->get('app.homepage_ticket_quantities_cache_ttl')) {
+ $cachedData = $this->getDataFromCache($eventId);
+ if ($cachedData) {
+ return $cachedData;
+ }
+ }
+
+ $reserved = OrderStatus::RESERVED->name;
+
+ $query = <<<SQL
+ WITH reserved_quantities AS (
+ SELECT order_items.ticket_id,
+ order_items.ticket_price_id,
+ SUM(order_items.quantity) AS quantity_reserved
+ FROM orders
+ INNER JOIN order_items ON order_items.order_id = orders.id
+ WHERE orders.event_id = :eventId
+ AND orders.status = :reserved
+ AND orders.reserved_until > NOW()
+ AND orders.deleted_at IS NULL
+ GROUP BY order_items.ticket_id, order_items.ticket_price_id
+ ),
+ capacity_reserved AS (
+ SELECT ticket_capacity_assignments.ticket_id,
+ ticket_capacity_assignments.capacity_assignment_id,
+ SUM(order_items.quantity) AS quantity_reserved
+ FROM orders
+ INNER JOIN order_items ON order_items.order_id = orders.id
+ INNER JOIN ticket_capacity_assignments ON order_items.ticket_id = ticket_capacity_assignments.ticket_id
+ WHERE orders.event_id = :eventId
+ AND orders.status = :reserved
+ AND orders.reserved_until > NOW()
+ AND orders.deleted_at IS NULL
+ GROUP BY ticket_capacity_assignments.ticket_id, ticket_capacity_assignments.capacity_assignment_id
+ ),
+ min_capacity AS (
+ SELECT ticket_capacity_assignments.ticket_id,
+ MIN(capacity_assignments.capacity - capacity_assignments.used_capacity - COALESCE(capacity_reserved.quantity_reserved, 0)) AS remaining_capacity
+ FROM ticket_capacity_assignments
+ INNER JOIN capacity_assignments ON ticket_capacity_assignments.capacity_assignment_id = capacity_assignments.id
+ LEFT JOIN capacity_reserved ON ticket_capacity_assignments.ticket_id = capacity_reserved.ticket_id
+ AND ticket_capacity_assignments.capacity_assignment_id = capacity_reserved.capacity_assignment_id
+ WHERE capacity_assignments.deleted_at IS NULL
+ GROUP BY ticket_capacity_assignments.ticket_id
+ )
+ SELECT
+ tickets.id AS ticket_id,
+ ticket_prices.id AS price_id,
+ tickets.title AS ticket_title,
+ ticket_prices.label AS price_label,
+ LEAST(
+ ticket_prices.initial_quantity_available - ticket_prices.quantity_sold - COALESCE(reserved_quantities.quantity_reserved, 0),
+ COALESCE(min_capacity.remaining_capacity, ticket_prices.initial_quantity_available - ticket_prices.quantity_sold - COALESCE(reserved_quantities.quantity_reserved, 0))
+ ) AS quantity_available
+ FROM ticket_prices
+ INNER JOIN tickets ON ticket_prices.ticket_id = tickets.id
+ LEFT JOIN reserved_quantities ON ticket_prices.id = reserved_quantities.ticket_price_id
+ LEFT JOIN min_capacity ON tickets.id = min_capacity.ticket_id
+ WHERE tickets.event_id = :eventId
+ AND tickets.deleted_at IS NULL
+ AND ticket_prices.deleted_at IS NULL
+ ORDER BY ticket_prices.id;
+SQL;
+
+ $result = collect($this->db->select($query, ['eventId' => $eventId, 'reserved' => $reserved]))->map(function ($row) {
+ return AvailableTicketQuantitiesDTO::fromArray([
+ 'ticket_id' => $row->ticket_id,
+ 'price_id' => $row->price_id,
+ 'ticket_title' => $row->ticket_title,
+ 'price_label' => $row->price_label,
+ 'quantity_available' => $row->quantity_available,
+ ]);
+ });
+
+ if ($this->config->get('app.homepage_ticket_quantities_cache_ttl')) {
+ $this->cache->put(
+ key: $this->getCacheKey($eventId),
+ value: $result,
+ ttl: $this->config->get('app.homepage_ticket_quantities_cache_ttl'),
+ );
+ }
+
+ return $result;
+ }
+
+ private function getDataFromCache(int $eventId): ?Collection
+ {
+ return $this->cache->get($this->getCacheKey($eventId));
+ }
+
+ private function getCacheKey(int $eventId): string
+ {
+ return "event.$eventId.available_ticket_quantities";
+ }
+}
diff --git a/backend/app/Services/Domain/Ticket/TicketAvailableQuantityService.php b/backend/app/Services/Domain/Ticket/TicketAvailableQuantityService.php
new file mode 100644
index 000000000..b983c6cab
--- /dev/null
+++ b/backend/app/Services/Domain/Ticket/TicketAvailableQuantityService.php
@@ -0,0 +1,39 @@
+<?php
+
+namespace HiEvents\Services\Domain\Ticket;
+
+use HiEvents\Repository\Interfaces\OrderRepositoryInterface;
+use HiEvents\Repository\Interfaces\TicketRepositoryInterface;
+use Illuminate\Support\Collection;
+
+class TicketAvailableQuantityService
+{
+ public function __construct(
+ private readonly TicketRepositoryInterface $ticketRepository,
+ private readonly OrderRepositoryInterface $orderRepository
+ )
+ {
+ }
+
+ public function getAvailableQuantity(int $ticketId, int $ticketPriceId): int
+ {
+ $ticketPriceAvailableQuantity = $this->ticketRepository->getQuantityRemainingForTicketPrice($ticketId, $ticketPriceId);
+ $capacityAssignments = $this->ticketRepository->getCapacityAssignmentsByTicketId($ticketId);
+
+ if ($capacityAssignments->isNotEmpty()) {
+ $capacityAssignmentAvailableQuantity = $this->calculateCapacityAssignmentAvailableQuantity($capacityAssignments, $ticketId);
+ $ticketPriceAvailableQuantity = min($ticketPriceAvailableQuantity, $capacityAssignmentAvailableQuantity);
+ }
+
+ return max(0, $ticketPriceAvailableQuantity);
+ }
+
+ private function calculateCapacityAssignmentAvailableQuantity(Collection $capacityAssignments, int $ticketId): int
+ {
+ return $capacityAssignments->map(function ($assignment) use ($ticketId) {
+ $reservedQuantity = $this->orderRepository->getReservedQuantityForTicketPrice($ticketId, $assignment->getId());
+
+ return max(0, $assignment->getCapacity() - $assignment->getUsedCapacity() - $reservedQuantity);
+ })->min();
+ }
+}
diff --git a/backend/app/Services/Domain/Ticket/TicketFilterService.php b/backend/app/Services/Domain/Ticket/TicketFilterService.php
index c07ae7599..a0ed31ff7 100644
--- a/backend/app/Services/Domain/Ticket/TicketFilterService.php
+++ b/backend/app/Services/Domain/Ticket/TicketFilterService.php
@@ -7,23 +7,23 @@ use HiEvents\DomainObjects\PromoCodeDomainObject;
use HiEvents\DomainObjects\TicketDomainObject;
use HiEvents\DomainObjects\TicketPriceDomainObject;
use HiEvents\Helper\Currency;
-use HiEvents\Repository\Interfaces\EventRepositoryInterface;
use HiEvents\Services\Domain\Tax\TaxAndFeeCalculationService;
+use HiEvents\Services\Domain\Ticket\DTO\AvailableTicketQuantitiesDTO;
use Illuminate\Support\Collection;
class TicketFilterService
{
public function __construct(
- private readonly EventRepositoryInterface $eventRepository,
- private readonly TaxAndFeeCalculationService $taxCalculationService,
- private readonly TicketPriceService $ticketPriceService,
+ private readonly TaxAndFeeCalculationService $taxCalculationService,
+ private readonly TicketPriceService $ticketPriceService,
+ private readonly FetchAvailableTicketQuantitiesService $fetchAvailableTicketQuantitiesService,
)
{
}
public function filter(EventDomainObject $event, ?PromoCodeDomainObject $promoCode): ?Collection
{
- $ticketQuantities = $this->eventRepository->getAvailableTicketQuantities($event->getId());
+ $ticketQuantities = $this->fetchAvailableTicketQuantitiesService->getAvailableTicketQuantities($event->getId());
return $event->getTickets()
?->map(fn(TicketDomainObject $ticket) => $this->processTicket($promoCode, $ticket, $ticketQuantities))
@@ -51,6 +51,12 @@ class TicketFilterService
&& $promoCode->appliesToTicket($ticket);
}
+ /**
+ * @param PromoCodeDomainObject|null $promoCode
+ * @param TicketDomainObject $ticket
+ * @param Collection<AvailableTicketQuantitiesDTO> $ticketQuantities
+ * @return TicketDomainObject
+ */
private function processTicket(?PromoCodeDomainObject $promoCode, TicketDomainObject $ticket, Collection $ticketQuantities): TicketDomainObject
{
if ($this->shouldTicketBeDiscounted($promoCode, $ticket)) {
diff --git a/backend/app/Services/Domain/Ticket/TicketQuantityUpdateService.php b/backend/app/Services/Domain/Ticket/TicketQuantityUpdateService.php
index d38e210ad..44179b57a 100644
--- a/backend/app/Services/Domain/Ticket/TicketQuantityUpdateService.php
+++ b/backend/app/Services/Domain/Ticket/TicketQuantityUpdateService.php
@@ -2,30 +2,69 @@
namespace HiEvents\Services\Domain\Ticket;
-use InvalidArgumentException;
+use HiEvents\DomainObjects\Generated\CapacityAssignmentDomainObjectAbstract;
use HiEvents\DomainObjects\Generated\TicketPriceDomainObjectAbstract;
use HiEvents\DomainObjects\OrderDomainObject;
use HiEvents\DomainObjects\OrderItemDomainObject;
+use HiEvents\Repository\Interfaces\CapacityAssignmentRepositoryInterface;
use HiEvents\Repository\Interfaces\TicketPriceRepositoryInterface;
+use HiEvents\Repository\Interfaces\TicketRepositoryInterface;
+use InvalidArgumentException;
-readonly class TicketQuantityUpdateService
+class TicketQuantityUpdateService
{
- public function __construct(private TicketPriceRepositoryInterface $ticketPriceRepository)
+ public function __construct(
+ private readonly TicketPriceRepositoryInterface $ticketPriceRepository,
+ private readonly TicketRepositoryInterface $ticketRepository,
+ private readonly CapacityAssignmentRepositoryInterface $capacityAssignmentRepository,
+ )
{
}
- public function updateTicketQuantities(OrderDomainObject $order): void
+ public function updateQuantities(OrderDomainObject $order): void
{
if (!$order->getOrderItems() === null) {
throw new InvalidArgumentException(__('Order has no order items'));
}
+ $this->updateTicketQuantities($order);
+ $this->updateCapacityAssignments($order);
+
+ }
+
+ /**
+ * @param OrderDomainObject $order
+ * @return void
+ */
+ private function updateCapacityAssignments(OrderDomainObject $order): void
+ {
+ /** @var OrderItemDomainObject $orderItem */
+ foreach ($order->getOrderItems() as $orderItem) {
+ $ticketPrice = $this->ticketPriceRepository->findById($orderItem->getTicketPriceId());
+ $capacityAssignments = $this->ticketRepository->getCapacityAssignmentsByTicketId($ticketPrice->getTicketId());
+
+ foreach ($capacityAssignments as $capacityAssignment) {
+ $this->capacityAssignmentRepository->increment(
+ id: $capacityAssignment->getId(),
+ column: CapacityAssignmentDomainObjectAbstract::USED_CAPACITY,
+ amount: $orderItem->getQuantity()
+ );
+ }
+ }
+ }
+
+ /**
+ * @param OrderDomainObject $order
+ * @return void
+ */
+ private function updateTicketQuantities(OrderDomainObject $order): void
+ {
/** @var OrderItemDomainObject $orderItem */
foreach ($order->getOrderItems() as $orderItem) {
$this->ticketPriceRepository->increment(
- $orderItem->getTicketPriceId(),
- TicketPriceDomainObjectAbstract::QUANTITY_SOLD,
- $orderItem->getQuantity()
+ id: $orderItem->getTicketPriceId(),
+ column: TicketPriceDomainObjectAbstract::QUANTITY_SOLD,
+ amount: $orderItem->getQuantity()
);
}
}
diff --git a/backend/app/Services/Handlers/Attendee/PartialEditAttendeeHandler.php b/backend/app/Services/Handlers/Attendee/PartialEditAttendeeHandler.php
index 51c77f1a5..ab2174b8b 100644
--- a/backend/app/Services/Handlers/Attendee/PartialEditAttendeeHandler.php
+++ b/backend/app/Services/Handlers/Attendee/PartialEditAttendeeHandler.php
@@ -42,6 +42,7 @@ class PartialEditAttendeeHandler
}
//if status has changed, adjust ticket quantity
+ // todo - check this logic
if ($data->status && $data->status !== $attendee->getStatus()) {
$this->ticketQuantityService->decreaseTicketPriceQuantitySold($attendee->getTicketPriceId());
$this->ticketQuantityService->increaseTicketPriceQuantitySold($attendee->getTicketPriceId());
diff --git a/backend/app/Services/Handlers/CapacityAssignment/CreateCapacityAssignmentHandler.php b/backend/app/Services/Handlers/CapacityAssignment/CreateCapacityAssignmentHandler.php
new file mode 100644
index 000000000..0f4c0b1ec
--- /dev/null
+++ b/backend/app/Services/Handlers/CapacityAssignment/CreateCapacityAssignmentHandler.php
@@ -0,0 +1,35 @@
+<?php
+
+namespace HiEvents\Services\Handlers\CapacityAssignment;
+
+use HiEvents\DomainObjects\CapacityAssignmentDomainObject;
+use HiEvents\Services\Domain\CapacityAssignment\CreateCapacityAssignmentService;
+use HiEvents\Services\Domain\Ticket\Exception\UnrecognizedTicketIdException;
+use HiEvents\Services\Handlers\CapacityAssignment\DTO\UpsertCapacityAssignmentDTO;
+
+class CreateCapacityAssignmentHandler
+{
+ public function __construct(
+ private readonly CreateCapacityAssignmentService $createCapacityAssignmentService
+ )
+ {
+ }
+
+ /**
+ * @throws UnrecognizedTicketIdException
+ */
+ public function handle(UpsertCapacityAssignmentDTO $data): CapacityAssignmentDomainObject
+ {
+ $capacityAssignment = (new CapacityAssignmentDomainObject)
+ ->setName($data->name)
+ ->setEventId($data->event_id)
+ ->setCapacity($data->capacity)
+ ->setAppliesTo($data->applies_to->name)
+ ->setStatus($data->status->name);
+
+ return $this->createCapacityAssignmentService->createCapacityAssignment(
+ $capacityAssignment,
+ $data->ticket_ids,
+ );
+ }
+}
diff --git a/backend/app/Services/Handlers/CapacityAssignment/DTO/GetCapacityAssignmentsDTO.php b/backend/app/Services/Handlers/CapacityAssignment/DTO/GetCapacityAssignmentsDTO.php
new file mode 100644
index 000000000..2d0b97cc1
--- /dev/null
+++ b/backend/app/Services/Handlers/CapacityAssignment/DTO/GetCapacityAssignmentsDTO.php
@@ -0,0 +1,14 @@
+<?php
+
+namespace HiEvents\Services\Handlers\CapacityAssignment\DTO;
+
+use HiEvents\DataTransferObjects\BaseDTO;
+
+class GetCapacityAssignmentsDTO extends BaseDTO
+{
+ public function __construct(
+ public int $eventId,
+ )
+ {
+ }
+}
diff --git a/backend/app/Services/Handlers/CapacityAssignment/DTO/UpsertCapacityAssignmentDTO.php b/backend/app/Services/Handlers/CapacityAssignment/DTO/UpsertCapacityAssignmentDTO.php
new file mode 100644
index 000000000..4aa227c04
--- /dev/null
+++ b/backend/app/Services/Handlers/CapacityAssignment/DTO/UpsertCapacityAssignmentDTO.php
@@ -0,0 +1,23 @@
+<?php
+
+namespace HiEvents\Services\Handlers\CapacityAssignment\DTO;
+
+use HiEvents\DataTransferObjects\BaseDTO;
+use HiEvents\DomainObjects\Enums\CapacityAssignmentAppliesTo;
+use HiEvents\DomainObjects\Status\CapacityAssignmentStatus;
+
+class UpsertCapacityAssignmentDTO extends BaseDTO
+{
+ public function __construct(
+ public string $name,
+ public int $event_id,
+ public CapacityAssignmentAppliesTo $applies_to,
+ public CapacityAssignmentStatus $status,
+
+ public ?int $capacity,
+ public ?array $ticket_ids = null,
+ public ?int $id = null,
+ )
+ {
+ }
+}
diff --git a/backend/app/Services/Handlers/CapacityAssignment/DeleteCapacityAssignmentHandler.php b/backend/app/Services/Handlers/CapacityAssignment/DeleteCapacityAssignmentHandler.php
new file mode 100644
index 000000000..bda3eac0b
--- /dev/null
+++ b/backend/app/Services/Handlers/CapacityAssignment/DeleteCapacityAssignmentHandler.php
@@ -0,0 +1,32 @@
+<?php
+
+namespace HiEvents\Services\Handlers\CapacityAssignment;
+
+use HiEvents\Repository\Interfaces\CapacityAssignmentRepositoryInterface;
+use HiEvents\Repository\Interfaces\TicketRepositoryInterface;
+use Illuminate\Database\DatabaseManager;
+
+class DeleteCapacityAssignmentHandler
+{
+ public function __construct(
+ private readonly CapacityAssignmentRepositoryInterface $capacityAssignmentRepository,
+ private readonly TicketRepositoryInterface $ticketRepository,
+ private readonly DatabaseManager $databaseManager,
+ )
+ {
+ }
+
+ public function handle(int $id, int $eventId): void
+ {
+ $this->databaseManager->transaction(function () use ($id, $eventId) {
+ $this->ticketRepository->removeCapacityAssignmentFromTickets(
+ capacityAssignmentId: $id,
+ );
+
+ $this->capacityAssignmentRepository->deleteWhere([
+ 'id' => $id,
+ 'event_id' => $eventId,
+ ]);
+ });
+ }
+}
diff --git a/backend/app/Services/Handlers/CapacityAssignment/GetCapacityAssignmentsHandler.php b/backend/app/Services/Handlers/CapacityAssignment/GetCapacityAssignmentsHandler.php
new file mode 100644
index 000000000..ada688d1f
--- /dev/null
+++ b/backend/app/Services/Handlers/CapacityAssignment/GetCapacityAssignmentsHandler.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace HiEvents\Services\Handlers\CapacityAssignment;
+
+use HiEvents\DomainObjects\TicketDomainObject;
+use HiEvents\Repository\Interfaces\CapacityAssignmentRepositoryInterface;
+use HiEvents\Services\Handlers\CapacityAssignment\DTO\GetCapacityAssignmentsDTO;
+use Illuminate\Support\Collection;
+
+class GetCapacityAssignmentsHandler
+{
+ public function __construct(
+ private readonly CapacityAssignmentRepositoryInterface $capacityAssignmentRepository,
+ )
+ {
+ }
+
+ public function handle(GetCapacityAssignmentsDTO $dto): Collection
+ {
+ return $this->capacityAssignmentRepository
+ ->loadRelation(TicketDomainObject::class)
+ ->findWhere([
+ 'event_id' => $dto->eventId,
+ ]);
+ }
+}
diff --git a/backend/app/Services/Handlers/CapacityAssignment/UpdateCapacityAssignmentHandler.php b/backend/app/Services/Handlers/CapacityAssignment/UpdateCapacityAssignmentHandler.php
new file mode 100644
index 000000000..4d6c31127
--- /dev/null
+++ b/backend/app/Services/Handlers/CapacityAssignment/UpdateCapacityAssignmentHandler.php
@@ -0,0 +1,36 @@
+<?php
+
+namespace HiEvents\Services\Handlers\CapacityAssignment;
+
+use HiEvents\DomainObjects\CapacityAssignmentDomainObject;
+use HiEvents\Services\Domain\CapacityAssignment\UpdateCapacityAssignmentService;
+use HiEvents\Services\Domain\Ticket\Exception\UnrecognizedTicketIdException;
+use HiEvents\Services\Handlers\CapacityAssignment\DTO\UpsertCapacityAssignmentDTO;
+
+class UpdateCapacityAssignmentHandler
+{
+ public function __construct(
+ private readonly UpdateCapacityAssignmentService $updateCapacityAssignmentService,
+ )
+ {
+ }
+
+ /**
+ * @throws UnrecognizedTicketIdException
+ */
+ public function handle(UpsertCapacityAssignmentDTO $data): CapacityAssignmentDomainObject
+ {
+ $capacityAssignment = (new CapacityAssignmentDomainObject)
+ ->setId($data->id)
+ ->setName($data->name)
+ ->setEventId($data->event_id)
+ ->setCapacity($data->capacity)
+ ->setAppliesTo($data->applies_to->name)
+ ->setStatus($data->status->name);
+
+ return $this->updateCapacityAssignmentService->updateCapacityAssignment(
+ $capacityAssignment,
+ $data->ticket_ids,
+ );
+ }
+}
diff --git a/backend/app/Services/Handlers/Order/CompleteOrderHandler.php b/backend/app/Services/Handlers/Order/CompleteOrderHandler.php
index d68363b51..02d35f697 100644
--- a/backend/app/Services/Handlers/Order/CompleteOrderHandler.php
+++ b/backend/app/Services/Handlers/Order/CompleteOrderHandler.php
@@ -74,7 +74,7 @@ readonly class CompleteOrderHandler
* @see PaymentIntentSucceededHandler
*/
if (!$order->isPaymentRequired()) {
- $this->ticketQuantityUpdateService->updateTicketQuantities($updatedOrder);
+ $this->ticketQuantityUpdateService->updateQuantities($updatedOrder);
}
OrderStatusChangedEvent::dispatch($updatedOrder);
diff --git a/backend/config/app.php b/backend/config/app.php
index b570f80d4..3e61b3627 100644
--- a/backend/config/app.php
+++ b/backend/config/app.php
@@ -22,6 +22,14 @@ return [
*/
'homepage_views_update_batch_size' => env('APP_HOMEPAGE_VIEWS_UPDATE_BATCH_SIZE', 8),
+ /**
+ * The number of seconds to cache the ticket quantities on the homepage
+ * It is recommended to cache this value for a short period of time for high traffic sites
+ *
+ * Set to null to disable caching
+ */
+ 'homepage_ticket_quantities_cache_ttl' => env('APP_HOMEPAGE_TICKET_QUANTITIES_CACHE_TTL', 2),
+
'frontend_urls' => [
'confirm_email_address' => '/manage/profile/confirm-email-address/%s',
'reset_password' => '/auth/reset-password/%s',
diff --git a/backend/database/migrations/2024_07_14_031511_create_capacity_assignments_and_associated_tables.php b/backend/database/migrations/2024_07_14_031511_create_capacity_assignments_and_associated_tables.php
new file mode 100644
index 000000000..77839e526
--- /dev/null
+++ b/backend/database/migrations/2024_07_14_031511_create_capacity_assignments_and_associated_tables.php
@@ -0,0 +1,55 @@
+<?php
+
+use HiEvents\DomainObjects\Enums\CapacityAssignmentAppliesTo;
+use HiEvents\DomainObjects\Status\CapacityAssignmentStatus;
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration {
+ public function up(): void
+ {
+ Schema::create('capacity_assignments', function (Blueprint $table) {
+ $table->id();
+ $table->foreignId('event_id')->constrained('events')->onDelete('cascade');
+ $table->string('name');
+ $table->integer('capacity')->nullable()->default(null);
+ $table->integer('used_capacity')->default(0);
+ $table->string('applies_to')->default(CapacityAssignmentAppliesTo::EVENT->name);
+ $table->string('status')->default(CapacityAssignmentStatus::ACTIVE->name);
+ $table->timestamps();
+ $table->softDeletes();
+
+ $table->index('event_id');
+ $table->index('applies_to');
+ $table->index('status');
+ });
+
+ Schema::create('ticket_capacity_assignments', function (Blueprint $table) {
+ $table->id();
+ $table->foreignId('ticket_id')->constrained('tickets')->onDelete('cascade');
+ $table->foreignId('capacity_assignment_id')->constrained('capacity_assignments')->onDelete('cascade');
+ $table->timestamps();
+ $table->softDeletes();
+
+ $table->index('ticket_id');
+ $table->index('capacity_assignment_id');
+
+ $table->unique(['ticket_id', 'capacity_assignment_id']);
+ });
+
+ Schema::table('ticket_prices', function (Blueprint $table) {
+ $table->integer('quantity_available')->default(null)->nullable();
+ });
+ }
+
+ public function down(): void
+ {
+ Schema::table('ticket_prices', function (Blueprint $table) {
+ $table->dropColumn('quantity_available');
+ });
+
+ Schema::dropIfExists('ticket_capacity_assignments');
+ Schema::dropIfExists('capacity_assignments');
+ }
+};
diff --git a/backend/database/migrations/2024_07_19_033929_add_missing_indexes.php b/backend/database/migrations/2024_07_19_033929_add_missing_indexes.php
new file mode 100644
index 000000000..897f64a00
--- /dev/null
+++ b/backend/database/migrations/2024_07_19_033929_add_missing_indexes.php
@@ -0,0 +1,21 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration {
+ public function up(): void
+ {
+ Schema::table('orders', function (Blueprint $table) {
+ $table->index(['event_id', 'status', 'reserved_until', 'deleted_at']);
+ });
+ }
+
+ public function down(): void
+ {
+ Schema::table('orders', function (Blueprint $table) {
+ $table->dropIndex(['event_id', 'status', 'reserved_until', 'deleted_at']);
+ });
+ }
+};
diff --git a/backend/routes/api.php b/backend/routes/api.php
index 5cf492bab..d3285e5e9 100644
--- a/backend/routes/api.php
+++ b/backend/routes/api.php
@@ -21,6 +21,10 @@ use HiEvents\Http\Actions\Auth\LogoutAction;
use HiEvents\Http\Actions\Auth\RefreshTokenAction;
use HiEvents\Http\Actions\Auth\ResetPasswordAction;
use HiEvents\Http\Actions\Auth\ValidateResetPasswordTokenAction;
+use HiEvents\Http\Actions\CapacityAssignments\CreateCapacityAssignmentAction;
+use HiEvents\Http\Actions\CapacityAssignments\DeleteCapacityAssignmentAction;
+use HiEvents\Http\Actions\CapacityAssignments\GetCapacityAssignmentsAction;
+use HiEvents\Http\Actions\CapacityAssignments\UpdateCapacityAssignmentAction;
use HiEvents\Http\Actions\Common\Webhooks\StripeIncomingWebhookAction;
use HiEvents\Http\Actions\Events\CreateEventAction;
use HiEvents\Http\Actions\Events\DuplicateEventAction;
@@ -207,6 +211,11 @@ $router->middleware(['auth:api'])->group(
$router->get('/events/{event_id}/settings', GetEventSettingsAction::class);
$router->put('/events/{event_id}/settings', EditEventSettingsAction::class);
$router->patch('/events/{event_id}/settings', PartialEditEventSettingsAction::class);
+
+ $router->post('/events/{event_id}/capacity-assignments', CreateCapacityAssignmentAction::class);
+ $router->get('/events/{event_id}/capacity-assignments', GetCapacityAssignmentsAction::class);
+ $router->put('/events/{event_id}/capacity-assignments/{capacity_assignment_id}', UpdateCapacityAssignmentAction::class);
+ $router->delete('/events/{event_id}/capacity-assignments/{capacity_assignment_id}', DeleteCapacityAssignmentAction::class);
}
);
diff --git a/frontend/src/api/capacity-assignment.client.ts b/frontend/src/api/capacity-assignment.client.ts
new file mode 100644
index 000000000..17c2f03d1
--- /dev/null
+++ b/frontend/src/api/capacity-assignment.client.ts
@@ -0,0 +1,31 @@
+import {api} from "./client";
+import {
+ CapacityAssignment,
+ CapacityAssignmentRequest,
+ GenericDataResponse,
+ GenericPaginatedResponse,
+ IdParam,
+} from "../types";
+
+export const capacityAssignmentClient = {
+ create: async (eventId: IdParam, capacityAssignment: CapacityAssignmentRequest) => {
+ const response = await api.post<GenericDataResponse<CapacityAssignment>>(`events/${eventId}/capacity-assignments`, capacityAssignment);
+ return response.data;
+ },
+ update: async (eventId: IdParam, capacityAssignmentId: IdParam, capacityAssignment: CapacityAssignmentRequest) => {
+ const response = await api.put<GenericDataResponse<CapacityAssignment>>(`events/${eventId}/capacity-assignments/${capacityAssignmentId}`, capacityAssignment);
+ return response.data;
+ },
+ all: async (eventId: IdParam) => {
+ const response = await api.get<GenericPaginatedResponse<CapacityAssignment>>(`events/${eventId}/capacity-assignments`);
+ return response.data;
+ },
+ get: async (eventId: IdParam, capacityAssignmentId: IdParam) => {
+ const response = await api.get<GenericDataResponse<CapacityAssignment>>(`events/${eventId}/capacity-assignments/${capacityAssignmentId}`);
+ return response.data;
+ },
+ delete: async (eventId: IdParam, capacityAssignmentId: IdParam) => {
+ const response = await api.delete<GenericDataResponse<CapacityAssignment>>(`events/${eventId}/capacity-assignments/${capacityAssignmentId}`);
+ return response.data;
+ },
+}
diff --git a/frontend/src/components/common/CapacityAssignmentList/CapacityAssignmentList.module.scss b/frontend/src/components/common/CapacityAssignmentList/CapacityAssignmentList.module.scss
new file mode 100644
index 000000000..5c56de818
--- /dev/null
+++ b/frontend/src/components/common/CapacityAssignmentList/CapacityAssignmentList.module.scss
@@ -0,0 +1,79 @@
+@import '../../../styles/mixins';
+
+.toolbar {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+
+ .search {
+
+ }
+}
+
+
+.capacityAssignmentList {
+ display: grid;
+ grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
+ gap: 20px;
+ margin-top: 20px;
+
+ @include respond-below(md) {
+
+ }
+
+
+ .capacityCard {
+ display: flex;
+ flex-direction: column;
+ justify-content: space-between;
+ margin-bottom: 0 !important;
+
+
+ .capacityAssignmentHeader {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ border-radius: 5px;
+ margin-bottom: 20px;
+
+ .capacityAssignmentAppliesTo {
+ .appliesToText {
+ display: flex;
+ color: #999;
+ justify-content: center;
+ align-items: center;
+ }
+ }
+
+ }
+
+ .capacityAssignmentName {
+ font-size: 1.2rem;
+ font-weight: bold;
+ margin-bottom: 10px;
+ }
+
+ .capacityAssignmentInfo {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+
+ .capacityAssignmentCapacity {
+ margin-bottom: 4px;
+ width: 120px;
+
+ .capacityText {
+ margin-top: 10px;
+ color: #999;
+ }
+ }
+
+ .capacityAssignmentActions {
+
+ }
+ }
+ }
+
+
+}
+
diff --git a/frontend/src/components/common/CapacityAssignmentList/index.tsx b/frontend/src/components/common/CapacityAssignmentList/index.tsx
new file mode 100644
index 000000000..ebb5be7b5
--- /dev/null
+++ b/frontend/src/components/common/CapacityAssignmentList/index.tsx
@@ -0,0 +1,178 @@
+import {CapacityAssignment} from "../../../types";
+import {Badge, Button, Progress} from "@mantine/core";
+import {t, Trans} from "@lingui/macro";
+import {IconDotsVertical, IconHelp, IconPlus} from "@tabler/icons-react";
+import Truncate from "../Truncate";
+import {NoResultsSplash} from "../NoResultsSplash";
+import classes from './CapacityAssignmentList.module.scss';
+import {Card} from "../Card";
+import {Popover} from "../Popover";
+import {SearchBar} from "../SearchBar";
+import {useState} from "react";
+
+interface CapacityAssignmentListProps {
+ capacityAssignments: CapacityAssignment[];
+ openCreateModal: () => void;
+}
+
+export const CapacityAssignmentList = ({capacityAssignments, openCreateModal}: CapacityAssignmentListProps) => {
+ const [searchValue, setSearchValue] = useState<string>('');
+
+
+ if (capacityAssignments.length === 0) {
+ return (
+ <NoResultsSplash
+ heading={t`No Capacity Assignments`}
+ imageHref={'/blank-slate/attendees.svg'}
+ subHeading={(
+ <>
+ <p>
+ <Trans>
+ <p>
+ Capacity assignments allow you to manage capacity for specific tickets or the entire
+ event.
+ </p>
+
+ Example:
+ <Card>
+ If you have a <b>Day 1</b> ticket and an <b>All Weekend</b> ticket, you can create a
+ capacity assignment called <b>Day 1 Capacity</b> which will ensure you don't go over
+ capacity on
+ the first day.
+ </Card>
+ </Trans>
+ </p>
+ <Button
+ size={'xs'}
+ leftSection={<IconPlus/>}
+ color={'green'}
+ onClick={() => openCreateModal()}>{t`Create Capacity Assignment`}
+ </Button>
+ </>
+ )}
+ />
+ );
+ }
+
+ return (
+ <>
+ <Card>
+ <div className={classes.toolbar}>
+ <div className={classes.search}>
+ <SearchBar
+ onClear={() => setSearchValue('')}
+ value={searchValue}
+ onChange={(value) => setSearchValue(value.target.value)}
+ />
+ </div>
+ <div className={classes.button}>
+ <Button color={'green'} rightSection={<IconPlus/>} onClick={openCreateModal}>
+ {t`Add capacity assignment`}
+ </Button>
+ </div>
+ </div>
+ </Card>
+
+ <div className={classes.capacityAssignmentList}>
+ {capacityAssignments.map((assignment) => {
+ const capacityPercentage = assignment.capacity
+ ? (assignment.used_capacity / assignment.capacity) * 100
+ : 0;
+ const capacityColor = capacityPercentage > 80 ? 'red' : capacityPercentage > 50 ? 'yellow' : 'green';
+
+ if (searchValue && !assignment.name.toLowerCase().includes(searchValue.toLowerCase())) {
+ return null;
+ }
+
+ return (
+ <Card className={classes.capacityCard} key={assignment.id}>
+ <div className={classes.capacityAssignmentHeader}>
+ <div className={classes.capacityAssignmentAppliesTo}>
+ {assignment.applies_to === 'EVENT' && (
+ <div className={classes.appliesToText}>
+ {t`Applies to entire event`}
+ </div>
+ )}
+
+ {assignment.applies_to === 'TICKETS' && (
+ <Popover
+ title={assignment.tickets.map((ticket) => (
+ <div key={ticket.id}>
+ {ticket.title}
+ </div>
+ ))}
+ position={'bottom'}
+ withArrow
+ >
+ <div className={classes.appliesToText}>
+ <div>
+ {assignment.tickets.length > 1 &&
+ <Trans>Applies to {assignment.tickets.length} tickets</Trans>}
+ {assignment.tickets.length === 1 && t`Applies to 1 ticket`}
+ </div>
+ &nbsp;
+ <IconHelp size={16}/>
+ </div>
+ </Popover>
+ )}
+ </div>
+
+ <div className={classes.capacityAssignmentStatus}>
+ <Badge variant={'light'} color={assignment.status === 'ACTIVE' ? 'green' : 'gray'}>
+ {assignment.status}
+ </Badge>
+ </div>
+ </div>
+ <div className={classes.capacityAssignmentName}>
+ <b>
+ <Truncate text={assignment.name} length={30}/>
+ </b>
+ </div>
+
+ <div className={classes.capacityAssignmentInfo}>
+ <div className={classes.capacityAssignmentCapacity}>
+ {assignment.capacity ? (
+ <div className={classes.capacity}>
+ <Progress
+ className={classes.capacityBar}
+ value={capacityPercentage}
+ color={capacityColor}
+ size={'md'}
+ />
+ <div className={classes.capacityText}>
+ {assignment.used_capacity}/{assignment.capacity}
+ </div>
+ </div>
+ ) : (
+ <div className={classes.capacityText}>
+ {assignment.used_capacity}/∞
+ </div>
+ )}
+ </div>
+ <div className={classes.capacityAssignmentActions}>
+ <Button variant={'transparent'}>
+ <IconDotsVertical/>
+ </Button>
+ </div>
+ </div>
+ </Card>
+ );
+ })}
+ </div>
+ </>
+ );
+};
+
+// Dummy handlers for menu actions (should be replaced with actual implementations)
+const handleModalClick = (assignment: CapacityAssignment, modalOpen: any) => {
+ console.log('Opening modal for:', assignment);
+};
+
+const handleDelete = (assignment: CapacityAssignment) => {
+ return () => {
+ console.log('Deleting assignment:', assignment);
+ };
+};
+
+const viewModalOpen = {}; // Placeholder for actual modal open state
+const editModal = {}; // Placeholder for actual modal open state
diff --git a/frontend/src/components/common/CheckoutQuestion/index.tsx b/frontend/src/components/common/CheckoutQuestion/index.tsx
index b48c8643a..96d3c3487 100644
--- a/frontend/src/components/common/CheckoutQuestion/index.tsx
+++ b/frontend/src/components/common/CheckoutQuestion/index.tsx
@@ -134,6 +134,8 @@ const AddressInput = ({question, name, form}: QuestionInputProps) => {
return (
<>
<h4>{question.title}</h4>
+ <div className={classes.description} dangerouslySetInnerHTML={{__html: question.description || ''}}>
+ </div>
<TextInput withAsterisk={question.required}
{...form.getInputProps(`${name}.address_line_1`)}
label={t`Address line 1`}/>
diff --git a/frontend/src/components/common/NoResultsSplash/index.tsx b/frontend/src/components/common/NoResultsSplash/index.tsx
index 89cacfe19..05109a93a 100644
--- a/frontend/src/components/common/NoResultsSplash/index.tsx
+++ b/frontend/src/components/common/NoResultsSplash/index.tsx
@@ -14,7 +14,7 @@ export const NoResultsSplash = ({
heading = t`'There\'s nothing to show yet'`,
children,
subHeading,
- imageHref = '/no-results-empty-boxes.svg'
+ imageHref = '/no-results-empty-boxes.svg',
}: NoResultsSplashProps) => {
const [searchParams] = useSearchParams();
const hasSearchQuery = !!searchParams.get('query');
@@ -34,4 +34,4 @@ export const NoResultsSplash = ({
{children && children}
</div>
)
-}
\ No newline at end of file
+}
diff --git a/frontend/src/components/common/PageTitle/index.tsx b/frontend/src/components/common/PageTitle/index.tsx
index c13fc16a8..1c3db1657 100644
--- a/frontend/src/components/common/PageTitle/index.tsx
+++ b/frontend/src/components/common/PageTitle/index.tsx
@@ -9,4 +9,4 @@ export const PageTitle = ({children}: PageTitleProps) => {
return (
<h1 className={classes.title}>{children}</h1>
);
-}
\ No newline at end of file
+}
diff --git a/frontend/src/components/common/Popover/index.tsx b/frontend/src/components/common/Popover/index.tsx
index 558b96e88..ea1114103 100644
--- a/frontend/src/components/common/Popover/index.tsx
+++ b/frontend/src/components/common/Popover/index.tsx
@@ -20,4 +20,4 @@ export const Popover = ({children, title, ...props}: PopoverProps) => {
</MantinePopover.Dropdown>
</MantinePopover>
);
-}
\ No newline at end of file
+}
diff --git a/frontend/src/components/forms/CapaciyAssigmentForm/index.tsx b/frontend/src/components/forms/CapaciyAssigmentForm/index.tsx
new file mode 100644
index 000000000..8016483a3
--- /dev/null
+++ b/frontend/src/components/forms/CapaciyAssigmentForm/index.tsx
@@ -0,0 +1,102 @@
+import {InputGroup} from "../../common/InputGroup";
+import {MultiSelect, NumberInput, TextInput} from "@mantine/core";
+import {t} from "@lingui/macro";
+import {UseFormReturnType} from "@mantine/form";
+import {CapacityAssignmentRequest, Ticket} from "../../../types.ts";
+import {CustomSelect, ItemProps} from "../../common/CustomSelect";
+import {
+ IconCalendarEvent,
+ IconCash, IconCheck,
+ IconCoinOff,
+ IconCoins, IconCross,
+ IconHeartDollar,
+ IconSwitch,
+ IconTicket, IconX
+} from "@tabler/icons-react";
+
+interface CapaciyAssigmentFormProps {
+ form: UseFormReturnType<CapacityAssignmentRequest>;
+ tickets: Ticket[],
+}
+
+export const CapaciyAssigmentForm = ({form, tickets}: CapaciyAssigmentFormProps) => {
+ const ticketOptions: ItemProps[] = [
+ {
+ icon: <IconCalendarEvent/>,
+ label: t`Applies to entire event`,
+ value: 'EVENT',
+ description: t`Capaciy applies to the entire event`,
+ },
+ {
+ icon: <IconTicket/>,
+ label: t`Applies to specific tickets`,
+ value: 'TICKETS',
+ description: t`Capacity applies to specific tickets`,
+ },
+ ];
+
+ const statusOptions: ItemProps[] = [
+ {
+ icon: <IconCheck/>,
+ label: t`Active`,
+ value: 'ACTIVE',
+ description: t`Enabled this capacity and enforce it during ticket sales`,
+ },
+ {
+ icon: <IconX/>,
+ label: t`Inactive`,
+ value: 'INACTIVE',
+ description: t`Disable this capacity and do not enforce it during ticket sales`,
+ },
+ ];
+
+ return (
+ <>
+ <InputGroup>
+ <TextInput
+ {...form.getInputProps('name')}
+ required
+ label={t`Name`}
+ placeholder={t`Day One Capacity`}
+ />
+ <NumberInput
+ {...form.getInputProps('capacity')}
+ label={t`Capacity`}
+ placeholder={t`Unlimited`}
+ />
+ </InputGroup>
+
+ <CustomSelect
+ label={t`What does this capacity apply to?`}
+ required
+ form={form}
+ name={'applies_to'}
+ optionList={ticketOptions}
+ />
+
+ {form.values.applies_to === 'TICKETS' && (
+ <MultiSelect
+ mt={20}
+ label={t`What tickets should this question be apply to?`}
+ multiple
+ data={tickets?.map(ticket => {
+ return {
+ value: String(ticket.id),
+ label: ticket.title,
+ }
+ })}
+ leftSection={<IconTicket size="1rem"/>}
+ {...form.getInputProps('ticket_ids')}
+ />
+ )}
+
+ <CustomSelect
+ label={t`Status`}
+ required
+ form={form}
+ name={'status'}
+ optionList={statusOptions}
+ />
+ </>
+ );
+}
diff --git a/frontend/src/components/layouts/Event/index.tsx b/frontend/src/components/layouts/Event/index.tsx
index cf3f35c45..3a0f094c3 100644
--- a/frontend/src/components/layouts/Event/index.tsx
+++ b/frontend/src/components/layouts/Event/index.tsx
@@ -16,7 +16,7 @@ import {
IconStar,
IconTicket,
IconUserQuestion,
- IconUsers,
+ IconUsers, IconUsersGroup,
IconWebhook
} from "@tabler/icons-react";
import {useState} from "react";
@@ -44,14 +44,15 @@ const EventLayout = () => {
{link: 'questions', label: t`Questions`, icon: IconUserQuestion},
{link: 'promo-codes', label: t`Promo Codes`, icon: IconDiscount2},
{link: 'messages', label: t`Messages`, icon: IconSend},
+ {link: 'capacity-assignments', label: t`Capacity`, icon: IconUsersGroup},
{label: t`Tools`},
{link: 'homepage-designer', label: t`Homepage Designer`, icon: IconPaint},
{link: 'widget', label: t`Widget Embed`, icon: IconDeviceTabletCode},
{link: 'check-in', label: t`Check-In`, icon: IconQrcode},
// { link: 'check-in', label: t`Interested People`, icon: IconBellHeart, comingSoon: true },
- {link: '/', label: t`Affiliates`, icon: IconAffiliate, comingSoon: true},
- {link: '/', label: t`Integrations`, icon: IconWebhook, comingSoon: true},
+ // {link: '/', label: t`Affiliates`, icon: IconAffiliate, comingSoon: true},
+ // {link: '/', label: t`Integrations`, icon: IconWebhook, comingSoon: true},
];
const [sidebarOpen, setSidebarOpen] = useState(false);
const {eventId} = useParams();
@@ -202,4 +203,4 @@ const EventLayout = () => {
)
}
-export default EventLayout;
\ No newline at end of file
+export default EventLayout;
diff --git a/frontend/src/components/modals/CreateCapacityAssignmentModal/index.tsx b/frontend/src/components/modals/CreateCapacityAssignmentModal/index.tsx
new file mode 100644
index 000000000..c0f76d0f0
--- /dev/null
+++ b/frontend/src/components/modals/CreateCapacityAssignmentModal/index.tsx
@@ -0,0 +1,55 @@
+import {CapacityAssignmentRequest, GenericModalProps, Ticket} from "../../../types.ts";
+import {Modal} from "../../common/Modal";
+import {t} from "@lingui/macro";
+import {CapaciyAssigmentForm} from "../../forms/CapaciyAssigmentForm";
+import {useForm} from "@mantine/form";
+import {Button} from "@mantine/core";
+import {useCreateCapacityAssignment} from "../../../mutations/useCreateCapacityAssignment.ts";
+import {showSuccess} from "../../../utilites/notifications.tsx";
+import {useParams} from "react-router-dom";
+import {useFormErrorResponseHandler} from "../../../hooks/useFormErrorResponseHandler.tsx";
+import {useGetEvent} from "../../../queries/useGetEvent.ts";
+
+export const CreateCapacityAssignmentModal = ({onClose}: GenericModalProps) => {
+ const {eventId} = useParams();
+ const errorHandler = useFormErrorResponseHandler();
+ const {data: event} = useGetEvent(eventId);
+ const form = useForm<CapacityAssignmentRequest>({
+ initialValues: {
+ name: '',
+ capacity: undefined,
+ applies_to: 'EVENT',
+ status: 'ACTIVE',
+ ticket_ids: [],
+ }
+ });
+ const createMutation = useCreateCapacityAssignment();
+
+ const handleSubmit = (requestData: CapacityAssignmentRequest) => {
+ createMutation.mutate({
+ eventId: eventId,
+ capacityAssignmentData: requestData,
+ }, {
+ onSuccess: () => {
+ showSuccess(t`Capacity Assignment created successfully`);
+ onClose();
+ },
+ onError: (error) => errorHandler(form, error),
+ })
+ }
+
+ return (
+ <Modal opened onClose={onClose} heading={t`Create Capacity Assignment`}>
+ <form onSubmit={form.onSubmit(handleSubmit)}>
+ {event && <CapaciyAssigmentForm form={form} tickets={event.tickets as Ticket[]}/>}
+ <Button
+ type={'submit'}
+ fullWidth
+ loading={createMutation.isLoading}
+ >
+ {t`Create Capacity Assignment`}
+ </Button>
+ </form>
+ </Modal>
+ );
+}
diff --git a/frontend/src/components/routes/event/CapacityAssignments/index.tsx b/frontend/src/components/routes/event/CapacityAssignments/index.tsx
new file mode 100644
index 000000000..41fa6530f
--- /dev/null
+++ b/frontend/src/components/routes/event/CapacityAssignments/index.tsx
@@ -0,0 +1,34 @@
+import {PageBody} from "../../../common/PageBody";
+import {PageTitle} from "../../../common/PageTitle";
+import {t} from "@lingui/macro";
+import {useParams} from "react-router-dom";
+import {useGetEventCapacityAssignments} from "../../../../queries/useGetCapacityAssignments.ts";
+import {CapacityAssignmentList} from "../../../common/CapacityAssignmentList/index.tsx";
+import {TableSkeleton} from "../../../common/TableSkeleton";
+import {CreateCapacityAssignmentModal} from "../../../modals/CreateCapacityAssignmentModal";
+import {useDisclosure} from "@mantine/hooks";
+
+const CapacityAssignments = () => {
+ const {eventId} = useParams();
+ const {data: capacityAssignments} = useGetEventCapacityAssignments(eventId);
+ const [createModalOpen, {open: openCreateModal, close: closeCreateModal}] = useDisclosure(false);
+
+ return (
+ <PageBody>
+ <PageTitle>
+ {t`Capacity Management`}
+ </PageTitle>
+
+ <TableSkeleton isVisible={!capacityAssignments}/>
+
+ {capacityAssignments && <CapacityAssignmentList
+ capacityAssignments={capacityAssignments}
+ openCreateModal={openCreateModal}
+ />}
+
+ {createModalOpen && <CreateCapacityAssignmentModal onClose={closeCreateModal}/>}
+ </PageBody>
+ );
+}
+
+export default CapacityAssignments;
diff --git a/frontend/src/mutations/useCreateCapacityAssignment.ts b/frontend/src/mutations/useCreateCapacityAssignment.ts
new file mode 100644
index 000000000..bdbd00d24
--- /dev/null
+++ b/frontend/src/mutations/useCreateCapacityAssignment.ts
@@ -0,0 +1,18 @@
+import {useMutation, useQueryClient} from "@tanstack/react-query";
+import {CapacityAssignmentRequest, IdParam} from "../types.ts";
+import {GET_EVENT_CAPACITY_ASSIGNMENTS_QUERY_KEY} from "../queries/useGetCapacityAssignments.ts";
+import {capacityAssignmentClient} from "../api/capacity-assignment.client.ts";
+
+export const useCreateCapacityAssignment = () => {
+ const queryClient = useQueryClient();
+
+ return useMutation(
+ ({capacityAssignmentData, eventId}: {
+ eventId: IdParam,
+ capacityAssignmentData: CapacityAssignmentRequest,
+ }) => capacityAssignmentClient.create(eventId, capacityAssignmentData),
+ {
+ onSuccess: () => queryClient.invalidateQueries({queryKey: [GET_EVENT_CAPACITY_ASSIGNMENTS_QUERY_KEY]}),
+ }
+ )
+}
diff --git a/frontend/src/queries/useGetCapacityAssignments.ts b/frontend/src/queries/useGetCapacityAssignments.ts
new file mode 100644
index 000000000..594291b68
--- /dev/null
+++ b/frontend/src/queries/useGetCapacityAssignments.ts
@@ -0,0 +1,15 @@
+import {useQuery} from "@tanstack/react-query";
+import {IdParam} from "../types.ts";
+import {capacityAssignmentClient} from "../api/capacity-assignment.client.ts";
+
+export const GET_EVENT_CAPACITY_ASSIGNMENTS_QUERY_KEY = 'getEventCapacityAssignments';
+
+export const useGetEventCapacityAssignments = (eventId: IdParam) => {
+ return useQuery(
+ [GET_EVENT_CAPACITY_ASSIGNMENTS_QUERY_KEY, eventId],
+ async () => {
+ const {data} = await capacityAssignmentClient.all(eventId);
+ return data;
+ }
+ )
+};
diff --git a/frontend/src/router.tsx b/frontend/src/router.tsx
index 829d34687..e3be87ccb 100644
--- a/frontend/src/router.tsx
+++ b/frontend/src/router.tsx
@@ -299,6 +299,13 @@ export const router: RouteObject[] = [
const GettingStarted = await import("./components/routes/event/GettingStarted");
return {Component: GettingStarted.default};
}
+ },
+ {
+ path: "capacity-assignments",
+ async lazy() {
+ const CapacityAssignments = await import("./components/routes/event/CapacityAssignments");
+ return {Component: CapacityAssignments.default};
+ }
}
]
},
diff --git a/frontend/src/types.ts b/frontend/src/types.ts
index ada5d99e2..46ebeec06 100644
--- a/frontend/src/types.ts
+++ b/frontend/src/types.ts
@@ -19,26 +19,21 @@ export interface AcceptInvitationRequest {
password_confirmation: string;
}
-export interface RegisterAccountRequest {
- first_name: string;
- last_name: string;
- email: string;
- password: string;
- password_confirmation: string;
+export interface RegisterAccountRequest extends AcceptInvitationRequest {
locale: SupportedLocales;
}
export interface ResetPasswordRequest {
password: string;
password_confirmation: string;
- }
+}
export interface LoginResponse {
- token?: string
- token_type: string
- expires_in: number
- user: User,
- accounts: Account[],
+ token?: string;
+ token_type: string;
+ expires_in: number;
+ user: User;
+ accounts: Account[];
}
export interface User {
@@ -71,7 +66,7 @@ export interface Account {
}
export interface StripeConnectDetails {
- account: Account,
+ account: Account;
stripe_account_id: string;
is_connect_setup_complete: boolean;
connect_url: string;
@@ -148,26 +143,15 @@ export interface Event extends EventBase {
slug: string;
status?: 'DRAFT' | 'LIVE' | 'PAUSED';
description_preview?: string;
-
lifecycle_status?: 'ONGOING' | 'UPCOMING' | 'ENDED';
-
settings?: EventSettings;
- tickets?: Ticket[],
- images?: Image[],
- organizer?: Organizer,
- currency: string,
- timezone: string,
- organizer_id?: IdParam,
-
- location_details?: {
- venue_name?: string,
- address_line_1?: string,
- address_line_2?: string,
- city?: string,
- state_or_region?: string,
- zip_or_postal_code?: string,
- country?: string,
- },
+ tickets?: Ticket[];
+ images?: Image[];
+ organizer?: Organizer;
+ currency: string;
+ timezone: string;
+ organizer_id?: IdParam;
+ location_details?: VenueAddress;
}
export interface EventDailyStats {
@@ -233,7 +217,7 @@ export interface PaginationData {
}
export interface GenericDataResponse<T> {
- data: T
+ data: T;
}
export interface GenericPaginatedResponse<T> {
@@ -277,8 +261,8 @@ export interface Ticket {
id?: number;
order?: number;
title: string;
- event_id?: IdParam,
- type: TicketType,
+ event_id?: IdParam;
+ type: TicketType;
description?: string;
price?: number;
prices?: TicketPrice[];
@@ -298,7 +282,7 @@ export interface Ticket {
status?: TicketStatus;
is_sold_out?: boolean;
is_available?: boolean;
- is_hidden_without_promo_code?: boolean,
+ is_hidden_without_promo_code?: boolean;
is_before_sale_start_date?: boolean;
is_after_sale_end_date?: boolean;
taxes?: TaxAndFee[];
@@ -364,7 +348,7 @@ export interface Order {
total_gross: number;
total_gross_after_refund: number;
total_refunded: number;
- is_expired: boolean,
+ is_expired: boolean;
order_items?: OrderItem[];
attendees?: Attendee[];
created_at: string;
@@ -401,27 +385,45 @@ export interface StripePaymentIntent {
}
export interface Question {
- id?: number,
- title: string,
- description?: string,
- required: boolean,
- type: string,
- options: string[],
- event_id?: number,
- tickets?: Ticket[], // remove
- ticket_ids?: number[],
+ id?: number;
+ title: string;
+ description?: string;
+ required: boolean;
+ type: string;
+ options: string[];
+ event_id?: number;
+ tickets?: Ticket[];
+ ticket_ids?: number[];
belongs_to: string;
is_hidden: boolean;
}
+export interface CapacityAssignment {
+ id?: number;
+ event_id: number;
+ name: string;
+ used_capacity: number;
+ applies_to: 'TICKETS' | 'EVENT';
+ status: 'ACTIVE' | 'INACTIVE';
+ capacity: number | undefined;
+ tickets: {
+ id: number;
+ title: string;
+ }[];
+}
+
+export type CapacityAssignmentRequest = Omit<CapacityAssignment, 'id' | 'event_id' | 'used_capacity'> & {
+ ticket_ids: number[];
+};
+
export interface QuestionRequestData {
- title: string,
- description?: string,
- required: boolean,
- is_hidden: boolean,
- type: string,
- options: string[],
- ticket_ids?: string[],
+ title: string;
+ description?: string;
+ required: boolean;
+ is_hidden: boolean;
+ type: string;
+ options: string[];
+ ticket_ids?: string[];
belongs_to: string;
}
@@ -444,7 +446,6 @@ export interface Message {
export enum QuestionType {
ADDRESS = 'ADDRESS',
-
SINGLE_LINE_TEXT = 'SINGLE_LINE_TEXT',
MULTI_LINE_TEXT = 'MULTI_LINE_TEXT',
CHECKBOX = 'CHECKBOX',
@@ -458,7 +459,7 @@ export enum QuestionBelongsToType {
}
export type QueryFilterFields = {
- [key: string]: string | string[] | number | number[] | boolean | boolean[] | undefined
+ [key: string]: string | string[] | number | number[] | boolean | boolean[] | undefined;
}
export interface QueryFilters {
@@ -471,8 +472,8 @@ export interface QueryFilters {
}
export interface GenericModalProps {
- onClose: () => void,
- isOpen?: boolean,
+ onClose: () => void;
+ isOpen?: boolean;
}
export interface MessageOrderRequest {
@@ -510,7 +511,6 @@ export enum PromoCodeDiscountType {
export enum TaxAndFeeType {
Tax = 'TAX',
Fee = 'FEE',
-
}
export enum TaxAndFeeCalculationType {
@@ -521,7 +521,7 @@ export enum TaxAndFeeCalculationType {
export interface TaxAndFee {
id?: number;
name: string;
- rate: number | undefined
+ rate: number | undefined;
type: TaxAndFeeType;
calculation_type: TaxAndFeeCalculationType;
is_default: boolean;
@@ -548,10 +548,8 @@ export interface QuestionAnswer {
answer: string[] | string;
text_answer: string;
order_id: number;
- belongs_to: string; // Assuming this is a string, adjust based on actual data type
+ belongs_to: string;
question_type: string;
-
- // Optional properties, assuming they can be null based on your PHP code
attendee_id?: number;
first_name?: string;
last_name?: string;