1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Modules\Posts\Domain\Logic; |
4
|
|
|
|
5
|
|
|
use App\Infrastructure\Events\Api\ApplicationEventPublisherInterface; |
6
|
|
|
use App\Modules\Posts\Api\Command\BaselinePostsCommand; |
7
|
|
|
use App\Modules\Posts\Domain\Dto\DeleteExistingPostDto; |
8
|
|
|
use App\Modules\Posts\Domain\Dto\UpdateExistingPostDto; |
9
|
|
|
use App\Modules\Posts\Domain\Event\Outbound\PostDeletedOEvent; |
10
|
|
|
use App\Modules\Posts\Domain\Event\Outbound\PostUpdatedOEvent; |
11
|
|
|
use App\Modules\Posts\Domain\Repository\PostsFindingRepositoryInterface; |
12
|
|
|
|
13
|
|
|
trait PostsBaseliner |
14
|
|
|
{ |
15
|
|
|
|
16
|
|
|
|
17
|
24 |
|
public function __construct( |
18
|
|
|
private PostsFindingRepositoryInterface $findingRepository, |
19
|
|
|
private ApplicationEventPublisherInterface $eventPublisher |
20
|
|
|
) |
21
|
|
|
{ |
22
|
24 |
|
} |
23
|
|
|
|
24
|
1 |
|
public function baseline(BaselinePostsCommand $command): void |
25
|
|
|
{ |
26
|
1 |
|
$this->baselineExistentPosts($command); |
27
|
1 |
|
$this->baselineDeletedPosts($command); |
28
|
|
|
|
29
|
1 |
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param BaselinePostsCommand $command |
33
|
|
|
*/ |
34
|
1 |
|
protected function baselineDeletedPosts(BaselinePostsCommand $command): void |
35
|
|
|
{ |
36
|
1 |
|
$deletedPostIds = $this->findingRepository->findDeletedPostIdsForBaseline($command->getFrom()); |
37
|
|
|
foreach ($deletedPostIds as $postId) { |
38
|
1 |
|
$this->eventPublisher->publish(new PostDeletedOEvent(new DeleteExistingPostDto($postId))); |
39
|
|
|
} |
40
|
|
|
} |
41
|
1 |
|
|
42
|
|
|
/** |
43
|
|
|
* @param BaselinePostsCommand $command |
44
|
|
|
*/ |
45
|
|
|
protected function baselineExistentPosts(BaselinePostsCommand $command): void |
46
|
1 |
|
{ |
47
|
|
|
$posts = $this->findingRepository->findExistingPostsForBaseline($command->getFrom()); |
48
|
1 |
|
foreach ($posts as $post) { |
49
|
1 |
|
$this->eventPublisher->publish(new PostUpdatedOEvent( |
50
|
1 |
|
new UpdateExistingPostDto( |
51
|
1 |
|
$post->getId(), |
52
|
1 |
|
$post->getTitle(), |
53
|
1 |
|
$post->getBody(), |
54
|
1 |
|
$post->getSummary(), |
55
|
1 |
|
$post->getTags(), |
56
|
1 |
|
$post->getUpdatedAt() |
57
|
1 |
|
), |
58
|
|
|
$post->getVersion() |
59
|
1 |
|
)); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
} |