Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace HiEvents\Http\Actions\Admin\Organizers;

use HiEvents\DomainObjects\Enums\Role;
use HiEvents\Http\Actions\BaseAction;
use HiEvents\Resources\Organizer\AdminOrganizerResource;
use HiEvents\Services\Application\Handlers\Admin\DTO\GetAllOrganizersDTO;
use HiEvents\Services\Application\Handlers\Admin\GetAllOrganizersHandler;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class GetAllOrganizersAction extends BaseAction
{
public function __construct(
private readonly GetAllOrganizersHandler $handler,
) {}

public function __invoke(Request $request): JsonResponse
{
$this->minimumAllowedRole(Role::SUPERADMIN);

$organizers = $this->handler->handle(new GetAllOrganizersDTO(
perPage: min((int) $request->query('per_page', 20), 100),
search: $request->query('search'),
));

return $this->resourceResponse(
resource: AdminOrganizerResource::class,
data: $organizers,
);
}
}
5 changes: 5 additions & 0 deletions backend/app/Http/Actions/Events/UpdateEventAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use HiEvents\DomainObjects\EventDomainObject;
use HiEvents\Exceptions\CannotChangeCurrencyException;
use HiEvents\Exceptions\OrganizerNotFoundException;
use HiEvents\Http\Actions\BaseAction;
use HiEvents\Http\Request\Event\UpdateEventRequest;
use HiEvents\Resources\Event\EventResource;
Expand Down Expand Up @@ -46,6 +47,10 @@ public function __invoke(UpdateEventRequest $request, int $eventId): JsonRespons
throw ValidationException::withMessages([
'currency' => $exception->getMessage(),
]);
} catch (OrganizerNotFoundException $exception) {
throw ValidationException::withMessages([
'organizer_id' => $exception->getMessage(),
]);
}

return $this->resourceResponse(EventResource::class, $event);
Expand Down
4 changes: 2 additions & 2 deletions backend/app/Http/Request/Event/UpdateEventRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class UpdateEventRequest extends BaseRequest

public function rules(): array
{
$rules = $this->eventRules();
unset($rules['organizer_id']);
$rules = $this->eventRules();
$rules['organizer_id'] = ['sometimes', 'integer'];

return $rules;
}
Expand Down
6 changes: 6 additions & 0 deletions backend/app/Models/Organizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace HiEvents\Models;

use HiEvents\Models\Traits\HasImages;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\SoftDeletes;
Expand All @@ -12,6 +13,11 @@ class Organizer extends BaseModel
use SoftDeletes;
use HasImages;

public function account(): BelongsTo
{
return $this->belongsTo(Account::class);
}

public function events(): HasMany
{
return $this->hasMany(Event::class);
Expand Down
17 changes: 17 additions & 0 deletions backend/app/Repository/Eloquent/OrganizerRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,23 @@ public function getSitemapOrganizerCount(): int
->count();
}

public function getAllOrganizersForAdmin(?string $search, int $perPage): LengthAwarePaginator
{
$query = $this->model->query()->with(['account', 'organizer_settings']);

if ($search) {
$query->where(function ($q) use ($search) {
$q->where('name', 'ilike', "%$search%")
->orWhere('email', 'ilike', "%$search%")
->orWhereHas('account', function ($accountQuery) use ($search) {
$accountQuery->where('name', 'ilike', "%$search%");
});
});
}

return $query->orderBy('created_at', 'desc')->paginate($perPage);
}

