Skip to content

Commit 136b9b0

Browse files
committed
Issue #453: Use native UUIDs in database via ramsey/uuid
Signed-off-by: alexmerlin <[email protected]>
1 parent 0d857b3 commit 136b9b0

Some content is hidden

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

45 files changed

+298
-333
lines changed

documentation/Dotkernel_API.postman_collection.json

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"header": [],
7474
"body": {
7575
"mode": "raw",
76-
"raw": "{\r\n \"identity\": \"{{$randomUserName}}\",\r\n \"password\": \"dotkernel\",\r\n \"passwordConfirm\": \"dotkernel\",\r\n \"firstName\": \"{{$randomFirstName}}\",\r\n \"lastName\": \"{{$randomLastName}}\",\r\n \"status\": \"active\",\r\n \"roles\": [\r\n {\r\n \"uuid\": \"{{$randomUUID}}\"\r\n }\r\n ]\r\n}",
76+
"raw": "{\r\n \"identity\": \"{{$randomUserName}}\",\r\n \"password\": \"dotkernel\",\r\n \"passwordConfirm\": \"dotkernel\",\r\n \"firstName\": \"{{$randomFirstName}}\",\r\n \"lastName\": \"{{$randomLastName}}\",\r\n \"status\": \"active\",\r\n \"roles\": [\r\n {\r\n \"id\": \"{{$randomUUID}}\"\r\n }\r\n ]\r\n}",
7777
"options": {
7878
"raw": {
7979
"language": "json"
@@ -178,7 +178,7 @@
178178
"header": [],
179179
"body": {
180180
"mode": "raw",
181-
"raw": "{\r\n \"password\": \"dotkernel\",\r\n \"passwordConfirm\": \"dotkernel\",\r\n \"firstName\": \"{{$randomFirstName}}\",\r\n \"lastName\": \"{{$randomLastName}}\",\r\n \"roles\": [\r\n {\r\n \"uuid\": \"{{$randomUUID}}\"\r\n }\r\n ],\r\n \"status\": \"active\"\r\n}",
181+
"raw": "{\r\n \"password\": \"dotkernel\",\r\n \"passwordConfirm\": \"dotkernel\",\r\n \"firstName\": \"{{$randomFirstName}}\",\r\n \"lastName\": \"{{$randomLastName}}\",\r\n \"roles\": [\r\n {\r\n \"id\": \"{{$randomUUID}}\"\r\n }\r\n ],\r\n \"status\": \"active\"\r\n}",
182182
"options": {
183183
"raw": {
184184
"language": "json"
@@ -209,7 +209,8 @@
209209
""
210210
],
211211
"type": "text/javascript",
212-
"packages": {}
212+
"packages": {},
213+
"requests": {}
213214
}
214215
}
215216
],
@@ -1176,7 +1177,9 @@
11761177
"exec": [
11771178
""
11781179
],
1179-
"type": "text/javascript"
1180+
"type": "text/javascript",
1181+
"packages": {},
1182+
"requests": {}
11801183
}
11811184
}
11821185
],
@@ -1185,7 +1188,7 @@
11851188
"header": [],
11861189
"body": {
11871190
"mode": "raw",
1188-
"raw": "{\r\n \"identity\": \"{{$randomUserName}}\",\r\n \"password\": \"dotkernel\",\r\n \"passwordConfirm\": \"dotkernel\",\r\n \"status\": \"pending\",\r\n \"detail\": {\r\n \"firstName\": \"{{$randomFirstName}}\",\r\n \"lastName\": \"{{$randomLastName}}\",\r\n \"email\": \"{{$randomExampleEmail}}\"\r\n },\r\n \"roles\": [\r\n {\r\n \"uuid\": \"{{$randomUUID}}\"\r\n }\r\n ]\r\n}",
1191+
"raw": "{\r\n \"identity\": \"{{$randomUserName}}\",\r\n \"password\": \"dotkernel\",\r\n \"passwordConfirm\": \"dotkernel\",\r\n \"status\": \"pending\",\r\n \"detail\": {\r\n \"firstName\": \"{{$randomFirstName}}\",\r\n \"lastName\": \"{{$randomLastName}}\",\r\n \"email\": \"{{$randomExampleEmail}}\"\r\n },\r\n \"roles\": [\r\n {\r\n \"id\": \"{{$randomUUID}}\"\r\n }\r\n ]\r\n}",
11891192
"options": {
11901193
"raw": {
11911194
"language": "json"
@@ -1314,7 +1317,7 @@
13141317
"header": [],
13151318
"body": {
13161319
"mode": "raw",
1317-
"raw": "{\r\n \"password\": \"dotkernel\",\r\n \"passwordConfirm\": \"dotkernel\",\r\n \"status\": \"active\",\r\n \"detail\": {\r\n \"firstName\": \"{{$randomFirstName}}\",\r\n \"lastName\": \"{{$randomLastName}}\",\r\n \"email\": \"{{$randomExampleEmail}}\"\r\n },\r\n \"roles\": [\r\n {\r\n \"uuid\": \"{{$randomUUID}}\"\r\n }\r\n ]\r\n}",
1320+
"raw": "{\r\n \"password\": \"dotkernel\",\r\n \"passwordConfirm\": \"dotkernel\",\r\n \"status\": \"active\",\r\n \"detail\": {\r\n \"firstName\": \"{{$randomFirstName}}\",\r\n \"lastName\": \"{{$randomLastName}}\",\r\n \"email\": \"{{$randomExampleEmail}}\"\r\n },\r\n \"roles\": [\r\n {\r\n \"id\": \"{{$randomUUID}}\"\r\n }\r\n ]\r\n}",
13181321
"options": {
13191322
"raw": {
13201323
"language": "json"

src/Admin/src/Command/AdminCreateCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9999
* firstName: string,
100100
* lastName: string,
101101
* status: 'active',
102-
* roles: array{uuid: non-empty-string}[],
102+
* roles: array{id: non-empty-string}[],
103103
* }
104104
* @throws Exception
105105
*/
@@ -118,7 +118,7 @@ private function getData(InputInterface $input): array
118118
'lastName' => trim($input->getOption('lastName')),
119119
'status' => AdminStatusEnum::Active->value,
120120
'roles' => [
121-
['uuid' => $adminRole->getUuid()->toString()],
121+
['id' => $adminRole->getId()->toString()],
122122
],
123123
];
124124
}

src/Admin/src/InputFilter/AdminRoleInputFilter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99

1010
/**
1111
* @phpstan-type AdminRoleDataType array{
12-
* uuid: non-empty-string,
12+
* id: non-empty-string,
1313
* }
1414
* @extends AbstractInputFilter<AdminRoleDataType>
1515
*/
1616
class AdminRoleInputFilter extends AbstractInputFilter
1717
{
1818
public function __construct()
1919
{
20-
$this->add(new UuidInput('uuid'));
20+
$this->add(new UuidInput('id'));
2121
}
2222
}

src/Admin/src/OpenAPI.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@
118118
property: 'roles',
119119
type: 'array',
120120
items: new OA\Items(
121-
required: ['uuid'],
121+
required: ['id'],
122122
properties: [
123-
new OA\Property(property: 'uuid', type: 'string'),
123+
new OA\Property(property: 'id', type: 'string'),
124124
],
125125
),
126126
),
@@ -157,15 +157,15 @@
157157
* @see DeleteAdminResourceHandler::handle()
158158
*/
159159
#[OA\Delete(
160-
path: '/admin/{uuid}',
161-
description: 'Authenticated (super)admin deletes an admin account identified by its UUID',
160+
path: '/admin/{id}',
161+
description: 'Authenticated (super)admin deletes an admin account identified by its id',
162162
summary: 'Admin deletes an admin account',
163163
security: [['AuthToken' => []]],
164164
tags: ['Admin'],
165165
parameters: [
166166
new OA\Parameter(
167-
name: 'uuid',
168-
description: 'Admin UUID',
167+
name: 'id',
168+
description: 'Admin id',
169169
in: 'path',
170170
required: true,
171171
schema: new OA\Schema(type: 'string'),
@@ -187,15 +187,15 @@
187187
* @see GetAdminResourceHandler::handle()
188188
*/
189189
#[OA\Get(
190-
path: '/admin/{uuid}',
191-
description: 'Authenticated (super)admin fetches an admin account identified by its UUID',
190+
path: '/admin/{id}',
191+
description: 'Authenticated (super)admin fetches an admin account identified by its id',
192192
summary: 'Admin fetches an admin account',
193193
security: [['AuthToken' => []]],
194194
tags: ['Admin'],
195195
parameters: [
196196
new OA\Parameter(
197-
name: 'uuid',
198-
description: 'Admin UUID',
197+
name: 'id',
198+
description: 'Admin id',
199199
in: 'path',
200200
required: true,
201201
schema: new OA\Schema(type: 'string'),
@@ -218,7 +218,7 @@
218218
* @see PatchAdminResourceHandler::handle()
219219
*/
220220
#[OA\Patch(
221-
path: '/admin/{uuid}',
221+
path: '/admin/{id}',
222222
description: 'Authenticated (super)admin updates an existing admin account',
223223
summary: 'Admin updates an admin account',
224224
security: [['AuthToken' => []]],
@@ -236,9 +236,9 @@
236236
property: 'roles',
237237
type: 'array',
238238
items: new OA\Items(
239-
required: ['uuid'],
239+
required: ['id'],
240240
properties: [
241-
new OA\Property(property: 'uuid', type: 'string'),
241+
new OA\Property(property: 'id', type: 'string'),
242242
],
243243
),
244244
),
@@ -249,8 +249,8 @@
249249
tags: ['Admin'],
250250
parameters: [
251251
new OA\Parameter(
252-
name: 'uuid',
253-
description: 'Admin UUID',
252+
name: 'id',
253+
description: 'Admin id',
254254
in: 'path',
255255
required: true,
256256
schema: new OA\Schema(type: 'string'),
@@ -352,15 +352,15 @@
352352
* @see GetAdminRoleResourceHandler::handle()
353353
*/
354354
#[OA\Get(
355-
path: '/admin/role/{uuid}',
356-
description: 'Authenticated (super)admin fetches an admin role identified by its UUID',
355+
path: '/admin/role/{id}',
356+
description: 'Authenticated (super)admin fetches an admin role identified by its id',
357357
summary: 'Admin fetches an admin role',
358358
security: [['AuthToken' => []]],
359359
tags: ['AdminRole'],
360360
parameters: [
361361
new OA\Parameter(
362-
name: 'uuid',
363-
description: 'Admin role UUID',
362+
name: 'id',
363+
description: 'Admin role id',
364364
in: 'path',
365365
required: true,
366366
schema: new OA\Schema(type: 'string'),
@@ -418,9 +418,9 @@
418418
property: 'roles',
419419
type: 'array',
420420
items: new OA\Items(
421-
required: ['uuid'],
421+
required: ['id'],
422422
properties: [
423-
new OA\Property(property: 'uuid', type: 'string'),
423+
new OA\Property(property: 'id', type: 'string'),
424424
],
425425
),
426426
),
@@ -444,7 +444,7 @@
444444
#[OA\Schema(
445445
schema: 'Admin',
446446
properties: [
447-
new OA\Property(property: 'uuid', type: 'string', example: '1234abcd-abcd-4321-12ab-123456abcdef'),
447+
new OA\Property(property: 'id', type: 'string', example: '1234abcd-abcd-4321-12ab-123456abcdef'),
448448
new OA\Property(property: 'identity', type: 'string'),
449449
new OA\Property(property: 'firstName', type: 'string'),
450450
new OA\Property(property: 'lastName', type: 'string'),
@@ -454,7 +454,7 @@
454454
type: 'array',
455455
items: new OA\Items(
456456
properties: [
457-
new OA\Property(property: 'uuid', type: 'string'),
457+
new OA\Property(property: 'id', type: 'string'),
458458
new OA\Property(property: 'name', type: 'string', example: AdminRoleEnum::Admin->value),
459459
],
460460
type: 'object',
@@ -489,7 +489,7 @@
489489
#[OA\Schema(
490490
schema: 'AdminRole',
491491
properties: [
492-
new OA\Property(property: 'uuid', type: 'string', example: '1234abcd-abcd-4321-12ab-123456abcdef'),
492+
new OA\Property(property: 'id', type: 'string', example: '1234abcd-abcd-4321-12ab-123456abcdef'),
493493
new OA\Property(property: 'name', type: 'string', example: AdminRoleEnum::Admin->value),
494494
new OA\Property(
495495
property: '_links',

src/Admin/src/RoutesDelegator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class RoutesDelegator
2828
*/
2929
public function __invoke(ContainerInterface $container, string $serviceName, callable $callback): Application
3030
{
31-
$uuid = ConfigProvider::REGEXP_UUID;
31+
$id = ConfigProvider::REGEXP_UUID;
3232

3333
/** @var RouteCollectorInterface $routeCollector */
3434
$routeCollector = $container->get(RouteCollectorInterface::class);
@@ -37,14 +37,14 @@ public function __invoke(ContainerInterface $container, string $serviceName, cal
3737
->get('', GetAdminCollectionHandler::class, 'admin::list-admin')
3838
->post('', PostAdminResourceHandler::class, 'admin::create-admin');
3939

40-
$routeCollector->group('/admin/' . $uuid)
40+
$routeCollector->group('/admin/' . $id)
4141
->delete('', DeleteAdminResourceHandler::class, 'admin::delete-admin')
4242
->get('', GetAdminResourceHandler::class, 'admin::view-admin')
4343
->patch('', PatchAdminResourceHandler::class, 'admin::update-admin');
4444

4545
$routeCollector->group('/admin/role')
4646
->get('', GetAdminRoleCollectionHandler::class, 'admin::list-role')
47-
->get('/' . $uuid, GetAdminRoleResourceHandler::class, 'admin::view-role');
47+
->get('/' . $id, GetAdminRoleResourceHandler::class, 'admin::view-role');
4848

4949
$routeCollector->group('/admin/account')
5050
->get('', GetAdminAccountResourceHandler::class, 'admin::view-account')

src/Admin/src/Service/AdminService.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ public function deleteAdmin(Admin $admin): void
4747
/**
4848
* @throws NotFoundException
4949
*/
50-
public function findAdmin(string $uuid): Admin
50+
public function findAdmin(string $id): Admin
5151
{
52-
$admin = $this->adminRepository->find($uuid);
52+
$admin = $this->adminRepository->find($id);
5353
if (! $admin instanceof Admin) {
5454
throw NotFoundException::create(Message::ADMIN_NOT_FOUND);
5555
}
@@ -119,12 +119,12 @@ public function saveAdmin(array $data, ?Admin $admin = null): Admin
119119
$admin->setStatus($status);
120120
}
121121

122-
$this->validateUniqueAdmin((string) $admin->getIdentity(), $admin->getUuid());
122+
$this->validateUniqueAdmin((string) $admin->getIdentity(), $admin->getId());
123123

124124
if (array_key_exists('roles', $data) && count($data['roles']) > 0) {
125125
$admin->resetRoles();
126126
foreach ($data['roles'] as $roleData) {
127-
$adminRole = $this->adminRoleRepository->find($roleData['uuid']);
127+
$adminRole = $this->adminRoleRepository->find($roleData['id']);
128128
if (! $adminRole instanceof AdminRole) {
129129
throw NotFoundException::create(Message::ROLE_NOT_FOUND);
130130
}
@@ -144,14 +144,14 @@ public function saveAdmin(array $data, ?Admin $admin = null): Admin
144144
/**
145145
* @throws ConflictException
146146
*/
147-
public function validateUniqueAdmin(string $identity, ?UuidInterface $uuid = null): void
147+
public function validateUniqueAdmin(string $identity, ?UuidInterface $id = null): void
148148
{
149149
$admin = $this->adminRepository->findOneBy(['identity' => $identity]);
150150
if ($admin instanceof Admin) {
151-
if ($uuid === null) {
151+
if ($id === null) {
152152
throw ConflictException::create(Message::DUPLICATE_IDENTITY);
153153
}
154-
if ($admin->getUuid()->toString() !== $uuid->toString()) {
154+
if (! $admin->getId()->equals($id)) {
155155
throw ConflictException::create(Message::DUPLICATE_IDENTITY);
156156
}
157157
}

src/Admin/src/Service/AdminServiceInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function deleteAdmin(Admin $admin): void;
2020
/**
2121
* @throws NotFoundException
2222
*/
23-
public function findAdmin(string $uuid): Admin;
23+
public function findAdmin(string $id): Admin;
2424

2525
/**
2626
* @param array<non-empty-string, mixed> $params

src/App/src/Attribute/Resource.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
*/
1919
public function __construct(
2020
public string $entity,
21-
public string $identifier = 'uuid',
22-
public string $placeholder = 'uuid',
21+
public string $identifier = 'id',
22+
public string $placeholder = 'id',
2323
public ?string $guard = null,
2424
) {
2525
}

src/App/src/ConfigProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ public static function getCollection(string $collectionClass, string $route, str
127127
public static function getResource(
128128
string $resourceClass,
129129
string $route,
130-
string $resourceIdentifier = 'uuid',
131-
string $resourceIdentifierPlaceholder = 'uuid'
130+
string $resourceIdentifier = 'id',
131+
string $resourceIdentifierPlaceholder = 'id'
132132
): array {
133133
return [
134134
'__class__' => RouteBasedResourceMetadata::class,

src/Core/src/Admin/src/Entity/Admin.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Core\App\Entity\PasswordTrait;
1111
use Core\App\Entity\RoleInterface;
1212
use Core\App\Entity\TimestampsTrait;
13+
use Core\App\Entity\UuidIdentifierTrait;
1314
use Core\Setting\Entity\Setting;
1415
use DateTimeImmutable;
1516
use Doctrine\Common\Collections\ArrayCollection;
@@ -29,6 +30,7 @@ class Admin extends AbstractEntity implements UserEntityInterface
2930
{
3031
use PasswordTrait;
3132
use TimestampsTrait;
33+
use UuidIdentifierTrait;
3234

3335
/** @var non-empty-string|null $identity */
3436
#[ORM\Column(name: 'identity', type: 'string', length: 191, unique: true)]
@@ -53,8 +55,8 @@ enumType: AdminStatusEnum::class,
5355
/** @var Collection<int, RoleInterface> $roles */
5456
#[ORM\ManyToMany(targetEntity: AdminRole::class)]
5557
#[ORM\JoinTable(name: 'admin_roles')]
56-
#[ORM\JoinColumn(name: 'userUuid', referencedColumnName: 'uuid')]
57-
#[ORM\InverseJoinColumn(name: 'roleUuid', referencedColumnName: 'uuid')]
58+
#[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id')]
59+
#[ORM\InverseJoinColumn(name: 'role_id', referencedColumnName: 'id')]
5860
protected Collection $roles;
5961

6062
/** @var Collection<int, Setting> $settings */
@@ -65,7 +67,6 @@ public function __construct()
6567
{
6668
parent::__construct();
6769

68-
$this->created();
6970
$this->roles = new ArrayCollection();
7071
$this->settings = new ArrayCollection();
7172
}
@@ -219,7 +220,7 @@ public function getIdentifier(): string
219220

220221
/**
221222
* @return array{
222-
* uuid: non-empty-string,
223+
* id: non-empty-string,
223224
* identity: non-empty-string|null,
224225
* firstName: string|null,
225226
* lastName: string|null,
@@ -232,7 +233,7 @@ public function getIdentifier(): string
232233
public function getArrayCopy(): array
233234
{
234235
return [
235-
'uuid' => $this->uuid->toString(),
236+
'id' => $this->id->toString(),
236237
'identity' => $this->identity,
237238
'firstName' => $this->firstName,
238239
'lastName' => $this->lastName,

0 commit comments

Comments
 (0)