Skip to content

Commit 9adf418

Browse files
committed
feat: replace CurrentUserGateway with AuthorGateway for author ID retrieval in ArticlePublishingCoordinator
1 parent db0db57 commit 9adf418

File tree

5 files changed

+30
-28
lines changed

5 files changed

+30
-28
lines changed

contexts/ArticlePublishing/Application/Coordinators/ArticlePublishingCoordinator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
use Contexts\ArticlePublishing\Application\DTOs\CreateArticleDTO;
1111
use Contexts\ArticlePublishing\Application\DTOs\GetArticleListDTO;
1212
use Contexts\ArticlePublishing\Application\DTOs\UpdateArticleDTO;
13+
use Contexts\ArticlePublishing\Domain\Gateway\AuthorGateway;
1314
use Contexts\ArticlePublishing\Domain\Gateway\CategoryGateway;
14-
use Contexts\ArticlePublishing\Domain\Gateway\CurrentUserGateway;
1515
use Contexts\ArticlePublishing\Domain\Gateway\ViewerGateway;
1616
use Contexts\ArticlePublishing\Domain\Models\Article;
1717
use Contexts\ArticlePublishing\Domain\Models\ArticleId;
@@ -29,7 +29,7 @@ class ArticlePublishingCoordinator extends BaseCoordinator
2929
public function __construct(
3030
private ArticleRepository $repository,
3131
private CategoryGateway $categoryGateway,
32-
private CurrentUserGateway $currentUserGateway,
32+
private AuthorGateway $authorGateway,
3333
private ViewerGateway $viewerGateway,
3434
) {}
3535

@@ -41,7 +41,7 @@ public function create(CreateArticleDTO $data): ArticleVisibility
4141

4242
$authorId = $data->authorId
4343
? AuthorId::fromInt($data->authorId)
44-
: $this->currentUserGateway->getCurrentAuthorId();
44+
: $this->authorGateway->getCurrentAuthorId();
4545

4646
$article = match ($data->status) {
4747
'draft' => $this->createDraft($data, $authorId),

contexts/ArticlePublishing/Domain/Gateway/CurrentUserGateway.php renamed to contexts/ArticlePublishing/Domain/Gateway/AuthorGateway.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use Contexts\ArticlePublishing\Domain\Models\AuthorId;
88

9-
interface CurrentUserGateway
9+
interface AuthorGateway
1010
{
1111
public function getCurrentAuthorId(): AuthorId;
1212
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Contexts\ArticlePublishing\Infrastructure\Adapters;
6+
7+
use Contexts\ArticlePublishing\Domain\Gateway\AuthorGateway;
8+
use Contexts\ArticlePublishing\Domain\Models\AuthorId;
9+
use Contexts\Authorization\Contracts\V1\Services\CurrentUserService;
10+
11+
class AuthorAdapter implements AuthorGateway
12+
{
13+
public function __construct(
14+
private CurrentUserService $currentUserService
15+
) {}
16+
17+
public function getCurrentAuthorId(): AuthorId
18+
{
19+
$currentUser = $this->currentUserService->getCurrentUser();
20+
21+
return AuthorId::fromInt($currentUser->id);
22+
}
23+
}

contexts/ArticlePublishing/Infrastructure/Adapters/CurrentUserAdapter.php

Lines changed: 0 additions & 21 deletions
This file was deleted.

contexts/ArticlePublishing/Infrastructure/ServiceProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
namespace Contexts\ArticlePublishing\Infrastructure;
66

77
use Contexts\ArticlePublishing\Domain\Events\ArticlePublishedEvent;
8+
use Contexts\ArticlePublishing\Domain\Gateway\AuthorGateway;
89
use Contexts\ArticlePublishing\Domain\Gateway\AuthorizationGateway;
910
use Contexts\ArticlePublishing\Domain\Gateway\CategoryGateway;
10-
use Contexts\ArticlePublishing\Domain\Gateway\CurrentUserGateway;
1111
use Contexts\ArticlePublishing\Domain\Gateway\ViewerGateway;
12+
use Contexts\ArticlePublishing\Infrastructure\Adapters\AuthorAdapter;
1213
use Contexts\ArticlePublishing\Infrastructure\Adapters\AuthorizationAdapter;
1314
use Contexts\ArticlePublishing\Infrastructure\Adapters\CategoryAdapter;
14-
use Contexts\ArticlePublishing\Infrastructure\Adapters\CurrentUserAdapter;
1515
use Contexts\ArticlePublishing\Infrastructure\Adapters\ViewerAdapter;
1616
use Contexts\ArticlePublishing\Infrastructure\EventListeners\ConsoleOutputListener;
1717
use Contexts\CategoryManagement\Application\Coordinators\CategoryManagementCoordinator;
@@ -53,8 +53,8 @@ public function map(): void
5353
});
5454

5555
$this->app->bind(AuthorizationGateway::class, AuthorizationAdapter::class);
56-
$this->app->bind(CurrentUserGateway::class, CurrentUserAdapter::class);
5756
$this->app->bind(ViewerGateway::class, ViewerAdapter::class);
57+
$this->app->bind(AuthorGateway::class, AuthorAdapter::class);
5858
}
5959

6060
public function provides(): array

0 commit comments

Comments
 (0)