-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We are leaking domain logic to the infrastructure layer by allowing a query to return the Article domain entity directly. In this commit we introduce a read model that can be exposed by the query handler instead. This fixes the domain leaking into the infrastructure layer.
- Loading branch information
Showing
8 changed files
with
84 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace App\Feed\Application\Model\Article; | ||
|
||
use App\Feed\Application\Model\Source\SourceReadModel; | ||
use App\Feed\Domain\Article\Article; | ||
use DateTimeImmutable; | ||
|
||
final readonly class ArticleReadModel | ||
{ | ||
private function __construct( | ||
public string $title, | ||
public string $summary, | ||
public string $url, | ||
public SourceReadModel $source, | ||
public DateTimeImmutable $updated, | ||
) { | ||
} | ||
|
||
public static function fromArticle(Article $article): self | ||
{ | ||
return new self( | ||
$article->getTitle(), | ||
$article->getSummary(), | ||
(string) $article->getUrl(), | ||
SourceReadModel::fromSource($article->getSource()), | ||
DateTimeImmutable::createFromMutable($article->getUpdated()), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace App\Feed\Application\Model\Source; | ||
|
||
use App\Feed\Domain\Source\Source; | ||
|
||
final readonly class SourceReadModel | ||
{ | ||
private function __construct( | ||
public string $id, | ||
public string $name, | ||
) { | ||
} | ||
|
||
public static function fromSource(Source $source): self | ||
{ | ||
return new self( | ||
$source->getId(), | ||
$source->getName(), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters