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/EmailTemplateDomainObject.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace HiEvents\DomainObjects;

class EmailTemplateDomainObject extends Generated\EmailTemplateDomainObjectAbstract
{
}
19 changes: 19 additions & 0 deletions backend/app/DomainObjects/Enums/EmailTemplateEngine.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace HiEvents\DomainObjects\Enums;

enum EmailTemplateEngine: string
{
use BaseEnum;

case LIQUID = 'liquid';
case BLADE = 'blade'; // For future use

public function label(): string
{
return match ($this) {
self::LIQUID => __('Liquid'),
self::BLADE => __('Blade'),
};
}
}
27 changes: 27 additions & 0 deletions backend/app/DomainObjects/Enums/EmailTemplateType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace HiEvents\DomainObjects\Enums;

enum EmailTemplateType: string
{
use BaseEnum;

case ORDER_CONFIRMATION = 'order_confirmation';
case ATTENDEE_TICKET = 'attendee_ticket';

public function label(): string
{
return match ($this) {
self::ORDER_CONFIRMATION => __('Order Confirmation'),
self::ATTENDEE_TICKET => __('Attendee Ticket'),
};
}

public function description(): string
{
return match ($this) {
self::ORDER_CONFIRMATION => __('Sent to the customer after placing an order'),
self::ATTENDEE_TICKET => __('Sent to each attendee with their ticket'),
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
<?php

namespace HiEvents\DomainObjects\Generated;

/**
* THIS FILE IS AUTOGENERATED - DO NOT EDIT IT DIRECTLY.
* @package HiEvents\DomainObjects\Generated
*/
abstract class EmailTemplateDomainObjectAbstract extends \HiEvents\DomainObjects\AbstractDomainObject
{
final public const SINGULAR_NAME = 'email_template';
final public const PLURAL_NAME = 'email_templates';
final public const ID = 'id';
final public const ACCOUNT_ID = 'account_id';
final public const ORGANIZER_ID = 'organizer_id';
final public const EVENT_ID = 'event_id';
final public const TEMPLATE_TYPE = 'template_type';
final public const SUBJECT = 'subject';
final public const BODY = 'body';
final public const CTA = 'cta';
final public const ENGINE = 'engine';
final public const IS_ACTIVE = 'is_active';
final public const CREATED_AT = 'created_at';
final public const UPDATED_AT = 'updated_at';

protected int $id;
protected int $account_id;
protected ?int $organizer_id = null;
protected ?int $event_id = null;
protected string $template_type;
protected string $subject;
protected string $body;
protected array|string|null $cta = null;
protected string $engine = 'liquid';
protected bool $is_active = true;
protected ?string $created_at = null;
protected ?string $updated_at = null;

public function toArray(): array
{
return [
'id' => $this->id ?? null,
'account_id' => $this->account_id ?? null,
'organizer_id' => $this->organizer_id ?? null,
'event_id' => $this->event_id ?? null,
'template_type' => $this->template_type ?? null,
'subject' => $this->subject ?? null,
'body' => $this->body ?? null,
'cta' => $this->cta ?? null,
'engine' => $this->engine ?? null,
'is_active' => $this->is_active ?? null,
'created_at' => $this->created_at ?? null,
'updated_at' => $this->updated_at ?? null,
];
}

public function setId(int $id): self
{
$this->id = $id;
return $this;
}

public function getId(): int
{
return $this->id;
}

public function setAccountId(int $account_id): self
{
$this->account_id = $account_id;
return $this;
}

public function getAccountId(): int
{
return $this->account_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 setEventId(?int $event_id): self
{
$this->event_id = $event_id;
return $this;
}

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

public function setTemplateType(string $template_type): self
{
$this->template_type = $template_type;
return $this;
}

public function getTemplateType(): string
{
return $this->template_type;
}

public function setSubject(string $subject): self
{
$this->subject = $subject;
return $this;
}

public function getSubject(): string
{
return $this->subject;
}

public function setBody(string $body): self
{
$this->body = $body;
return $this;
}

public function getBody(): string
{
return $this->body;
}

public function setCta(array|string|null $cta): self
{
$this->cta = $cta;
return $this;
}

public function getCta(): array|string|null
{
return $this->cta;
}

public function setEngine(string $engine): self
{
$this->engine = $engine;
return $this;
}

public function getEngine(): string
{
return $this->engine;
}

public function setIsActive(bool $is_active): self
{
$this->is_active = $is_active;
return $this;
}

public function getIsActive(): bool
{
return $this->is_active;
}

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;
}
}
10 changes: 10 additions & 0 deletions backend/app/Exceptions/EmailTemplateNotFoundException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace HiEvents\Exceptions;

use Exception;

class EmailTemplateNotFoundException extends Exception
{

}
10 changes: 10 additions & 0 deletions backend/app/Exceptions/EmailTemplateValidationException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace HiEvents\Exceptions;

use Exception;

class EmailTemplateValidationException extends Exception
{
public array $validationErrors = [];
}
10 changes: 10 additions & 0 deletions backend/app/Exceptions/InvalidEmailTemplateException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace HiEvents\Exceptions;

use Exception;

class InvalidEmailTemplateException extends Exception
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace HiEvents\Http\Actions\EmailTemplates;

use HiEvents\DomainObjects\Enums\EmailTemplateType;
use HiEvents\Http\Actions\BaseAction;
use HiEvents\Services\Application\Handlers\EmailTemplate\DTO\PreviewEmailTemplateDTO;
use HiEvents\Services\Application\Handlers\EmailTemplate\PreviewEmailTemplateHandler;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\Rules\Enum;

abstract class BaseEmailTemplateAction extends BaseAction
{
protected function validateEmailTemplateRequest(Request $request): array
{
return $request->validate([
'template_type' => ['required', new Enum(EmailTemplateType::class)],
'subject' => ['required', 'string', 'max:255'],
'body' => ['required', 'string'],
'ctaLabel' => ['required', 'string', 'max:100'],
'isActive' => ['boolean'],
]);
}

protected function validateUpdateEmailTemplateRequest(Request $request): array
{
return $request->validate([
'subject' => ['required', 'string', 'max:255'],
'body' => ['required', 'string'],
'ctaLabel' => ['required', 'string', 'max:100'],
'isActive' => ['boolean'],
]);
}

protected function validatePreviewRequest(Request $request): array
{
return $request->validate([
'template_type' => ['required', new Enum(EmailTemplateType::class)],
'subject' => ['required', 'string', 'max:255'],
'body' => ['required', 'string'],
'ctaLabel' => ['required', 'string', 'max:100'],
]);
}

protected function handlePreviewRequest(Request $request, PreviewEmailTemplateHandler $handler): JsonResponse
{
$validated = $this->validatePreviewRequest($request);

$cta = [
'label' => $validated['ctaLabel'],
'url_token' => $validated['template_type'] === 'order_confirmation' ? 'order.url' : 'ticket.url',
];

$preview = $handler->handle(
new PreviewEmailTemplateDTO(
subject: $validated['subject'],
body: $validated['body'],
template_type: EmailTemplateType::from($validated['template_type']),
cta: $cta,
)
);

return $this->jsonResponse($preview);
}
}
Loading
Loading