Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
20 / 20 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| AddDocumentCommentAction | |
100.00% |
20 / 20 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| execute | |
100.00% |
19 / 19 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace ImovelZapAi\Documents\Application\Actions; |
| 6 | |
| 7 | use App\Models\User; |
| 8 | use ImovelZapAi\Documents\Application\Services\DocumentHistoryWriter; |
| 9 | use ImovelZapAi\Documents\Domain\Enums\DocumentHistoryEvent; |
| 10 | use ImovelZapAi\Documents\Infrastructure\Persistence\Eloquent\BusinessDocumentModel; |
| 11 | use ImovelZapAi\Documents\Infrastructure\Persistence\Eloquent\DocumentCommentModel; |
| 12 | |
| 13 | final class AddDocumentCommentAction |
| 14 | { |
| 15 | public function __construct(private readonly DocumentHistoryWriter $history) {} |
| 16 | |
| 17 | public function execute( |
| 18 | BusinessDocumentModel $document, |
| 19 | string $body, |
| 20 | string $authorType = 'broker', |
| 21 | ?User $actor = null, |
| 22 | ?string $authorName = null, |
| 23 | ): DocumentCommentModel { |
| 24 | $comment = DocumentCommentModel::query()->create([ |
| 25 | 'tenant_id' => $document->tenant_id, |
| 26 | 'business_document_id' => $document->id, |
| 27 | 'document_version_id' => $document->current_version_id, |
| 28 | 'author_type' => $authorType, |
| 29 | 'author_user_id' => $actor?->id, |
| 30 | 'author_name' => $authorName ?? $actor?->name, |
| 31 | 'body' => $body, |
| 32 | 'visible_to_client' => true, |
| 33 | ]); |
| 34 | |
| 35 | $this->history->write( |
| 36 | $document->tenant_id, |
| 37 | $document->id, |
| 38 | DocumentHistoryEvent::CommentAdded, |
| 39 | actorType: $authorType, |
| 40 | actorUserId: $actor?->id, |
| 41 | message: 'Comentário adicionado ao documento.', |
| 42 | ); |
| 43 | |
| 44 | return $comment; |
| 45 | } |
| 46 | } |