public function getOrganizerStats(int $organizerId, int $accountId, string $currencyCode): OrganizerStatsResponseDTO
{
$totalsQuery = <<<SQL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ public function getOrganizerStats(int $organizerId, int $accountId, string $curr
public function getSitemapOrganizers(int $page, int $perPage): LengthAwarePaginator;

public function getSitemapOrganizerCount(): int;

public function getAllOrganizersForAdmin(?string $search, int $perPage): LengthAwarePaginator;
}
1 change: 1 addition & 0 deletions backend/app/Resources/Event/EventResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function toArray(Request $request): array
{
return [
'id' => $this->getId(),
'organizer_id' => $this->getOrganizerId(),
'title' => $this->getTitle(),
'category' => $this->getCategory(),
'description' => $this->getDescription(),
Expand Down
32 changes: 32 additions & 0 deletions backend/app/Resources/Organizer/AdminOrganizerResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace HiEvents\Resources\Organizer;

use HiEvents\Resources\BaseResource;
use Illuminate\Http\Request;

class AdminOrganizerResource extends BaseResource
{
public function toArray(Request $request): array
{
$account = $this->resource->account;

return [
'id' => $this->resource->id,
'name' => $this->resource->name,
'email' => $this->resource->email,
'phone' => $this->resource->phone,
'website' => $this->resource->website,
'currency' => $this->resource->currency,
'timezone' => $this->resource->timezone,
'status' => $this->resource->status,
'created_at' => $this->resource->created_at,
'updated_at' => $this->resource->updated_at,
'account' => $account ? [
'id' => $account->id,
'name' => $account->name,
'email' => $account->email,
] : null,
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace HiEvents\Services\Application\Handlers\Admin\DTO;

use HiEvents\DataTransferObjects\BaseDataObject;

class GetAllOrganizersDTO extends BaseDataObject
{
public function __construct(
public readonly int $perPage = 20,
public readonly ?string $search = null,
) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace HiEvents\Services\Application\Handlers\Admin;

use HiEvents\Repository\Interfaces\OrganizerRepositoryInterface;
use HiEvents\Services\Application\Handlers\Admin\DTO\GetAllOrganizersDTO;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;

class GetAllOrganizersHandler
{
public function __construct(
private readonly OrganizerRepositoryInterface $organizerRepository,
) {}

public function handle(GetAllOrganizersDTO $dto): LengthAwarePaginator
{
return $this->organizerRepository->getAllOrganizersForAdmin(
search: $dto->search,
perPage: $dto->perPage,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function __construct(
public readonly ?string $location = null,
public readonly ?AddressDTO $location_details = null,
public readonly ?string $status = EventStatus::DRAFT->name,
public readonly ?int $organizer_id = null,
)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
use HiEvents\Events\EventUpdateEvent;
use HiEvents\Exceptions\CannotChangeCurrencyException;
use HiEvents\Helper\DateHelper;
use HiEvents\Exceptions\OrganizerNotFoundException;
use HiEvents\Repository\Interfaces\EventRepositoryInterface;
use HiEvents\Repository\Interfaces\OrderRepositoryInterface;
use HiEvents\Services\Application\Handlers\Event\DTO\UpdateEventDTO;
use HiEvents\Services\Domain\Organizer\OrganizerFetchService;
use HiEvents\Services\Infrastructure\HtmlPurifier\HtmlPurifierService;
use HiEvents\Jobs\Event\Webhook\DispatchEventWebhookJob;
use HiEvents\Services\Infrastructure\DomainEvents\Enums\DomainEventType;
Expand All @@ -26,6 +28,7 @@ public function __construct(
private DatabaseManager $databaseManager,
private OrderRepositoryInterface $orderRepository,
private HtmlPurifierService $purifier,
private OrganizerFetchService $organizerFetchService,
)
{
}
Expand Down Expand Up @@ -60,6 +63,7 @@ private function fetchExistingEvent(UpdateEventDTO $eventData)

/**
* @throws CannotChangeCurrencyException
* @throws OrganizerNotFoundException
*/
private function updateEventAttributes(UpdateEventDTO $eventData): void
{
Expand All @@ -69,20 +73,28 @@ private function updateEventAttributes(UpdateEventDTO $eventData): void
$this->checkForCompletedOrders($eventData);
}

$attributes = [
'title' => $eventData->title,
'category' => $eventData->category?->value ?? $existingEvent->getCategory(),
'start_date' => DateHelper::convertToUTC($eventData->start_date, $eventData->timezone),
'end_date' => $eventData->end_date
? DateHelper::convertToUTC($eventData->end_date, $eventData->timezone)
: null,
'description' => $this->purifier->purify($eventData->description),
'timezone' => $eventData->timezone ?? $existingEvent->getTimezone(),
'currency' => $eventData->currency ?? $existingEvent->getCurrency(),
'location' => $eventData->location,
'location_details' => $eventData->location_details?->toArray(),
];

if ($eventData->organizer_id !== null && $eventData->organizer_id !== $existingEvent->getOrganizerId()) {
// Throws OrganizerNotFoundException if the organizer is not in this account.
$this->organizerFetchService->fetchOrganizer($eventData->organizer_id, $eventData->account_id);
$attributes['organizer_id'] = $eventData->organizer_id;
}

$this->eventRepository->updateWhere(
attributes: [
'title' => $eventData->title,
'category' => $eventData->category?->value ?? $existingEvent->getCategory(),
'start_date' => DateHelper::convertToUTC($eventData->start_date, $eventData->timezone),
'end_date' => $eventData->end_date
? DateHelper::convertToUTC($eventData->end_date, $eventData->timezone)
: null,
'description' => $this->purifier->purify($eventData->description),
'timezone' => $eventData->timezone ?? $existingEvent->getTimezone(),
'currency' => $eventData->currency ?? $existingEvent->getCurrency(),
'location' => $eventData->location,
'location_details' => $eventData->location_details?->toArray(),
],
attributes: $attributes,
where: [
'id' => $eventData->id,
'account_id' => $eventData->account_id,
Expand Down
2 changes: 2 additions & 0 deletions backend/routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
use HiEvents\Http\Actions\Admin\GetMessagingTiersAction;
use HiEvents\Http\Actions\Admin\Accounts\UpdateAccountMessagingTierAction;
use HiEvents\Http\Actions\Admin\Orders\GetAllOrdersAction;
use HiEvents\Http\Actions\Admin\Organizers\GetAllOrganizersAction as GetAllAdminOrganizersAction;
use HiEvents\Http\Actions\Admin\Attribution\GetUtmAttributionStatsAction;
use HiEvents\Http\Actions\Admin\GetSystemInfoAction;
use HiEvents\Http\Actions\Admin\Stats\GetAdminDashboardDataAction;
Expand Down Expand Up @@ -461,6 +462,7 @@ function (Router $router): void {
$router->put('/configurations/{configuration_id}', UpdateConfigurationAction::class);
$router->delete('/configurations/{configuration_id}', DeleteConfigurationAction::class);
$router->get('/users', GetAllUsersAction::class);
$router->get('/organizers', GetAllAdminOrganizersAction::class);
$router->get('/events', GetAllAdminEventsAction::class);
$router->get('/events/upcoming', GetUpcomingEventsAction::class);
$router->get('/orders', GetAllOrdersAction::class);
Expand Down
Loading
Loading