Skip to content

Commit 12249e4

Browse files
committed
feat: add visibility support to workspaces with domain, DTO, and schema updates
- Introduced `visibility` field to `Workspace` domain, DTO, and database schema - Added `VisibilityInput` validator with range validation rules - Updated `WorkspaceHydrator`, `WorkspaceCreator`, and `WorkspaceCreateValidator` to handle `visibility` - Registered `VisibilityInput` in `ConfigProvider` - Ensured date tracking with `createdAt` and `updatedAt` fields in relevant components and database schema
1 parent ffa8f84 commit 12249e4

13 files changed

Lines changed: 96 additions & 8 deletions

File tree

database/migrations/Version20260121203207_CreateWorkspaceTable.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public function up(Schema $schema): void
1919
$table->addColumn('slug', Types::STRING, ['length' => 64,]);
2020
$table->addColumn('description', Types::STRING, ['length' => 255, 'notnull' => false, 'default' => '']);
2121
$table->addColumn('details', Types::TEXT, ['notnull' => false, 'default' => '']);
22+
$table->addColumn('visibility', Types::SMALLINT, ['unsigned' => true, 'length' => 2, 'default' => 5]);
23+
$table->addColumn('createdAt', Types::DATETIME_IMMUTABLE, ['default' => 'CURRENT_TIMESTAMP',]);
24+
$table->addColumn('updatedAt', Types::DATETIME_IMMUTABLE, ['default' => 'CURRENT_TIMESTAMP',]);
2225

2326
$table->addPrimaryKeyConstraint(
2427
PrimaryKeyConstraint::editor()

src/App/Shared/ConfigProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Laminas\ServiceManager\Factory\InvokableFactory;
77
use ownHackathon\Shared\Infrastructure\Service\PaginationTotalPages;
88
use ownHackathon\Shared\Middleware\PaginationMiddleware;
9+
use ownHackathon\Shared\Validator\Input\VisibilityInput;
910

1011
class ConfigProvider
1112
{
@@ -30,6 +31,7 @@ public function getDependencies(): array
3031

3132
],
3233
'invokables' => [
34+
VisibilityInput::class,
3335
],
3436
'factories' => [
3537
PaginationMiddleware::class => InvokableFactory::class,

src/App/Shared/Domain/Workspace/WorkspaceInterface.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace ownHackathon\Shared\Domain\Workspace;
44

5+
use DateTimeImmutable;
6+
use Exdrals\Core\Shared\Domain\Enum\Visibility;
57
use Ramsey\Uuid\UuidInterface;
68

79
interface WorkspaceInterface
@@ -20,5 +22,11 @@ interface WorkspaceInterface
2022

2123
public ?string $details { get; }
2224

25+
public Visibility $visibility { get; }
26+
27+
public DateTimeImmutable $createdAt { get; }
28+
29+
public DateTimeImmutable $updatedAt { get; }
30+
2331
public function with(mixed ...$properties): self;
2432
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ownHackathon\Shared\Validator\Input;
4+
5+
use Laminas\Filter\Digits;
6+
use Laminas\Filter\StringTrim;
7+
use Laminas\InputFilter\Input;
8+
use Laminas\Validator\NumberComparison;
9+
10+
class VisibilityInput extends Input
11+
{
12+
public function __construct()
13+
{
14+
parent::__construct('visibility');
15+
16+
$this->setRequired(true);
17+
$this->setFallbackValue(5);
18+
$this->setAllowEmpty(false);
19+
20+
$this->getFilterChain()->attachByName(StringTrim::class);
21+
$this->getFilterChain()->attachByName(Digits::class);
22+
23+
$this->getValidatorChain()->attachByName(
24+
NumberComparison::class,
25+
[
26+
'min' => 1,
27+
'max' => 5,
28+
],
29+
);
30+
}
31+
}

src/App/Workspace/ConfigProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use ownHackathon\Shared\Infrastructure\Service\PaginationTotalPages;
1717
use ownHackathon\Shared\Infrastructure\Service\WorkspaceCreatorInterface;
1818
use ownHackathon\Shared\Middleware\PaginationMiddleware;
19+
use ownHackathon\Shared\Validator\Input\VisibilityInput;
1920
use ownHackathon\Workspace\Handler\ListOwnWorkspacesHandler;
2021
use ownHackathon\Workspace\Handler\WorkspaceCreateHandler;
2122
use ownHackathon\Workspace\Handler\WorkspaceHandler;
@@ -123,6 +124,7 @@ public function getAbstractFactoryConfig(): array
123124
WorkspaceNameInput::class,
124125
WorkspaceDescriptionInput::class,
125126
WorkspaceDetailsInput::class,
127+
VisibilityInput::class,
126128
],
127129
WorkspaceCreateValidatorMiddleware::class => [
128130
WorkspaceCreateValidator::class,

src/App/Workspace/DTO/Workspace.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,24 @@ public function __construct(
99
public string $description,
1010
public string $owner,
1111
public string $ownerUuid,
12+
public string $details,
13+
public int $visibility,
14+
public string $createdAt,
15+
public string $updatedAt,
1216
) {
1317
}
1418

1519
public static function fromArray(array $data): self
1620
{
1721
return new self(
18-
$data['name'],
19-
$data['description'] ?? '',
20-
$data['owner'],
21-
$data['ownerUuid']
22+
name: $data['name'],
23+
description: $data['description'] ?? '',
24+
owner: $data['owner'],
25+
ownerUuid: $data['ownerUuid'],
26+
details: $data['details'],
27+
visibility: $data['visibility'],
28+
createdAt: $data['createdAt'],
29+
updatedAt: $data['updatedAt'],
2230
);
2331
}
2432
}

src/App/Workspace/DTO/WorkspaceRequest.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Exdrals\Core\Shared\Domain\Enum\DataType;
66
use OpenApi\Attributes as OA;
77

8-
#[OA\Schema(required: ['name'])]
8+
#[OA\Schema(required: ['name', 'visibility'])]
99
readonly class WorkspaceRequest
1010
{
1111
public function __construct(
@@ -27,15 +27,22 @@ public function __construct(
2727
example: 'My own workspace is wonderfully'
2828
)]
2929
public ?string $details,
30+
#[OA\Property(
31+
description: 'The visibility from workspace',
32+
type: DataType::INTEGER->value,
33+
example: '5'
34+
)]
35+
public int $visibility
3036
) {
3137
}
3238

