|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace App\Src\UseCases\Domain\Context\UseCases; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
use App\Src\UseCases\Domain\Context\Model\Characteristic; |
|
8
|
|
|
use App\Src\UseCases\Domain\Ports\CharacteristicsRepository; |
|
9
|
|
|
use App\Src\UseCases\Domain\Ports\ContextRepository; |
|
10
|
|
|
use App\Src\UseCases\Domain\Shared\Gateway\AuthGateway; |
|
11
|
|
|
|
|
12
|
|
|
class CreateCharacteristic |
|
13
|
|
|
{ |
|
14
|
|
|
private $characteristicRepository; |
|
15
|
|
|
private $authGateway; |
|
16
|
|
|
private $contextRepository; |
|
17
|
|
|
|
|
18
|
|
|
public function __construct( |
|
19
|
|
|
CharacteristicsRepository $characteristicRepository, |
|
20
|
|
|
AuthGateway $authGateway, |
|
21
|
|
|
ContextRepository $contextRepository |
|
22
|
|
|
) |
|
23
|
|
|
{ |
|
24
|
|
|
$this->characteristicRepository = $characteristicRepository; |
|
25
|
|
|
$this->authGateway = $authGateway; |
|
26
|
|
|
$this->contextRepository = $contextRepository; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function execute(string $id, string $type, string $title) |
|
30
|
|
|
{ |
|
31
|
|
|
$characteristic = $this->characteristicRepository->getBy(['title' => $title, 'type' => $type]); |
|
32
|
|
|
if(!isset($characteristic)){ |
|
33
|
|
|
$characteristic = new Characteristic($id, $type, $title, false); |
|
34
|
|
|
$characteristic->create(); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
$user = $this->authGateway->current(); |
|
38
|
|
|
$context = $this->contextRepository->getByUser($user->id()); |
|
39
|
|
|
$context->addCharacteristics([$characteristic->id()], $user->id()); |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
|