|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Aggrego\Domain\Api\Domain\Command\CreateBoard; |
|
6
|
|
|
|
|
7
|
|
|
use Aggrego\Domain\Api\Application\Model\ProgressiveBoard\Exception\BoardExistException; |
|
8
|
|
|
use Aggrego\Domain\Api\Application\Model\ProgressiveBoard\Repository; |
|
9
|
|
|
use Aggrego\Domain\Api\Application\Profile\BoardConstruction\Exception\BuilderNotFoundException; |
|
10
|
|
|
use Aggrego\Domain\Api\Application\Profile\BoardConstruction\Exception\UnableToBuildBoardException; |
|
11
|
|
|
use Aggrego\Domain\Api\Application\Profile\BoardConstruction\Factory; |
|
12
|
|
|
use Aggrego\Domain\Api\Domain\Command\CreateBoard\Exception\InvalidCommandDataException; |
|
13
|
|
|
use Aggrego\Domain\Model\ProgressiveBoard\Board; |
|
14
|
|
|
|
|
15
|
|
|
class UseCase |
|
16
|
|
|
{ |
|
17
|
|
|
/** @var Repository */ |
|
18
|
|
|
private $boardRepository; |
|
19
|
|
|
|
|
20
|
|
|
/** @var Factory */ |
|
21
|
|
|
private $profileBoardFactory; |
|
22
|
|
|
|
|
23
|
|
|
public function __construct( |
|
24
|
|
|
Repository $boardRepository, |
|
25
|
|
|
Factory $profileBoardFactory |
|
26
|
|
|
) |
|
27
|
|
|
{ |
|
28
|
|
|
$this->boardRepository = $boardRepository; |
|
29
|
|
|
$this->profileBoardFactory = $profileBoardFactory; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param Command $command |
|
34
|
|
|
* @throws InvalidCommandDataException |
|
35
|
|
|
*/ |
|
36
|
|
|
public function handle(Command $command): void |
|
37
|
|
|
{ |
|
38
|
|
|
$key = $command->getKey(); |
|
39
|
|
|
$profile = $command->getProfile(); |
|
40
|
|
|
|
|
41
|
|
|
try { |
|
42
|
|
|
$this->boardRepository->addBoard( |
|
43
|
|
|
Board::factory( |
|
44
|
|
|
$key, |
|
45
|
|
|
$this->profileBoardFactory->factory($profile) |
|
46
|
|
|
) |
|
47
|
|
|
); |
|
48
|
|
|
} catch (BuilderNotFoundException $e) { |
|
49
|
|
|
throw new InvalidCommandDataException($e->getMessage(), $e->getCode(), $e); |
|
50
|
|
|
} catch (UnableToBuildBoardException $e) { |
|
51
|
|
|
throw new InvalidCommandDataException($e->getMessage(), $e->getCode(), $e); |
|
52
|
|
|
} catch (BoardExistException $e) { |
|
53
|
|
|
throw new InvalidCommandDataException($e->getMessage(), $e->getCode(), $e); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|