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
13 changes: 13 additions & 0 deletions backend/app/DataTransferObjects/UpdateAccountConfigurationDTO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace HiEvents\DataTransferObjects;

class UpdateAccountConfigurationDTO extends BaseDataObject
{
public function __construct(
public readonly int $accountId,
public readonly array $applicationFees,
)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace HiEvents\DataTransferObjects;

class UpdateAdminAccountVatSettingDTO extends BaseDataObject
{
public function __construct(
public readonly int $accountId,
public readonly bool $vatRegistered,
public readonly ?string $vatNumber = null,
public readonly ?bool $vatValidated = null,
public readonly ?string $businessName = null,
public readonly ?string $businessAddress = null,
public readonly ?string $vatCountryCode = null,
)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace HiEvents\Http\Actions\Admin\Accounts;

use HiEvents\DomainObjects\Enums\Role;
use HiEvents\Http\Actions\BaseAction;
use HiEvents\Services\Application\Handlers\Admin\AssignConfigurationHandler;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class AssignConfigurationAction extends BaseAction
{
public function __construct(
private readonly AssignConfigurationHandler $handler,
) {
}

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

$validated = $request->validate([
'configuration_id' => 'required|integer|exists:account_configuration,id',
]);

$this->handler->handle($accountId, (int) $validated['configuration_id']);

return $this->jsonResponse([
'message' => __('Configuration assigned successfully.'),
]);
}
}
29 changes: 29 additions & 0 deletions backend/app/Http/Actions/Admin/Accounts/GetAccountAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace HiEvents\Http\Actions\Admin\Accounts;

use HiEvents\DomainObjects\Enums\Role;
use HiEvents\Http\Actions\BaseAction;
use HiEvents\Resources\Account\AdminAccountDetailResource;
use HiEvents\Services\Application\Handlers\Admin\GetAccountHandler;
use Illuminate\Http\JsonResponse;

class GetAccountAction extends BaseAction
{
public function __construct(
private readonly GetAccountHandler $handler,
)
{
}

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

$account = $this->handler->handle($accountId);

return $this->jsonResponse(new AdminAccountDetailResource($account), wrapInData: true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace HiEvents\Http\Actions\Admin\Accounts;

use HiEvents\DataTransferObjects\UpdateAccountConfigurationDTO;
use HiEvents\DomainObjects\Enums\Role;
use HiEvents\Http\Actions\BaseAction;
use HiEvents\Resources\Account\AccountConfigurationResource;
use HiEvents\Services\Application\Handlers\Admin\UpdateAccountConfigurationHandler;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class UpdateAccountConfigurationAction extends BaseAction
{
public function __construct(
private readonly UpdateAccountConfigurationHandler $handler,
)
{
}

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

$validated = $request->validate([
'application_fees' => 'required|array',
'application_fees.fixed' => 'required|numeric|min:0',
'application_fees.percentage' => 'required|numeric|min:0|max:100',
]);

$configuration = $this->handler->handle(new UpdateAccountConfigurationDTO(
accountId: $accountId,
applicationFees: $validated['application_fees'],
));

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

declare(strict_types=1);

namespace HiEvents\Http\Actions\Admin\Accounts;

use HiEvents\DataTransferObjects\UpdateAdminAccountVatSettingDTO;
use HiEvents\DomainObjects\Enums\Role;
use HiEvents\Http\Actions\BaseAction;
use HiEvents\Resources\Account\AccountVatSettingResource;
use HiEvents\Services\Application\Handlers\Admin\UpdateAdminAccountVatSettingHandler;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class UpdateAccountVatSettingAction extends BaseAction
{
public function __construct(
private readonly UpdateAdminAccountVatSettingHandler $handler,
)
{
}

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

$validated = $request->validate([
'vat_registered' => 'required|boolean',
'vat_number' => 'nullable|string|max:20',
'vat_validated' => 'nullable|boolean',
'business_name' => 'nullable|string|max:255',
'business_address' => 'nullable|string|max:500',
'vat_country_code' => 'nullable|string|max:2',
]);

$vatSetting = $this->handler->handle(new UpdateAdminAccountVatSettingDTO(
accountId: $accountId,
vatRegistered: $validated['vat_registered'],
vatNumber: $validated['vat_number'] ?? null,
vatValidated: $validated['vat_validated'] ?? null,
businessName: $validated['business_name'] ?? null,
businessAddress: $validated['business_address'] ?? null,
vatCountryCode: $validated['vat_country_code'] ?? null,
));

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

declare(strict_types=1);

namespace HiEvents\Http\Actions\Admin\Configurations;

use HiEvents\DomainObjects\Enums\Role;
use HiEvents\Http\Actions\BaseAction;
use HiEvents\Repository\Interfaces\AccountConfigurationRepositoryInterface;
use HiEvents\Resources\Account\AccountConfigurationResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class CreateConfigurationAction extends BaseAction
{
public function __construct(
private readonly AccountConfigurationRepositoryInterface $repository,
) {
}

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

$validated = $request->validate([
'name' => 'required|string|max:255',
'application_fees' => 'required|array',
'application_fees.fixed' => 'required|numeric|min:0',
'application_fees.percentage' => 'required|numeric|min:0|max:100',
]);

$configuration = $this->repository->create([
'name' => $validated['name'],
'is_system_default' => false,
'application_fees' => $validated['application_fees'],
]);

return $this->jsonResponse(
new AccountConfigurationResource($configuration),
statusCode: Response::HTTP_CREATED,
wrapInData: true
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace HiEvents\Http\Actions\Admin\Configurations;

use HiEvents\DomainObjects\Enums\Role;
use HiEvents\Exceptions\CannotDeleteEntityException;
use HiEvents\Http\Actions\BaseAction;
use HiEvents\Services\Application\Handlers\Admin\DeleteConfigurationHandler;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Response;
use Illuminate\Validation\ValidationException;

class DeleteConfigurationAction extends BaseAction
{
public function __construct(
private readonly DeleteConfigurationHandler $handler,
) {
}

public function __invoke(int $configurationId): Response
{
$this->minimumAllowedRole(Role::SUPERADMIN);

try {
$this->handler->handle($configurationId);
} catch (CannotDeleteEntityException $e) {
throw ValidationException::withMessages([
'configuration' => [$e->getMessage()],
]);
}

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

declare(strict_types=1);

namespace HiEvents\Http\Actions\Admin\Configurations;

use HiEvents\DomainObjects\Enums\Role;
use HiEvents\Http\Actions\BaseAction;
use HiEvents\Repository\Interfaces\AccountConfigurationRepositoryInterface;
use HiEvents\Resources\Account\AccountConfigurationResource;
use Illuminate\Http\JsonResponse;

class GetAllConfigurationsAction extends BaseAction
{
public function __construct(
private readonly AccountConfigurationRepositoryInterface $repository,
) {
}

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

$configurations = $this->repository->all();

return $this->jsonResponse(
AccountConfigurationResource::collection($configurations),
wrapInData: true
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace HiEvents\Http\Actions\Admin\Configurations;

use HiEvents\DomainObjects\Enums\Role;
use HiEvents\Http\Actions\BaseAction;
use HiEvents\Repository\Interfaces\AccountConfigurationRepositoryInterface;
use HiEvents\Resources\Account\AccountConfigurationResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class UpdateConfigurationAction extends BaseAction
{
public function __construct(
private readonly AccountConfigurationRepositoryInterface $repository,
) {
}

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

$validated = $request->validate([
'name' => 'required|string|max:255',
'application_fees' => 'required|array',
'application_fees.fixed' => 'required|numeric|min:0',
'application_fees.percentage' => 'required|numeric|min:0|max:100',
]);

$configuration = $this->repository->updateFromArray(
id: $configurationId,
attributes: [
'name' => $validated['name'],
'application_fees' => $validated['application_fees'],
]
);

return $this->jsonResponse(
new AccountConfigurationResource($configuration),
wrapInData: true
);
}
}
39 changes: 39 additions & 0 deletions backend/app/Http/Actions/Admin/Orders/GetAllOrdersAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace HiEvents\Http\Actions\Admin\Orders;

use HiEvents\DomainObjects\Enums\Role;
use HiEvents\Http\Actions\BaseAction;
use HiEvents\Resources\Order\AdminOrderResource;
use HiEvents\Services\Application\Handlers\Admin\DTO\GetAllOrdersDTO;
use HiEvents\Services\Application\Handlers\Admin\GetAllOrdersHandler;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class GetAllOrdersAction extends BaseAction
{
public function __construct(
private readonly GetAllOrdersHandler $handler,
)
{
}

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

$orders = $this->handler->handle(new GetAllOrdersDTO(
perPage: min((int)$request->query('per_page', 20), 100),
search: $request->query('search'),
sortBy: $request->query('sort_by', 'created_at'),
sortDirection: $request->query('sort_direction', 'desc'),
));

return $this->resourceResponse(
resource: AdminOrderResource::class,
data: $orders
);
}
}
Loading
Loading