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
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ abstract class WebhookDomainObjectAbstract extends \HiEvents\DomainObjects\Abstr
final public const ID = 'id';
final public const USER_ID = 'user_id';
final public const EVENT_ID = 'event_id';
final public const ORGANIZER_ID = 'organizer_id';
final public const ACCOUNT_ID = 'account_id';
final public const URL = 'url';
final public const EVENT_TYPES = 'event_types';
Expand All @@ -27,7 +28,8 @@ abstract class WebhookDomainObjectAbstract extends \HiEvents\DomainObjects\Abstr

protected int $id;
protected int $user_id;
protected int $event_id;
protected ?int $event_id = null;
protected ?int $organizer_id = null;
protected int $account_id;
protected string $url;
protected array|string $event_types;
Expand All @@ -46,6 +48,7 @@ public function toArray(): array
'id' => $this->id ?? null,
'user_id' => $this->user_id ?? null,
'event_id' => $this->event_id ?? null,
'organizer_id' => $this->organizer_id ?? null,
'account_id' => $this->account_id ?? null,
'url' => $this->url ?? null,
'event_types' => $this->event_types ?? null,
Expand Down Expand Up @@ -82,17 +85,28 @@ public function getUserId(): int
return $this->user_id;
}

public function setEventId(int $event_id): self
public function setEventId(?int $event_id): self
{
$this->event_id = $event_id;
return $this;
}

public function getEventId(): int
public function getEventId(): ?int
{
return $this->event_id;
}

public function setOrganizerId(?int $organizer_id): self
{
$this->organizer_id = $organizer_id;
return $this;
}

public function getOrganizerId(): ?int
{
return $this->organizer_id;
}

