Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions backend/app/DomainObjects/AttendeeDomainObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

class AttendeeDomainObject extends Generated\AttendeeDomainObjectAbstract implements IsSortable, IsFilterable
{
public const TICKET_NAME_SORT_KEY = 'ticket_name';

private ?OrderDomainObject $order = null;

private ?ProductDomainObject $product = null;
Expand All @@ -30,6 +32,10 @@ public static function getAllowedSorts(): AllowedSorts
{
return new AllowedSorts(
[
self::TICKET_NAME_SORT_KEY => [
'asc' => __('Ticket Name A-Z'),
'desc' => __('Ticket Name Z-A'),
],
self::CREATED_AT => [
'asc' => __('Older First'),
'desc' => __('Newest First'),
Expand Down Expand Up @@ -64,6 +70,7 @@ public static function getAllowedFilterFields(): array
return [
self::STATUS,
self::PRODUCT_ID,
self::PRODUCT_PRICE_ID,
];
}

Expand Down
25 changes: 8 additions & 17 deletions backend/app/Http/Actions/Attendees/GetAttendeesAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,29 @@

use HiEvents\DomainObjects\AttendeeDomainObject;
use HiEvents\DomainObjects\EventDomainObject;
use HiEvents\DomainObjects\OrderDomainObject;
use HiEvents\Http\Actions\BaseAction;
use HiEvents\Http\DTO\QueryParamsDTO;
use HiEvents\Repository\Eloquent\Value\Relationship;
use HiEvents\Repository\Interfaces\AttendeeRepositoryInterface;
use HiEvents\Resources\Attendee\AttendeeResource;
use HiEvents\Services\Application\Handlers\Attendee\GetAttendeesHandler;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

/**
* @todo move to handler
* @todo - add validation for filter fields
*/
class GetAttendeesAction extends BaseAction
{
private AttendeeRepositoryInterface $attendeeRepository;

public function __construct(AttendeeRepositoryInterface $attendeeRepository)
public function __construct(
private readonly GetAttendeesHandler $getAttendeesHandler,
)
{
$this->attendeeRepository = $attendeeRepository;
}

public function __invoke(int $eventId, Request $request): JsonResponse
{
$this->isActionAuthorized($eventId, EventDomainObject::class);

$attendees = $this->attendeeRepository
->loadRelation(new Relationship(
domainObject: OrderDomainObject::class,
name: 'order'
))
->findByEventId($eventId, QueryParamsDTO::fromArray($request->query->all()));
$attendees = $this->getAttendeesHandler->handle(
eventId: $eventId,
queryParams: QueryParamsDTO::fromArray($request->query->all())
);

return $this->filterableResourceResponse(
resource: AttendeeResource::class,
Expand Down
22 changes: 17 additions & 5 deletions backend/app/Repository/Eloquent/AttendeeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use HiEvents\DomainObjects\Generated\AttendeeDomainObjectAbstract;
use HiEvents\DomainObjects\Status\AttendeeStatus;
use HiEvents\DomainObjects\Status\OrderStatus;
use HiEvents\Http\DTO\FilterFieldDTO;
use HiEvents\Http\DTO\QueryParamsDTO;
use HiEvents\Models\Attendee;
use HiEvents\Repository\Eloquent\Value\Relationship;
Expand Down Expand Up @@ -76,11 +77,22 @@ public function findByEventId(int $eventId, QueryParamsDTO $params): LengthAware

$this->model = $this->model->select('attendees.*')
->join('orders', 'orders.id', '=', 'attendees.order_id')
->whereIn('orders.status', [OrderStatus::COMPLETED->name, OrderStatus::CANCELLED->name, OrderStatus::AWAITING_OFFLINE_PAYMENT->name])
->orderBy(
'attendees.' . ($params->sort_by ?? AttendeeDomainObject::getDefaultSort()),
$params->sort_direction ?? 'desc',
);
->whereIn('orders.status', [OrderStatus::COMPLETED->name, OrderStatus::CANCELLED->name, OrderStatus::AWAITING_OFFLINE_PAYMENT->name]);

if ($params->filter_fields && $params->filter_fields->isNotEmpty()) {
$this->applyFilterFields($params, AttendeeDomainObject::getAllowedFilterFields(), prefix: 'attendees');
}

$sortBy = $params->sort_by ?? AttendeeDomainObject::getDefaultSort();
$sortDirection = $params->sort_direction ?? AttendeeDomainObject::getDefaultSortDirection();

if ($sortBy === AttendeeDomainObject::TICKET_NAME_SORT_KEY) {
$this->model = $this->model
->leftJoin('products', 'products.id', '=', 'attendees.product_id')
->orderBy('products.title', $sortDirection);
} else {
$this->model = $this->model->orderBy('attendees.' . $sortBy, $sortDirection);
}

return $this->paginateWhere(
where: $where,
Expand Down
14 changes: 10 additions & 4 deletions backend/app/Repository/Eloquent/BaseRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,14 @@ protected function handleSingleResult(
return $this->hydrateDomainObjectFromModel($model, $domainObjectOverride);
}

protected function applyFilterFields(QueryParamsDTO $params, array $allowedFilterFields = []): void
protected function applyFilterFields(
QueryParamsDTO $params,
array $allowedFilterFields = [],
?string $prefix = null,
): void
{
if ($params->filter_fields && $params->filter_fields->isNotEmpty()) {
$params->filter_fields->each(function ($filterField) use ($allowedFilterFields) {
$params->filter_fields->each(function ($filterField) use ($prefix, $allowedFilterFields) {
if (!in_array($filterField->field, $allowedFilterFields, true)) {
return;
}
Expand All @@ -412,6 +416,8 @@ protected function applyFilterFields(QueryParamsDTO $params, array $allowedFilte
sprintf('Operator %s is not supported', $filterField->operator)
);

$field = $prefix ? $prefix . '.' . $filterField->field : $filterField->field;

// Special handling for IN operator
if ($operator === 'IN') {
// Ensure value is array or convert comma-separated string to array
Expand All @@ -420,12 +426,12 @@ protected function applyFilterFields(QueryParamsDTO $params, array $allowedFilte
: explode(',', $filterField->value);

$this->model = $this->model->whereIn(
column: $filterField->field,
column: $field,
values: $value
);
} else {
$this->model = $this->model->where(
column: $filterField->field,
column: $field,
operator: $operator,
value: $isNull ? null : $filterField->value,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace HiEvents\Services\Application\Handlers\Attendee;

use HiEvents\DomainObjects\AttendeeCheckInDomainObject;
use HiEvents\DomainObjects\OrderDomainObject;
use HiEvents\Http\DTO\QueryParamsDTO;
use HiEvents\Repository\Eloquent\Value\Relationship;
use HiEvents\Repository\Interfaces\AttendeeRepositoryInterface;
use Illuminate\Pagination\LengthAwarePaginator;

class GetAttendeesHandler
{
public function __construct(
private readonly AttendeeRepositoryInterface $attendeeRepository,
)
{
}

public function handle(int $eventId, QueryParamsDTO $queryParams): LengthAwarePaginator
{
return $this->attendeeRepository
->loadRelation(new Relationship(
domainObject: OrderDomainObject::class,
name: 'order'
))
->loadRelation(new Relationship(
domainObject: AttendeeCheckInDomainObject::class,
name: 'check_ins'
))
->findByEventId($eventId, $queryParams);
}
}
8 changes: 5 additions & 3 deletions frontend/src/api/check-in-list.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
CheckInListRequest,
GenericDataResponse,
GenericPaginatedResponse,
IdParam, QueryFilters,
IdParam,
QueryFilters,
} from "../types";
import {queryParamsHelper} from "../utilites/queryParamsHelper.ts";

Expand All @@ -17,8 +18,9 @@ export const checkInListClient = {
const response = await api.put<GenericDataResponse<CheckInList>>(`events/${eventId}/check-in-lists/${checkInListId}`, checkInList);
return response.data;
},
all: async (eventId: IdParam, pagination: QueryFilters) => {
const response = await api.get<GenericPaginatedResponse<CheckInList>>(`events/${eventId}/check-in-lists` + queryParamsHelper.buildQueryString(pagination));
all: async (eventId: IdParam, pagination: QueryFilters | null = null) => {
const paginationQuery = (pagination) ? queryParamsHelper.buildQueryString(pagination as QueryFilters) : '';
const response = await api.get<GenericPaginatedResponse<CheckInList>>(`events/${eventId}/check-in-lists` + paginationQuery);
return response.data;
},
get: async (eventId: IdParam, checkInListId: IdParam) => {
Expand Down
Loading
Loading