3339
public static function fromArray(array $workspace): self
3440
{
3541
return new self(
3642
name: $workspace['name'],
37-
description: $workspace['description'],
38-
details: $workspace['details'],
43+
description: $workspace['description'] ?? null,
44+
details: $workspace['details'] ?? null,
45+
visibility: (int)$workspace['visibility']
3946
);
4047
}
4148
}

src/App/Workspace/Domain/Workspace.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace ownHackathon\Workspace\Domain;
44

5+
use DateTimeImmutable;
6+
use Exdrals\Core\Shared\Domain\Enum\Visibility;
57
use Exdrals\Core\Shared\Trait\CloneReadonlyClassWith;
68
use Exdrals\Core\Shared\Utils\Collectible;
79
use ownHackathon\Shared\Domain\Workspace\WorkspaceInterface;
@@ -19,6 +21,9 @@ public function __construct(
1921
public string $slug,
2022
public ?string $description,
2123
public ?string $details,
24+
public Visibility $visibility,
25+
public DateTimeImmutable $createdAt,
26+
public DateTimeImmutable $updatedAt,
2227
) {
2328
}
2429
}

src/App/Workspace/Handler/WorkspaceHandler.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace ownHackathon\Workspace\Handler;
44

5+
use Exdrals\Core\Shared\Domain\Enum\DateTimeFormat;
56
use Exdrals\Identity\Infrastructure\Persistence\Repository\AccountRepositoryInterface;
67
use Fig\Http\Message\StatusCodeInterface as Http;
78
use Laminas\Diactoros\Response\JsonResponse;
@@ -32,6 +33,10 @@ public function handle(ServerRequestInterface $request): ResponseInterface
3233
'description' => $workspace->description,
3334
'owner' => $account->name,
3435
'ownerUuid' => $account->uuid->toString(),
36+
'details' => $workspace->details,
37+
'visibility' => $workspace->visibility->value,
38+
'createdAt' => $workspace->createdAt->format(DateTimeFormat::DEFAULT->value),
39+
'updatedAt' => $workspace->updatedAt->format(DateTimeFormat::DEFAULT->value),
3540
]
3641
);
3742

src/App/Workspace/Infrastructure/Hydrator/WorkspaceHydrator.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
namespace ownHackathon\Workspace\Infrastructure\Hydrator;
44

5+
use DateTimeImmutable;
56
use Exception;
7+
use Exdrals\Core\Shared\Domain\Enum\DateTimeFormat;
8+
use Exdrals\Core\Shared\Domain\Enum\Visibility;
69
use Exdrals\Core\Shared\Utils\UuidFactoryInterface;
710
use ownHackathon\Shared\Domain\Workspace\WorkspaceCollectionInterface;
811
use ownHackathon\Shared\Domain\Workspace\WorkspaceInterface;
@@ -30,6 +33,9 @@ public function hydrate(array $data): WorkspaceInterface
3033
slug: $data['slug'],
3134
description: $data['description'],
3235
details: $data['details'],
36+
visibility: Visibility::tryFrom($data['visibility']),
37+
createdAt: new DateTimeImmutable($data['createdAt']),
38+
updatedAt: new DateTimeImmutable($data['updatedAt']),
3339
);
3440
}
3541

@@ -57,6 +63,9 @@ public function extract(WorkspaceInterface $object): array
5763
'slug' => $object->slug,
5864
'description' => $object->description,
5965
'details' => $object->details,
66+
'visibility' => $object->visibility->value,
67+
'createdAt' => $object->createdAt->format(DateTimeFormat::DEFAULT->value),
68+
'updatedAt' => $object->updatedAt->format(DateTimeFormat::DEFAULT->value),
6069
];
6170
}
6271

0 commit comments

Comments
 (0)