public function setAccountId(int $account_id): self
{
$this->account_id = $account_id;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace HiEvents\Http\Actions\Organizers\Webhooks;

use HiEvents\DomainObjects\OrganizerDomainObject;
use HiEvents\DomainObjects\Status\WebhookStatus;
use HiEvents\Http\Actions\BaseAction;
use HiEvents\Http\Request\Webhook\UpsertWebhookRequest;
use HiEvents\Resources\Webhook\WebhookResource;
use HiEvents\Services\Application\Handlers\Webhook\CreateWebhookHandler;
use HiEvents\Services\Application\Handlers\Webhook\DTO\CreateWebhookDTO;
use Illuminate\Http\JsonResponse;

class CreateOrganizerWebhookAction extends BaseAction
{
public function __construct(
private readonly CreateWebhookHandler $createWebhookHandler,
)
{
}

public function __invoke(int $organizerId, UpsertWebhookRequest $request): JsonResponse
{
$this->isActionAuthorized($organizerId, OrganizerDomainObject::class);

$webhook = $this->createWebhookHandler->handle(
new CreateWebhookDTO(
url: $request->validated('url'),
eventTypes: $request->validated('event_types'),
eventId: null,
organizerId: $organizerId,
userId: $this->getAuthenticatedUser()->getId(),
accountId: $this->getAuthenticatedAccountId(),
status: WebhookStatus::fromName($request->validated('status')),
)
);

return $this->resourceResponse(
resource: WebhookResource::class,
data: $webhook
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace HiEvents\Http\Actions\Organizers\Webhooks;

use HiEvents\DomainObjects\OrganizerDomainObject;
use HiEvents\Http\Actions\BaseAction;
use HiEvents\Services\Application\Handlers\Webhook\DeleteWebhookHandler;
use Illuminate\Http\Response;

class DeleteOrganizerWebhookAction extends BaseAction
{
public function __construct(
private readonly DeleteWebhookHandler $deleteWebhookHandler,
)
{
}

public function __invoke(int $organizerId, int $webhookId): Response
{
$this->isActionAuthorized($organizerId, OrganizerDomainObject::class);

$this->deleteWebhookHandler->handle(
webhookId: $webhookId,
eventId: null,
organizerId: $organizerId,
);

return $this->deletedResponse();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace HiEvents\Http\Actions\Organizers\Webhooks;

use HiEvents\DomainObjects\OrganizerDomainObject;
use HiEvents\DomainObjects\Status\WebhookStatus;
use HiEvents\Http\Actions\BaseAction;
use HiEvents\Http\Request\Webhook\UpsertWebhookRequest;
use HiEvents\Resources\Webhook\WebhookResource;
use HiEvents\Services\Application\Handlers\Webhook\DTO\EditWebhookDTO;
use HiEvents\Services\Application\Handlers\Webhook\EditWebhookHandler;
use Illuminate\Http\JsonResponse;

class EditOrganizerWebhookAction extends BaseAction
{
public function __construct(
private readonly EditWebhookHandler $editWebhookHandler,
)
{
}

public function __invoke(int $organizerId, int $webhookId, UpsertWebhookRequest $request): JsonResponse
{
$this->isActionAuthorized($organizerId, OrganizerDomainObject::class);

$webhook = $this->editWebhookHandler->handle(
new EditWebhookDTO(
webhookId: $webhookId,
url: $request->validated('url'),
eventTypes: $request->validated('event_types'),
eventId: null,
organizerId: $organizerId,
userId: $this->getAuthenticatedUser()->getId(),
accountId: $this->getAuthenticatedAccountId(),
status: WebhookStatus::fromName($request->validated('status')),
)
);

return $this->resourceResponse(
resource: WebhookResource::class,
data: $webhook
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace HiEvents\Http\Actions\Organizers\Webhooks;

use HiEvents\DomainObjects\OrganizerDomainObject;
use HiEvents\Http\Actions\BaseAction;
use HiEvents\Resources\Webhook\WebhookResource;
use HiEvents\Services\Application\Handlers\Webhook\GetWebhookHandler;
use Illuminate\Http\JsonResponse;

class GetOrganizerWebhookAction extends BaseAction
{
public function __construct(
private readonly GetWebhookHandler $getWebhookHandler,
)
{
}

public function __invoke(int $organizerId, int $webhookId): JsonResponse
{
$this->isActionAuthorized($organizerId, OrganizerDomainObject::class);

$webhook = $this->getWebhookHandler->handle(
webhookId: $webhookId,
eventId: null,
organizerId: $organizerId
);

return $this->resourceResponse(
resource: WebhookResource::class,
data: $webhook
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace HiEvents\Http\Actions\Organizers\Webhooks;

use HiEvents\DomainObjects\OrganizerDomainObject;
use HiEvents\DomainObjects\WebhookLogDomainObject;
use HiEvents\Http\Actions\BaseAction;
use HiEvents\Resources\Webhook\WebhookLogResource;
use HiEvents\Services\Application\Handlers\Webhook\GetWebhookLogsHandler;
use Illuminate\Http\JsonResponse;

class GetOrganizerWebhookLogsAction extends BaseAction
{
public function __construct(
private readonly GetWebhookLogsHandler $getWebhookLogsHandler,
)
{
}

public function __invoke(int $organizerId, int $webhookId): JsonResponse
{
$this->isActionAuthorized($organizerId, OrganizerDomainObject::class);

$webhookLogs = $this->getWebhookLogsHandler->handle(
webhookId: $webhookId,
eventId: null,
organizerId: $organizerId,
);

$webhookLogs = $webhookLogs->sortBy(function (WebhookLogDomainObject $webhookLog) {
return $webhookLog->getId();
}, SORT_REGULAR, true);

return $this->resourceResponse(
resource: WebhookLogResource::class,
data: $webhookLogs
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace HiEvents\Http\Actions\Organizers\Webhooks;

use HiEvents\DomainObjects\OrganizerDomainObject;
use HiEvents\Http\Actions\BaseAction;
use HiEvents\Resources\Webhook\WebhookResource;
use HiEvents\Services\Application\Handlers\Webhook\GetWebhooksHandler;
use Illuminate\Http\JsonResponse;

class GetOrganizerWebhooksAction extends BaseAction
{
public function __construct(
private readonly GetWebhooksHandler $getWebhooksHandler,
)
{
}

public function __invoke(int $organizerId): JsonResponse
{
$this->isActionAuthorized($organizerId, OrganizerDomainObject::class);

$webhooks = $this->getWebhooksHandler->handler(
accountId: $this->getAuthenticatedAccountId(),
eventId: null,
organizerId: $organizerId
);

return $this->resourceResponse(
resource: WebhookResource::class,
data: $webhooks
);
}
}
2 changes: 1 addition & 1 deletion backend/app/Http/Actions/Webhooks/CreateWebhookAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public function __invoke(int $eventId, UpsertWebhookRequest $request): JsonRespo
new CreateWebhookDTO(
url: $request->validated('url'),
eventTypes: $request->validated('event_types'),
eventId: $eventId,
userId: $this->getAuthenticatedUser()->getId(),
accountId: $this->getAuthenticatedAccountId(),
status: WebhookStatus::fromName($request->validated('status')),
eventId: $eventId,
)
);

Expand Down
4 changes: 2 additions & 2 deletions backend/app/Http/Actions/Webhooks/DeleteWebhookAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public function __invoke(int $eventId, int $webhookId): Response
$this->isActionAuthorized($eventId, EventDomainObject::class);

$this->deleteWebhookHandler->handle(
$eventId,
$webhookId,
webhookId: $webhookId,
eventId: $eventId,
);

return $this->deletedResponse();
Expand Down
31 changes: 31 additions & 0 deletions backend/app/Jobs/Event/Webhook/DispatchEventWebhookJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace HiEvents\Jobs\Event\Webhook;

use HiEvents\Services\Infrastructure\DomainEvents\Enums\DomainEventType;
use HiEvents\Services\Infrastructure\Webhook\WebhookDispatchService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class DispatchEventWebhookJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

public function __construct(
public int $eventId,
public DomainEventType $eventType,
)
{
}

public function handle(WebhookDispatchService $webhookDispatchService): void
{
$webhookDispatchService->dispatchEventWebhook(
eventType: $this->eventType,
eventId: $this->eventId,
);
}
}
5 changes: 5 additions & 0 deletions backend/app/Models/Organizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ public function organizer_settings(): HasOne
{
return $this->hasOne(OrganizerSetting::class);
}

public function webhooks(): HasMany
{
return $this->hasMany(Webhook::class);
}
}
5 changes: 5 additions & 0 deletions backend/app/Models/Webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public function event(): BelongsTo
return $this->belongsTo(Event::class);
}

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

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