Skip to content

Commit 5d3ae85

Browse files
authored
Feature: admin improvements (#940)
1 parent de5e9ad commit 5d3ae85

File tree

67 files changed

+4453
-105
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+4453
-105
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace HiEvents\DataTransferObjects;
4+
5+
class UpdateAccountConfigurationDTO extends BaseDataObject
6+
{
7+
public function __construct(
8+
public readonly int $accountId,
9+
public readonly array $applicationFees,
10+
)
11+
{
12+
}
13+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace HiEvents\DataTransferObjects;
4+
5+
class UpdateAdminAccountVatSettingDTO extends BaseDataObject
6+
{
7+
public function __construct(
8+
public readonly int $accountId,
9+
public readonly bool $vatRegistered,
10+
public readonly ?string $vatNumber = null,
11+
public readonly ?bool $vatValidated = null,
12+
public readonly ?string $businessName = null,
13+
public readonly ?string $businessAddress = null,
14+
public readonly ?string $vatCountryCode = null,
15+
)
16+
{
17+
}
18+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace HiEvents\Http\Actions\Admin\Accounts;
6+
7+
use HiEvents\DomainObjects\Enums\Role;
8+
use HiEvents\Http\Actions\BaseAction;
9+
use HiEvents\Services\Application\Handlers\Admin\AssignConfigurationHandler;
10+
use Illuminate\Http\JsonResponse;
11+
use Illuminate\Http\Request;
12+
13+
class AssignConfigurationAction extends BaseAction
14+
{
15+
public function __construct(
16+
private readonly AssignConfigurationHandler $handler,
17+
) {
18+
}
19+
20+
public function __invoke(Request $request, int $accountId): JsonResponse
21+
{
22+
$this->minimumAllowedRole(Role::SUPERADMIN);
23+
24+
$validated = $request->validate([
25+
'configuration_id' => 'required|integer|exists:account_configuration,id',
26+
]);
27+
28+
$this->handler->handle($accountId, (int) $validated['configuration_id']);
29+
30+
return $this->jsonResponse([
31+
'message' => __('Configuration assigned successfully.'),
32+
]);
33+
}
34+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace HiEvents\Http\Actions\Admin\Accounts;
6+
7+
use HiEvents\DomainObjects\Enums\Role;
8+
use HiEvents\Http\Actions\BaseAction;
9+
use HiEvents\Resources\Account\AdminAccountDetailResource;
10+
use HiEvents\Services\Application\Handlers\Admin\GetAccountHandler;
11+
use Illuminate\Http\JsonResponse;
12+
13+
class GetAccountAction extends BaseAction
14+
{
15+
public function __construct(
16+
private readonly GetAccountHandler $handler,
17+
)
18+
{
19+
}
20+
21+
public function __invoke(int $accountId): JsonResponse
22+
{
23+
$this->minimumAllowedRole(Role::SUPERADMIN);
24+
25+
$account = $this->handler->handle($accountId);
26+
27+
return $this->jsonResponse(new AdminAccountDetailResource($account), wrapInData: true);
28+
}
29+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace HiEvents\Http\Actions\Admin\Accounts;
6+
7+
use HiEvents\DataTransferObjects\UpdateAccountConfigurationDTO;
8+
use HiEvents\DomainObjects\Enums\Role;
9+
use HiEvents\Http\Actions\BaseAction;
10+
use HiEvents\Resources\Account\AccountConfigurationResource;
11+
use HiEvents\Services\Application\Handlers\Admin\UpdateAccountConfigurationHandler;
12+
use Illuminate\Http\JsonResponse;
13+
use Illuminate\Http\Request;
14+
15+
class UpdateAccountConfigurationAction extends BaseAction
16+
{
17+
public function __construct(
18+
private readonly UpdateAccountConfigurationHandler $handler,
19+
)
20+
{
21+
}
22+
23+
public function __invoke(Request $request, int $accountId): JsonResponse
24+
{
25+
$this->minimumAllowedRole(Role::SUPERADMIN);
26+
27+
$validated = $request->validate([
28+
'application_fees' => 'required|array',
29+
'application_fees.fixed' => 'required|numeric|min:0',
30+
'application_fees.percentage' => 'required|numeric|min:0|max:100',
31+
]);
32+
33+
$configuration = $this->handler->handle(new UpdateAccountConfigurationDTO(
34+
accountId: $accountId,
35+
applicationFees: $validated['application_fees'],
36+
));
37+
38+
return $this->resourceResponse(
39+
resource: AccountConfigurationResource::class,
40+
data: $configuration
41+
);
42+
}
43+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace HiEvents\Http\Actions\Admin\Accounts;
6+
7+
use HiEvents\DataTransferObjects\UpdateAdminAccountVatSettingDTO;
8+
use HiEvents\DomainObjects\Enums\Role;
9+
use HiEvents\Http\Actions\BaseAction;
10+
use HiEvents\Resources\Account\AccountVatSettingResource;
11+
use HiEvents\Services\Application\Handlers\Admin\UpdateAdminAccountVatSettingHandler;
12+
use Illuminate\Http\JsonResponse;
13+
use Illuminate\Http\Request;
14+
15+
class UpdateAccountVatSettingAction extends BaseAction
16+
{
17+
public function __construct(
18+
private readonly UpdateAdminAccountVatSettingHandler $handler,
19+
)
20+
{
21+
}
22+
23+
public function __invoke(Request $request, int $accountId): JsonResponse
24+
{
25+
$this->minimumAllowedRole(Role::SUPERADMIN);
26+
27+
$validated = $request->validate([
28+
'vat_registered' => 'required|boolean',
29+
'vat_number' => 'nullable|string|max:20',
30+
'vat_validated' => 'nullable|boolean',
31+
'business_name' => 'nullable|string|max:255',
32+
'business_address' => 'nullable|string|max:500',
33+
'vat_country_code' => 'nullable|string|max:2',
34+
]);
35+
36+
$vatSetting = $this->handler->handle(new UpdateAdminAccountVatSettingDTO(
37+
accountId: $accountId,
38+
vatRegistered: $validated['vat_registered'],
39+
vatNumber: $validated['vat_number'] ?? null,
40+
vatValidated: $validated['vat_validated'] ?? null,
41+
businessName: $validated['business_name'] ?? null,
42+
businessAddress: $validated['business_address'] ?? null,
43+
vatCountryCode: $validated['vat_country_code'] ?? null,
44+
));
45+
46+
return $this->resourceResponse(
47+
resource: AccountVatSettingResource::class,
48+
data: $vatSetting
49+
);
50+
}
51+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace HiEvents\Http\Actions\Admin\Configurations;
6+
7+
use HiEvents\DomainObjects\Enums\Role;
8+
use HiEvents\Http\Actions\BaseAction;
9+
use HiEvents\Repository\Interfaces\AccountConfigurationRepositoryInterface;
10+
use HiEvents\Resources\Account\AccountConfigurationResource;
11+
use Illuminate\Http\JsonResponse;
12+
use Illuminate\Http\Request;
13+
use Symfony\Component\HttpFoundation\Response;
14+
15+
class CreateConfigurationAction extends BaseAction
16+
{
17+
public function __construct(
18+
private readonly AccountConfigurationRepositoryInterface $repository,
19+
) {
20+
}
21+
22+
public function __invoke(Request $request): JsonResponse
23+
{
24+
$this->minimumAllowedRole(Role::SUPERADMIN);
25+
26+
$validated = $request->validate([
27+
'name' => 'required|string|max:255',
28+
'application_fees' => 'required|array',
29+
'application_fees.fixed' => 'required|numeric|min:0',
30+
'application_fees.percentage' => 'required|numeric|min:0|max:100',
31+
]);
32+
33+
$configuration = $this->repository->create([
34+
'name' => $validated['name'],
35+
'is_system_default' => false,
36+
'application_fees' => $validated['application_fees'],
37+
]);
38+
39+
return $this->jsonResponse(
40+
new AccountConfigurationResource($configuration),
41+
statusCode: Response::HTTP_CREATED,
42+
wrapInData: true
43+
);
44+
}
45+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace HiEvents\Http\Actions\Admin\Configurations;
6+
7+
use HiEvents\DomainObjects\Enums\Role;
8+
use HiEvents\Exceptions\CannotDeleteEntityException;
9+
use HiEvents\Http\Actions\BaseAction;
10+
use HiEvents\Services\Application\Handlers\Admin\DeleteConfigurationHandler;
11+
use Illuminate\Http\JsonResponse;
12+
use Illuminate\Http\Response;
13+
use Illuminate\Validation\ValidationException;
14+
15+
class DeleteConfigurationAction extends BaseAction
16+
{
17+
public function __construct(
18+
private readonly DeleteConfigurationHandler $handler,
19+
) {
20+
}
21+
22+
public function __invoke(int $configurationId): Response
23+
{
24+
$this->minimumAllowedRole(Role::SUPERADMIN);
25+
26+
try {
27+
$this->handler->handle($configurationId);
28+
} catch (CannotDeleteEntityException $e) {
29+
throw ValidationException::withMessages([
30+
'configuration' => [$e->getMessage()],
31+
]);
32+
}
33+
34+
return $this->deletedResponse();
35+
}
36+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace HiEvents\Http\Actions\Admin\Configurations;
6+
7+
use HiEvents\DomainObjects\Enums\Role;
8+
use HiEvents\Http\Actions\BaseAction;
9+
use HiEvents\Repository\Interfaces\AccountConfigurationRepositoryInterface;
10+
use HiEvents\Resources\Account\AccountConfigurationResource;
11+
use Illuminate\Http\JsonResponse;
12+
13+
class GetAllConfigurationsAction extends BaseAction
14+
{
15+
public function __construct(
16+
private readonly AccountConfigurationRepositoryInterface $repository,
17+
) {
18+
}
19+
20+
public function __invoke(): JsonResponse
21+
{
22+
$this->minimumAllowedRole(Role::SUPERADMIN);
23+
24+
$configurations = $this->repository->all();
25+
26+
return $this->jsonResponse(
27+
AccountConfigurationResource::collection($configurations),
28+
wrapInData: true
29+
);
30+
}
31+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace HiEvents\Http\Actions\Admin\Configurations;
6+
7+
use HiEvents\DomainObjects\Enums\Role;
8+
use HiEvents\Http\Actions\BaseAction;
9+
use HiEvents\Repository\Interfaces\AccountConfigurationRepositoryInterface;
10+
use HiEvents\Resources\Account\AccountConfigurationResource;
11+
use Illuminate\Http\JsonResponse;
12+
use Illuminate\Http\Request;
13+
14+
class UpdateConfigurationAction extends BaseAction
15+
{
16+
public function __construct(
17+
private readonly AccountConfigurationRepositoryInterface $repository,
18+
) {
19+
}
20+
21+
public function __invoke(Request $request, int $configurationId): JsonResponse
22+
{
23+
$this->minimumAllowedRole(Role::SUPERADMIN);
24+
25+
$validated = $request->validate([
26+
'name' => 'required|string|max:255',
27+
'application_fees' => 'required|array',
28+
'application_fees.fixed' => 'required|numeric|min:0',
29+
'application_fees.percentage' => 'required|numeric|min:0|max:100',
30+
]);
31+
32+
$configuration = $this->repository->updateFromArray(
33+
id: $configurationId,
34+
attributes: [
35+
'name' => $validated['name'],
36+
'application_fees' => $validated['application_fees'],
37+
]
38+
);
39+
40+
return $this->jsonResponse(
41+
new AccountConfigurationResource($configuration),
42+
wrapInData: true
43+
);
44+
}
45+
}

0 commit comments

Comments
 (0)